From d9d879777b9dbe76a8b235eb4fec162d6d393e7f Mon Sep 17 00:00:00 2001 From: GeorgWa Date: Sat, 28 Sep 2024 20:01:31 +0200 Subject: [PATCH 1/4] 1-based sage scan idx --- alphabase/psm_reader/sage_reader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alphabase/psm_reader/sage_reader.py b/alphabase/psm_reader/sage_reader.py index 5edb3804..d0687d20 100644 --- a/alphabase/psm_reader/sage_reader.py +++ b/alphabase/psm_reader/sage_reader.py @@ -548,7 +548,7 @@ def _sage_spec_idx_from_scan_nr(scan_nr: str) -> int: The scan_nr field in Sage output. """ - return int(scan_nr.split("=")[-1]) + return int(scan_nr.split("=")[-1]) - 1 class SageReaderBase(PSMReaderBase): From a8f850c61bb3be70041f93effae826a282c0b5b3 Mon Sep 17 00:00:00 2001 From: GeorgWa Date: Sat, 28 Sep 2024 20:25:44 +0200 Subject: [PATCH 2/4] fix test --- nbs_tests/psm_reader/sage_reader.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nbs_tests/psm_reader/sage_reader.ipynb b/nbs_tests/psm_reader/sage_reader.ipynb index 2646aba0..b7c989a7 100644 --- a/nbs_tests/psm_reader/sage_reader.ipynb +++ b/nbs_tests/psm_reader/sage_reader.ipynb @@ -47,7 +47,7 @@ "outputs": [], "source": [ "#| hide\n", - "assert _sage_spec_idx_from_scan_nr('controllerType=0 controllerNumber=1 scan=7846') == 7846" + "assert _sage_spec_idx_from_scan_nr('controllerType=0 controllerNumber=1 scan=7846') == 7845" ] }, { @@ -195,7 +195,7 @@ ], "metadata": { "kernelspec": { - "display_name": "python3", + "display_name": "alpha", "language": "python", "name": "python3" }, From 91cdb791f5b17ee725fd2e76ab3ee6a486192ace Mon Sep 17 00:00:00 2001 From: GeorgWa Date: Wed, 30 Oct 2024 14:19:46 +0100 Subject: [PATCH 3/4] fixes --- alphabase/psm_reader/sage_reader.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/alphabase/psm_reader/sage_reader.py b/alphabase/psm_reader/sage_reader.py index d0687d20..ee46840b 100644 --- a/alphabase/psm_reader/sage_reader.py +++ b/alphabase/psm_reader/sage_reader.py @@ -540,6 +540,7 @@ def _get_annotated_mod_df() -> pd.DataFrame: def _sage_spec_idx_from_scan_nr(scan_nr: str) -> int: """Extract the spectrum index from the scan_nr field in Sage output. + Sage uses 1-based indexing for spectra, so we need to subtract 1 to convert to 0-based indexing. Parameters ---------- @@ -547,8 +548,20 @@ def _sage_spec_idx_from_scan_nr(scan_nr: str) -> int: scan_nr : str The scan_nr field in Sage output. + Returns + ------- + + int + The 0-based spectrum index. + + Examples + -------- + + >>> _sage_spec_idx_from_scan_nr('controllerType=0 controllerNumber=1 scan=7846') + 7845 + """ - return int(scan_nr.split("=")[-1]) - 1 + return int(re.search(r"scan=(\d+)", scan_nr).group(1)) - 1 class SageReaderBase(PSMReaderBase): From 68d4c20de8aa1f88965fc72ea84c846e50f22a24 Mon Sep 17 00:00:00 2001 From: GeorgWa Date: Wed, 30 Oct 2024 14:27:29 +0100 Subject: [PATCH 4/4] fix --- alphabase/psm_reader/sage_reader.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/alphabase/psm_reader/sage_reader.py b/alphabase/psm_reader/sage_reader.py index ee46840b..4d237514 100644 --- a/alphabase/psm_reader/sage_reader.py +++ b/alphabase/psm_reader/sage_reader.py @@ -538,15 +538,16 @@ def _get_annotated_mod_df() -> pd.DataFrame: ] -def _sage_spec_idx_from_scan_nr(scan_nr: str) -> int: +def _sage_spec_idx_from_scan_nr(scan_indicator_str: str) -> int: """Extract the spectrum index from the scan_nr field in Sage output. Sage uses 1-based indexing for spectra, so we need to subtract 1 to convert to 0-based indexing. Parameters ---------- - scan_nr : str - The scan_nr field in Sage output. + scan_indicator_str : str + The scan_indicator_str field in Sage output. + e.g. `'controllerType=0 controllerNumber=1 scan=7846'` Returns ------- @@ -561,7 +562,7 @@ def _sage_spec_idx_from_scan_nr(scan_nr: str) -> int: 7845 """ - return int(re.search(r"scan=(\d+)", scan_nr).group(1)) - 1 + return int(re.search(r"scan=(\d+)", scan_indicator_str).group(1)) - 1 class SageReaderBase(PSMReaderBase):