File: extreme_values.py

package info (click to toggle)
python-pymzml 2.5.2%2Brepack1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 27,792 kB
  • sloc: python: 6,495; pascal: 341; makefile: 233; sh: 30
file content (44 lines) | stat: -rwxr-xr-x 1,081 bytes parent folder | download | duplicates (3)
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()