forked from pymzml/pymzML
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extreme_values.py
executable file
·44 lines (32 loc) · 1.06 KB
/
extreme_values.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python
import pymzml
from collections import defaultdict as ddict
import os
def main():
"""
Testscript to fetch the extreme m/z values from each spectrum
of an example file.
Usage:
./extreme_values.py
Parses the file '../tests/data/example.mzML' and extracts the smallest and
largest m/z from each each spectrum.
"""
example_file = os.path.join(
os.path.dirname(__file__), os.pardir, "tests", "data", "example.mzML"
)
run = pymzml.run.Reader(example_file)
extreme_mz_values = {}
number_of_mz_values = 2
for spectrum in run:
# print( spectrum.ID )
if spectrum.ms_level == 1:
extreme_mz_values[spectrum.ID] = spectrum.extreme_values("mz")
for spectrum_id, extreme_mz_tuple in extreme_mz_values.items():
assert len(extreme_mz_tuple) == number_of_mz_values
print(
"Spectrum {0}; lowest m/z: {1} highest m/z: {2}".format(
spectrum_id, *extreme_mz_tuple
)
)
if __name__ == "__main__":
main()