-
Notifications
You must be signed in to change notification settings - Fork 6
/
MSdataset.py
42 lines (37 loc) · 1.52 KB
/
MSdataset.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
import numpy as np
from pyMS.mass_spectrum import mass_spectrum
class MSdataset():
def __init__(self):
self.index_list = []
self.mz_min=float("inf")
self.mz_max=0
self.spectra = []#dict of mass_spectrum objects
def data_summary(self):
# check if all spectra are the same length
spec_length = np.zeros(len(self.index_list))
for ii in self.index_list:
this_spectrum = self.get_spectrum(ii)
tmp_shape = this_spectrum.mzs.shape
spec_length[ii]=tmp_shape[0]
if this_spectrum.mzs[0]<self.mz_min:
self.mz_min=this_spectrum.mzs[0]
if this_spectrum.mzs[-1]>self.mz_max:
self.mz_max=this_spectrum.mzs[-1]
if np.all(spec_length==spec_length[1]):
self.consistent_mz = True
else:
self.consistent_mz = False
def _del_(self):
# clean up afterwards
self.hdf.close()
def get_spectrum(self,index):
return self.spectra[index]
def add_spectrum(self,profile_mzs=[],profile_intensities=[],centroids_mz=[],centroid_intensity=[],index=[]):
if profile_mzs==[] & centroids_mz==[]:
raise ValueError('one of profile or centroids mzs should be non-empty')
new_spectrum=mass_spectrum()
new_spectrum.add_spectrum(profile_mzs,profile_intensities)
new_spectrum.add_centroids(centroids_mz,centroid_intensity)
if index==[]:
self.index_list.append(max(self.index_list)+1)
self.spectra.append(new_spectrum)