Debian Codegraph @

docs/source/code_inc/simple_parser.inc

raw
1 .. code-block:: python
2
3 #!/usr/bin/env python
4 import sys
5 import pymzml
6
7
8 def main(mzml_file):
9 """
10 Basic example script to demonstrate the usage of pymzML. Requires a mzML
11 file as first argument.
12
13 usage:
14
15 ./simple_parser.py <path_to_mzml_file>
16
17 Note:
18
19 This script uses the new syntax with the MS level being a property of
20 the spectrum class ( Spectrum.ms_level ). The old syntax can be found in
21 the script simple_parser_v2.py where the MS level can be queried as a key
22 (Spectrum['ms level'])
23
24
25 """
26 run = pymzml.run.Reader(mzml_file)
27 for n, spec in enumerate(run):
28 print(
29 "Spectrum {0}, MS level {ms_level} @ RT {scan_time:1.2f}".format(
30 spec.ID, ms_level=spec.ms_level, scan_time=spec.scan_time_in_minutes()
31 )
32 )
33 print("Parsed {0} spectra from file {1}".format(n, mzml_file))
34 print()
35
36
37 if __name__ == "__main__":
38 if len(sys.argv) < 2:
39 print(main.__doc__)
40 exit()
41 mzml_file = sys.argv[1]
42 main(mzml_file)