From 935a0967d3014d3cce9ba75325a6ad6c20054aff Mon Sep 17 00:00:00 2001 From: Mart Last Date: Sun, 5 Oct 2025 14:39:21 +0100 Subject: [PATCH 1/2] - fix rlnTomoName parsing bug - added support for Warp starfiles --- src/io/RELION/RELIONParticleData.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/io/RELION/RELIONParticleData.py b/src/io/RELION/RELIONParticleData.py index 88dc393..311ac66 100644 --- a/src/io/RELION/RELIONParticleData.py +++ b/src/io/RELION/RELIONParticleData.py @@ -141,6 +141,19 @@ def read_file(self): if "rlnCoordinateZ" in list(val.keys()): data_loop = key break + elif 'wrpCoordinateZ1' in list(val.keys()): # Check whether it's a Warp/M starfile and if so, edit parameter names. + print(f"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: + print(f'renaming {old} to {new}') + val.rename(columns={old: new}, inplace=True) + data_loop = key # Abort if none found if data_loop is None: @@ -260,14 +273,21 @@ 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 _raised_tomoname_parse_error else print(f'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"] From 9d26994d680eec0f4a3942840f7cf91abfe0bfe9 Mon Sep 17 00:00:00 2001 From: uermel Date: Tue, 16 Jun 2026 15:38:47 -0700 Subject: [PATCH 2/2] use logger for printing --- src/io/RELION/RELIONParticleData.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/io/RELION/RELIONParticleData.py b/src/io/RELION/RELIONParticleData.py index 311ac66..5155094 100644 --- a/src/io/RELION/RELIONParticleData.py +++ b/src/io/RELION/RELIONParticleData.py @@ -141,8 +141,9 @@ def read_file(self): if "rlnCoordinateZ" in list(val.keys()): data_loop = key break - elif 'wrpCoordinateZ1' in list(val.keys()): # Check whether it's a Warp/M starfile and if so, edit parameter names. - print(f"Changing Warp/M starfile columns to Relion format.") + 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'), @@ -151,9 +152,10 @@ def read_file(self): ('wrpAnglePsi1', 'rlnAnglePsi'), ] for old, new in wrp_to_rln: if old in val.columns: - print(f'renaming {old} to {new}') + 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: @@ -285,8 +287,11 @@ def read_file(self): num = int(n[-1]) p["rlnTomoName"] = num except Exception as e: - "" if _raised_tomoname_parse_error else print(f'Could not parse rlnTomoName the original way - applying workaround.') - _raised_tomoname_parse_error = True + 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