Debian Codegraph @

docs/source/code_inc/simple_parser_v2.inc

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