diff --git a/src/io/RELION/RELIONParticleData.py b/src/io/RELION/RELIONParticleData.py index 88dc393..5155094 100644 --- a/src/io/RELION/RELIONParticleData.py +++ b/src/io/RELION/RELIONParticleData.py @@ -141,6 +141,21 @@ def read_file(self): if "rlnCoordinateZ" in list(val.keys()): data_loop = key break + elif "wrpCoordinateZ1" in list(val.keys()): + # Warp/M starfile: rename the relevant wrp* columns to their rln* equivalents. + self.session.logger.info("Changing Warp/M starfile columns to RELION format.") + wrp_to_rln = [('wrpCoordinateX1', 'rlnCoordinateX'), + ('wrpCoordinateY1', 'rlnCoordinateY'), + ('wrpCoordinateZ1', 'rlnCoordinateZ'), + ('wrpAngleRot1', 'rlnAngleRot'), + ('wrpAngleTilt1', 'rlnAngleTilt'), + ('wrpAnglePsi1', 'rlnAnglePsi'), ] + for old, new in wrp_to_rln: + if old in val.columns: + self.session.logger.info("Renaming {} to {}.".format(old, new)) + val.rename(columns={old: new}, inplace=True) + data_loop = key + break # Abort if none found if data_loop is None: @@ -260,14 +275,24 @@ def read_file(self): # Now make particles df.reset_index() + + _raised_tomoname_parse_error = False for idx, row in df.iterrows(): p = self.new_particle() # Name if names_present: - n = row["rlnTomoName"].split("_") - num = int(n[-1]) - p["rlnTomoName"] = num + try: + n = row["rlnTomoName"].split("_") + num = int(n[-1]) + p["rlnTomoName"] = num + except Exception as e: + if not _raised_tomoname_parse_error: + self.session.logger.warning( + "Could not parse rlnTomoName the original way - applying workaround." + ) + _raised_tomoname_parse_error = True + p["rlnTomoName"] = int(''.join(filter(str.isdigit, row["rlnTomoName"]))) # Position p["pos_x"] = row["rlnCoordinateX"]