Skip to content

Commit 3a5fa7b

Browse files
authored
Merge pull request #471 from cbielow/fixs
add SpectrumLookup example
2 parents c9c4752 + 24b397a commit 3a5fa7b

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

docs/source/user_guide/ms_data.rst

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,8 @@ mass spectra that are not :term:`MS1` spectra
653653
654654
# 'filtered' now only contains spectra with MS level >= 2
655655
656-
Alternatively, we can chose to load only spectra of a certain level using :py:class:`~.PeakFileOptions`, which is even more efficient.
656+
Alternatively, we can choose to load only spectra of a certain level using :py:class:`~.PeakFileOptions`, which is even more efficient since
657+
unwanted data is not even loaded into memory.
657658

658659
.. code-block:: python
659660
:linenos:
@@ -669,7 +670,7 @@ Alternatively, we can chose to load only spectra of a certain level using :py:cl
669670
670671
# 'filtered' now only contains spectra with MS level == 2
671672
672-
# Now exp contains only MS level 2 spectra
673+
Now exp contains only MS level 2 spectra
673674

674675

675676
Filtering by Scan Number
@@ -687,6 +688,33 @@ to only retain a list of MS scans we are interested in:
687688
for k, s in enumerate(inp):
688689
if k in scan_nrs:
689690
filtered.addSpectrum(s)
691+
692+
Note: the scan numbers are the index of the respective spectra in the data file (mzML). This may not be identical to the vendor scan number, especially if the data has been sliced/filtered before.
693+
694+
Advanced Filtering of NativeID via SpectrumLookup
695+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
696+
697+
To find a spectrum using their original scan number from their native ID we can use :py:class:`~.SpectrumLookup`:
698+
699+
.. code-block:: python
700+
:linenos:
701+
702+
lookup = oms.SpectrumLookup()
703+
704+
## now, we need to define how to extract the vendor scan number from the 'id' attribute in mzML:
705+
# Bruker may have:
706+
# <spectrum index="0" id="scan=19" defaultArrayLength="15">
707+
# thus we can use (this would also work for Thermo native IDs)
708+
lookup.readSpectra(inp, "scan=(?<SCAN>\d+)") ## required: creates an internal look-up table
709+
710+
vendor_scan_nrs = [19, 21] ## our test.mzML contains 4 spectra, starting at scan=19
711+
712+
filtered = oms.MSExperiment() ## our result, with all spectra we were looking for
713+
for v_scan_nr in vendor_scan_nrs:
714+
filtered.addSpectrum(inp[lookup.findByScanNumber(v_scan_nr)])
715+
716+
filtered.size() ## prints '2'
717+
filtered.updateRanges() ## make sure RT and m/z ranges are up to date
690718
691719
692720
Filtering Mass Spectra and Peaks

0 commit comments

Comments
 (0)