File: highestPeaks.py

package info (click to toggle)
python-pymzml 0.7.6-dfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 66,128 kB
  • ctags: 335
  • sloc: python: 2,428; makefile: 142; sh: 38
file content (47 lines) | stat: -rwxr-xr-x 1,322 bytes parent folder | download | duplicates (2)
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
45
46
47
#!/usr/bin/env python3.2

"""
Testscript to isolate the n-highest peaks from an example file.

Example:

>>> example_file = get_example_file.open_example('deconvolution.mzML.gz')
>>> run = pymzml.run.Reader(example_file, MS1_Precision = 5e-6, MSn_Precision = 20e-6)
>>> for spectrum in run:
...     if spectrum["ms level"] == 2:
...         if spectrum["id"] == 1770:
...             for mz,i  in spectrum.highestPeaks(5):
...                 print(mz,i)

"""
    
import sys
import pymzml
import get_example_file

def main(verbose = False):
    
    ref_intensities = set([9258.819334518503, 19141.735187697403, 20922.463809964283, 10594.642802391083, 9193.546071711491])
    
    example_file = get_example_file.open_example('deconvolution.mzML.gz')
    
    run = pymzml.run.Reader(example_file, MS1_Precision = 5e-6, MSn_Precision = 20e-6)
    
    highest_i_list = list()
    
    for spectrum in run:
        if spectrum["ms level"] == 2:
            if spectrum["id"] == 1770:
                for mz,i  in spectrum.highestPeaks(5):
                    highest_i_list.append(i)

    if set(highest_i_list) == set(ref_intensities):
        if verbose:
            print("Function .highestPeaks worked properly")
        return True
    else:
        return False


if __name__ == '__main__':
    main(verbose = True)