Skip to content

Commit

Permalink
Merge pull request #222 from MannLabs/sage-spec-idx
Browse files Browse the repository at this point in the history
FIX Sage spec idx
  • Loading branch information
GeorgWa authored Oct 31, 2024
2 parents d997a98 + 68d4c20 commit 7a3be9d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
22 changes: 18 additions & 4 deletions alphabase/psm_reader/sage_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,17 +538,31 @@ 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
-------
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])
return int(re.search(r"scan=(\d+)", scan_indicator_str).group(1)) - 1


class SageReaderBase(PSMReaderBase):
Expand Down
4 changes: 2 additions & 2 deletions nbs_tests/psm_reader/sage_reader.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
},
{
Expand Down Expand Up @@ -195,7 +195,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "python3",
"display_name": "alpha",
"language": "python",
"name": "python3"
},
Expand Down

0 comments on commit 7a3be9d

Please sign in to comment.