@@ -85,6 +85,13 @@ def setUp(self):
8585 self .createTestCoordFiles (_centers , i )
8686 self .createTestStarFiles (_centers , i )
8787
88+ # Create extra coordinate files with float
89+ # coordinates to make sure we can process these
90+ # as well
91+ self .createFloatBoxFile (centers )
92+ self .createFloatCoordFile (centers )
93+ self .createFloatStarFile (centers )
94+
8895 # create lists of files
8996 self .all_mrc_paths = sorted (glob (os .path .join (self .data_folder , "sample*.mrc" )))
9097 # create file lists that will be used several times
@@ -113,6 +120,10 @@ def setUp(self):
113120 )
114121 )
115122
123+ self .float_box = os .path .join (self .data_folder , "float.box" )
124+ self .float_coord = os .path .join (self .data_folder , "float.coord" )
125+ self .float_star = os .path .join (self .data_folder , "float.star" )
126+
116127 def tearDown (self ):
117128 self .tmpdir .cleanup ()
118129
@@ -166,6 +177,47 @@ def createTestStarFiles(self, centers, index):
166177 starfile = StarFile (blocks = blocks )
167178 starfile .write (star_fp )
168179
180+ def createFloatBoxFile (self , centers ):
181+ # for testing float coordinates
182+ # create a box file (lower left corner and X/Y sizes)
183+ box_fp = os .path .join (self .data_folder , "float.box" )
184+ # populate box file with coordinates in box format
185+ with open (box_fp , "w" ) as box :
186+ for center in centers :
187+ # to make a box file, we convert the centers to lower left
188+ # corners by subtracting half the particle size (here: 256)
189+ lower_left_corners = (center [0 ] - 128 , center [1 ] - 128 )
190+ box .write (
191+ f"{ lower_left_corners [0 ]} .000\t { lower_left_corners [1 ]} .000\t 256.000\t 256.000\n "
192+ )
193+
194+ def createFloatCoordFile (self , centers ):
195+ # for testing float coordinates
196+ # create a coord file (only particle centers listed)
197+ coord_fp = os .path .join (self .data_folder , "float.coord" )
198+ # populate coord file with particle centers
199+ with open (coord_fp , "w" ) as coord :
200+ for center in centers :
201+ # .coord file usually contains just the centers
202+ coord .write (f"{ center [0 ]} .000\t { center [1 ]} .000\n " )
203+
204+ def createFloatStarFile (self , centers ):
205+ # for testing float coordinates
206+ # create a star file (only particle centers listed)
207+ star_fp = os .path .join (self .data_folder , "float.star" )
208+ # populate star file with particle centers
209+ x_coords = [str (center [0 ]) + ".000" for center in centers ]
210+ y_coords = [str (center [1 ]) + ".000" for center in centers ]
211+ blocks = OrderedDict (
212+ {
213+ "coordinates" : DataFrame (
214+ {"_rlnCoordinateX" : x_coords , "_rlnCoordinateY" : y_coords }
215+ )
216+ }
217+ )
218+ starfile = StarFile (blocks = blocks )
219+ starfile .write (star_fp )
220+
169221 def testLoadFromBox (self ):
170222 # ensure successful loading from box files
171223 BoxesCoordinateSource (self .files_box )
@@ -178,6 +230,24 @@ def testLoadFromStar(self):
178230 # ensure successful loading from particle center files (.star)
179231 CentersCoordinateSource (self .files_star , particle_size = 256 )
180232
233+ def testLoadFromBox_Floats (self ):
234+ # ensure successful loading from box files with float coordinates
235+ BoxesCoordinateSource ([(self .all_mrc_paths [0 ], self .float_box )])
236+
237+ def testLoadFromCenters_Floats (self ):
238+ # ensure successful loading from particle center files (.coord)
239+ # with float coordinates
240+ CentersCoordinateSource (
241+ [(self .all_mrc_paths [0 ], self .float_coord )], particle_size = 256
242+ )
243+
244+ def testLoadFromStar_Floats (self ):
245+ # ensure successful loading from particle center files (.star)
246+ # with float coordinates
247+ CentersCoordinateSource (
248+ [(self .all_mrc_paths [0 ], self .float_star )], particle_size = 256
249+ )
250+
181251 def testNonSquareParticles (self ):
182252 # nonsquare box sizes must fail
183253 with self .assertRaises (ValueError ):
0 commit comments