-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmass_spectrum.py
78 lines (62 loc) · 2.54 KB
/
mass_spectrum.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
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
import numpy as np
import sys
sys.path.append('/Users/palmer/Documents/python_codebase')
import pyMS.normalisation
class mass_spectrum():
# a class that describes a single mass spectrum
def __init__(self):
self.mzs = []
self.intensities = []
self.centroids = []
self.norm = []
## Private basic spectrum I/O
def __add_mzs(self, mzs):
self.mzs = mzs
def __add_intensities(self, intensities):
self.intensities = intensities
def __get_mzs(self):
return np.asarray(self.mzs)
def __get_intensities(self):
return np.asarray(self.intensities)
def __get_mzs_centroids(self):
return np.asarray(self.centroids)
def __get_intensities_centroids(self):
return np.asarray(self.centroids_intensity)
def __add_centroids_mzs(self, mz_list):
self.centroids = mz_list
def __add_centroids_intensities(self, intensity_list):
self.centroids_intensity = intensity_list
## Public methods
def add_spectrum(self, mzs, intensities):
if len(mzs) != len(intensities):
raise IOError("mz/intensities vector different lengths")
self.__add_mzs(mzs)
self.__add_intensities(intensities)
def add_centroids(self, mz_list, intensity_list):
if len(mz_list) != len(intensity_list):
raise IOError("mz/intensities vector different lengths")
self.__add_centroids_mzs(mz_list)
self.__add_centroids_intensities(intensity_list)
def get_spectrum(self, source='profile'):
if source == 'profile':
mzs = self.__get_mzs()
intensities = self.__get_intensities()
elif source == 'centroids':
mzs = self.__get_mzs_centroids()
intensities = self.__get_intensities_centroids()
else:
raise IOError('spectrum source should be profile or centroids')
#max_idx = np.argmax(intensities)
return mzs, intensities
def normalise_spectrum(self,method="tic"):
self.centroids_intensity = pyMS.normalisation.apply_normalisation(self.centroids_intensity, method)
self.intensities = pyMS.normalisation.apply_normalisation(self.intensities, method)
self.norm.append("method")
class MSn_spectrum(mass_spectrum):
def __init__(self):
self.ms_transitions = []
self.ms_level = 1
def add_transition(self, transitions):
# transitions is a list of ms fragmentation acceptance windows
self.transitions = transitions
self.mz_level = len(self.transitions) + 1