@@ -141,6 +141,21 @@ def read_file(self):
141141 if "rlnCoordinateZ" in list (val .keys ()):
142142 data_loop = key
143143 break
144+ elif "wrpCoordinateZ1" in list (val .keys ()):
145+ # Warp/M starfile: rename the relevant wrp* columns to their rln* equivalents.
146+ self .session .logger .info ("Changing Warp/M starfile columns to RELION format." )
147+ wrp_to_rln = [('wrpCoordinateX1' , 'rlnCoordinateX' ),
148+ ('wrpCoordinateY1' , 'rlnCoordinateY' ),
149+ ('wrpCoordinateZ1' , 'rlnCoordinateZ' ),
150+ ('wrpAngleRot1' , 'rlnAngleRot' ),
151+ ('wrpAngleTilt1' , 'rlnAngleTilt' ),
152+ ('wrpAnglePsi1' , 'rlnAnglePsi' ), ]
153+ for old , new in wrp_to_rln :
154+ if old in val .columns :
155+ self .session .logger .info ("Renaming {} to {}." .format (old , new ))
156+ val .rename (columns = {old : new }, inplace = True )
157+ data_loop = key
158+ break
144159
145160 # Abort if none found
146161 if data_loop is None :
@@ -260,14 +275,24 @@ def read_file(self):
260275
261276 # Now make particles
262277 df .reset_index ()
278+
279+ _raised_tomoname_parse_error = False
263280 for idx , row in df .iterrows ():
264281 p = self .new_particle ()
265282
266283 # Name
267284 if names_present :
268- n = row ["rlnTomoName" ].split ("_" )
269- num = int (n [- 1 ])
270- p ["rlnTomoName" ] = num
285+ try :
286+ n = row ["rlnTomoName" ].split ("_" )
287+ num = int (n [- 1 ])
288+ p ["rlnTomoName" ] = num
289+ except Exception as e :
290+ if not _raised_tomoname_parse_error :
291+ self .session .logger .warning (
292+ "Could not parse rlnTomoName the original way - applying workaround."
293+ )
294+ _raised_tomoname_parse_error = True
295+ p ["rlnTomoName" ] = int ('' .join (filter (str .isdigit , row ["rlnTomoName" ])))
271296
272297 # Position
273298 p ["pos_x" ] = row ["rlnCoordinateX" ]
0 commit comments