File: deconvolution.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 (74 lines) | stat: -rwxr-xr-x 2,598 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python

"""

Example for retrieving monoisotopic peaks from the processed spectrum.
The python-matplotlib has to be installed for plotting. Otherwise a list of
monoisotopic peaks will be returned.

Example:

>>> import pymzml, get_example_file
>>> example_file = get_example_file.open_example('deconvolution.mzML.gz')
>>> run = pymzml.MSRun(example_file, MS1_Precision = 5e-6, MSn_Precision = 20e-6)
>>> for spectrum in run:
...     if spectrum.lvl == 2:
...        l = spectrum.get_deisotopedMZ_for_chargeDeconvolution()
...         if len(l) > 0:
...             print(l)

"""

from __future__ import print_function
import sys
import os
import pymzml
import get_example_file

def deconvolution():
    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 spec in run:
        charge_dict = dict()
        for mz, i, charge, n in spec._get_deisotopedMZ_for_chargeDeconvolution():
            charge_dict[mz] = charge
        
        
        p   = pymzml.plot.Factory()
        
        tmp = spec.deRef()
        tmp.reduce((590, 615))
    
        p.newPlot(header = 'centroided I', mzRange = [590, 615])
        p.add(spec.centroidedPeaks, color=(200,00,00), style='sticks')
        for mz, i in tmp.centroidedPeaks:
            try:
                p.add([ (mz,'mz = {0}, z = {1}'.format(mz, charge_dict[mz]) ) ], color=(000,200,00), style='label' )
            except KeyError:
                p.add([ (mz,'mz = {0}'.format(mz) ) ], color=(000,200,00), style='label' )

        tmp = spec.deRef()
        tmp.reduce((1190, 1215))

        p.newPlot(header = 'centroided II', mzRange = [1190, 1215])
        p.add(spec.centroidedPeaks, color=(200,00,00), style='sticks')
        for mz, i in tmp.centroidedPeaks:
            try:
                p.add([ (mz,'mz = {0}, z = {1}'.format(mz, charge_dict[mz]) ) ], color=(000,200,00), style='label' )
            except KeyError:
                p.add([ (mz,'mz = {0}'.format(mz) ) ], color=(000,200,00), style='label' )        
        
        
        
        p.newPlot(header = 'deconvoluted', mzRange = [1190, 1215])
        p.add(spec.deconvolutedPeaks, color=(200,00,00), style='sticks')

        tmp = spec.deRef()
        tmp.reduce((1190, 1215))
        for mass, i in tmp.deconvolutedPeaks:
            p.add([ (mass,'mass = {0}'.format(mass) ) ], color=(000,200,00), style='label' )  
        
        p.save(filename = "output/deconvolution.xhtml",)
        
if __name__ == '__main__':
    deconvolution()