File: obj_peak.py

package info (click to toggle)
mmass 5.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 8,396 kB
  • sloc: python: 33,183; xml: 7,925; ansic: 1,722; makefile: 83; sh: 2
file content (186 lines) | stat: -rw-r--r-- 4,411 bytes parent folder | download
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# -------------------------------------------------------------------------
#     Copyright (C) 2005-2012 Martin Strohalm <www.mmass.org>

#     This program is free software; you can redistribute it and/or modify
#     it under the terms of the GNU General Public License as published by
#     the Free Software Foundation; either version 3 of the License, or
#     (at your option) any later version.

#     This program is distributed in the hope that it will be useful,
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#     GNU General Public License for more details.

#     Complete text of GNU GPL can be found in the file LICENSE.TXT in the
#     main directory of the program.
# -------------------------------------------------------------------------

# load stopper
from mod_stopper import CHECK_FORCE_QUIT

# load objects
import blocks

# load modules
import mod_basics


# PEAK OBJECT DEFINITION
# ----------------------

class peak:
    """Peak object definition."""
    
    def __init__(self, mz, ai=0., base=0., sn=None, charge=None, isotope=None, fwhm=None, group='', **attr):
        
        self.mz = float(mz)
        self.ai = float(ai)
        self.base = float(base)
        self.sn = sn
        self.charge = charge
        self.isotope = isotope
        self.fwhm = fwhm
        self.group = group
        
        self.childScanNumber = None
        
        # set intensity
        self.ri = 1.
        self.intensity = self.ai - self.base
        
        # set resolution
        self.resolution = None
        if self.fwhm:
            self.resolution = self.mz/self.fwhm
        
        # set buffers
        self._mass = None
        
        # get additional attributes
        self.attributes = {}
        for name, value in attr.items():
            self.attributes[name] = value
    # ----
    
    
    def reset(self):
        """Clear peak buffers and set intensity and resolution."""
        
        # clear mass buffer
        self._mass = None
        
        # update intensity
        self.intensity = self.ai - self.base
        
        # update resolution
        self.resolution = None
        if self.fwhm:
            self.resolution = self.mz/self.fwhm
    # ----
    
    
    
    # GETTERS
    
    def mass(self):
        """Get neutral peak mass."""
        
        # check charge
        if self.charge == None:
            return None
        
        # check mass buffer
        if self._mass != None:
            return self._mass
        
        # calculate neutral mass
        self._mass = mod_basics.mz(self.mz, 0, self.charge, agentFormula='H', agentCharge=1)
        
        return self._mass
    # ----
    
    
    
    # SETTERS
    
    def setmz(self, mz):
        """Set new m/z value."""
        
        # update value
        self.mz = mz
        
        # update resolution
        self.resolution = None
        if self.fwhm:
            self.resolution = self.mz/self.fwhm
        
        # clear mass buffer
        self._mass = None
    # ----
    
    
    def setai(self, ai):
        """Set new a.i. value."""
        
        # update value
        self.ai = ai
        
        # update intensity
        self.intensity = self.ai - self.base
    # ----
    
    
    def setbase(self, base):
        """Set new baseline value."""
        
        # update value
        self.base = base
        
        # update intensity
        self.intensity = self.ai - self.base
    # ----
    
    
    def setsn(self, sn):
        """Set new s/n value."""
        self.sn = sn
    # ----
    
    
    def setcharge(self, charge):
        """Set new charge value."""
        
        # update value
        self.charge = charge
        
        # clear mass buffer
        self._mass = None
    # ----
    
    
    def setisotope(self, isotope):
        """Set new isotope value."""
        self.isotope = isotope
    # ----
    
    
    def setfwhm(self, fwhm):
        """Set new fwhm value."""
        
        # update value
        self.fwhm = fwhm
        
        # update resolution
        self.resolution = None
        if self.fwhm:
            self.resolution = self.mz/self.fwhm
    # ----
    
    
    def setgroup(self, group):
        """Set new group name value."""
        self.group = group
    # ----