Debian Codegraph @

docs/source/code_inc/extract_ion_chromatogram.inc

raw
1 .. code-block:: python
2
3 #!/usr/bin/env python
4
5 import os
6
7 import pymzml
8
9
10 def main():
11 """
12 Demonstration of the extraction of a specific ion chromatogram, i.e. XIC or EIC
13
14 All intensities and m/z values for a target m/z are extracted.
15
16 usage:
17
18 ./extract_ion_chromatogram.py
19
20 """
21
22 example_file = os.path.join(
23 os.path.dirname(__file__), os.pardir, "tests", "data", "example.mzML"
24 )
25 run = pymzml.run.Reader(example_file)
26 time_dependent_intensities = []
27
28 MZ_2_FOLLOW = 70.06575775
29
30 for spectrum in run:
31 if spectrum.ms_level == 1:
32 has_peak_matches = spectrum.has_peak(MZ_2_FOLLOW)
33 if has_peak_matches != []:
34 for mz, I in has_peak_matches:
35 time_dependent_intensities.append(
36 [spectrum.scan_time_in_minutes(), I, mz]
37 )
38 print("RT \ti \tmz")
39 for rt, i, mz in time_dependent_intensities:
40 print("{0:5.3f}\t{1:13.4f}\t{2:10}".format(rt, i, mz))
41 return
42
43
44 if __name__ == "__main__":
45 main()