Skip to content

Commit

Permalink
fixed the scan capture
Browse files Browse the repository at this point in the history
  • Loading branch information
ypriverol committed Mar 9, 2025
1 parent c8c49f0 commit e959970
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
20 changes: 16 additions & 4 deletions quantmsutils/mzml/mzml_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def __init__(
self.parquet_writer = None
self.id_parquet_writer = None
self.acquisition_datetime = None
self.scan_pattern = re.compile(r"[scan|spectrum]=(\d+)")
self.scan_pattern = re.compile(r'(?:spectrum|scan)=(\d+)')

def transform_mzml_spectrum(
self,
Expand Down Expand Up @@ -320,10 +320,22 @@ def transform_mzml_spectrum(
self._write_batch()

def _extract_scan_id(self, spectrum: oms.MSSpectrum) -> str:
"""Extract scan ID from native ID using regex pattern"""
match = self.scan_pattern.findall(spectrum.getNativeID())
"""
Extracts the scan ID from a given spectrum's native ID.
Parameters
----------
spectrum : oms.MSSpectrum
The spectrum from which to extract the scan ID.
Returns
-------
str
The extracted scan ID if found, otherwise the original native ID.
"""
match = re.search(r'(?:spectrum|scan)=(\d+)', spectrum.getNativeID())
if match:
return match[0]
return match.group(1)
return spectrum.getNativeID()

def _extract_first_precursor_data(
Expand Down
17 changes: 17 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pathlib import Path

import pandas as pd
import pytest
from click.testing import CliRunner
from quantmsutils.quantmsutilsc import cli

Expand Down Expand Up @@ -142,3 +143,19 @@ def test_mzml_statistics():
assert len(table2) == len(table1)

assert result.exit_code == 0

def test_mzml_statistics_local():
runner = CliRunner()

mzml_path = TESTS_DIR / "test_data" / "TMT_Erwinia_1uLSike_Top10HCD_isol2_45stepped_60min_01.mzML"

# check if the file exist, delete it
ms_info_path = TESTS_DIR / "test_data" / "TMT_Erwinia_1uLSike_Top10HCD_isol2_45stepped_60min_01_ms_info.parquet"
if ms_info_path.exists():
ms_info_path.unlink()

result = runner.invoke(cli, ["mzmlstats", "--id_only", "--ms_path", mzml_path])
table = pd.read_parquet(ms_info_path)

assert len(table) > 0
assert result.exit_code == 0

0 comments on commit e959970

Please sign in to comment.