Exemplo n.º 1
0
 def test_get_centroid_spectrum(self):
     mzs = [0, 1, 2, 3]
     vals = [1, 2, 1, 0]
     this_spectrum = mass_spectrum()
     this_spectrum.add_centroids(mzs, vals)
     [mzs_, vals_] = this_spectrum.get_spectrum(source='centroids')
     self.assertItemsEqual(mzs, mzs_)
     self.assertItemsEqual(vals, vals_)
 def test_get_centroid_spectrum(self):
     mzs = [0, 1, 2, 3]
     vals = [1, 2, 1, 0]
     this_spectrum = mass_spectrum()
     this_spectrum.add_centroids(mzs, vals)
     [mzs_, vals_] = this_spectrum.get_spectrum(source='centroids')
     self.assertItemsEqual(mzs, mzs_)
     self.assertItemsEqual(vals, vals_)
Exemplo n.º 3
0
 def test_get_profile_spectrum(self):
     mzs = [0, 1, 2, 3]
     vals = [1, 2, 1, 0]
     this_spectrum = mass_spectrum()
     this_spectrum.add_spectrum(mzs, vals)
     [mzs_, vals_] = this_spectrum.get_spectrum(source='profile')
     self.assertItemsEqual(mzs, mzs_)
     self.assertItemsEqual(vals, vals_)
 def test_get_profile_spectrum(self):
     mzs = [0, 1, 2, 3]
     vals = [1, 2, 1, 0]
     this_spectrum = mass_spectrum()
     this_spectrum.add_spectrum(mzs, vals)
     [mzs_, vals_] = this_spectrum.get_spectrum(source='profile')
     self.assertItemsEqual(mzs, mzs_)
     self.assertItemsEqual(vals, vals_)
Exemplo n.º 5
0
 def get_spectrum_imzml(self, index):
     mzs, intensities = self.imzml.getspectrum(index)
     ## temp hack -> assume centroided
     this_spectrum = mass_spectrum()
     if self.spectrum_type == 'centroids':
         this_spectrum.add_centroids(mzs, intensities)
     else:
         this_spectrum.add_spectrum(mzs, intensities)
     return this_spectrum
Exemplo n.º 6
0
 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)
 def test_add_centroids(self):
     mzs_counts_list = [[[0, 1, 2], [2, 2, 2]],
                        [[0, 0, 0], [0, 0, 0]],
                        [[0, 1, 2], [2, ]]
                        ]
     test_vals_should_add = [True,
                             True,
                             False,
                             ]
     for mzs_counts, should_add in zip(mzs_counts_list, test_vals_should_add):
         this_spectrum = mass_spectrum()
         if should_add:
             this_spectrum.add_centroids(mzs_counts[0], mzs_counts[1])
             self.assertItemsEqual(this_spectrum._centroids, mzs_counts[0])
             self.assertItemsEqual(this_spectrum._centroids_intensity, mzs_counts[1])
         else:
             with self.assertRaises(IOError):
                 this_spectrum.add_centroids(mzs_counts[0], mzs_counts[1])
Exemplo n.º 8
0
 def get_spectrum_hdf5(self, index):
     import h5py
     this_spectrum = mass_spectrum()
     tmp_str = '/spectral_data/%d' % (index)
     try:
         this_spectrum.add_spectrum(self.hdf[tmp_str + '/mzs/'],
                                    self.hdf[tmp_str + '/intensities/'])
         got_spectrum = True
     except KeyError:
         got_spectrum = False
     try:
         this_spectrum.add_centroids(
             self.hdf[tmp_str + '/centroid_mzs/'],
             self.hdf[tmp_str + '/centroid_intensities/'])
         got_centroids = True
     except KeyError:
         got_centroids = False
     if not any([got_spectrum, got_centroids]):
         raise ValueError(
             'No spectral data found in index {}'.format(index))
     return this_spectrum
Exemplo n.º 9
0
 def test_add_centroids(self):
     mzs_counts_list = [[[0, 1, 2], [2, 2, 2]], [[0, 0, 0], [0, 0, 0]],
                        [[0, 1, 2], [
                            2,
                        ]]]
     test_vals_should_add = [
         True,
         True,
         False,
     ]
     for mzs_counts, should_add in zip(mzs_counts_list,
                                       test_vals_should_add):
         this_spectrum = mass_spectrum()
         if should_add:
             this_spectrum.add_centroids(mzs_counts[0], mzs_counts[1])
             self.assertItemsEqual(this_spectrum._centroids, mzs_counts[0])
             self.assertItemsEqual(this_spectrum._centroids_intensity,
                                   mzs_counts[1])
         else:
             with self.assertRaises(IOError):
                 this_spectrum.add_centroids(mzs_counts[0], mzs_counts[1])
Exemplo n.º 10
0
 def make_spectrum(self, mzs, vals, centroid_mzs, centroid_vals):
     this_spectrum = mass_spectrum()
     this_spectrum.add_spectrum(mzs, vals)
     this_spectrum.add_centroids(centroid_mzs, centroid_vals)
     return this_spectrum
 def make_spectrum(self, mzs, vals, centroid_mzs, centroid_vals):
     this_spectrum = mass_spectrum()
     this_spectrum.add_spectrum(mzs, vals)
     this_spectrum.add_centroids(centroid_mzs, centroid_vals)
     return this_spectrum