From 3900a2c6f97200c70e096e1b55d9670019c8df17 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 1 Sep 2026 20:56:20 +0200 Subject: [PATCH] patch for KeyError when attempting a direct index lookup for Thermo-style composite spectrum identifiers in mzML files where scan identifiers are formatted strictly as scan=X or integer scan numbers --- AA_stat/localization.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/AA_stat/localization.py b/AA_stat/localization.py index f2c5347..79e4a52 100644 --- a/AA_stat/localization.py +++ b/AA_stat/localization.py @@ -150,7 +150,19 @@ def preprocess_spectrum(reader, spec_id, kwargs, acc=0.01): # logger.debug('Returning cached spectrum %s', spec_id) return spectrum # logger.debug('Preprocessing new spectrum %s', spec_id) - original = reader[spec_id] + try: + original = reader[spec_id] + except KeyError: + import re + match = re.search(r"scan=(\d+)", str(spec_id)) + if match: + scan_num = match.group(1) + try: + original = reader[f"scan={scan_num}"] + except KeyError: + original = reader[scan_num] + else: + raise maxpeaks = kwargs.get('maxpeaks', 100) dynrange = kwargs.get('dynrange', 1000)