Esempio n. 1
0
def MZMLtoSpectrum(filename, rtOnly=False):
    spectra = []
    import pyopenms

    # need to use OnDiscMSExperiment to sequentially read
    # spectra without loading whole file into memory
    experiment = pyopenms.OnDiscMSExperiment()
    pyopenms.IndexedMzMLFileLoader().load(filename, experiment)

    for i in range(experiment.getNrSpectra()):
        spectrum = experiment.getSpectrum(i)
        try:
            time = spectrum.getRT()
        except KeyError, e:
            time_prev = time
            if delta_time > 0:
                time += delta_time
            else:
                time += 1.0

        if rtOnly:
            mzData, intData, spectrum = None, None, None

        else:
            (mzData, intData) = spectrum.get_peaks()
            if mzData.shape[0] == 0:
                mzData = np.empty(0, dtype='float32')
                intData = np.empty(0, dtype='float32')

        yield Spectrum(time, mzData, intData, spectrum)
    def test_readfile_content(self):
        e = pyopenms.OnDiscMSExperiment()
        pyopenms.IndexedMzMLFileLoader().load(self.filename, e)

        self.assertEqual(e.getNrSpectra(), 2)
        self.assertEqual(e.getNrChromatograms(), 1)

        s = e.getSpectrum(0)
        data_mz, data_int = s.get_peaks()
        self.assertEqual(len(data_mz), 19914)
        self.assertEqual(len(data_int), 19914)

        self.assertEqual(len(e.getSpectrum(1).get_peaks()[0]), 19800)
        self.assertEqual(len(e.getSpectrum(1).get_peaks()[1]), 19800)
        self.assertEqual(len(e.getChromatogram(0).get_peaks()[0]), 48)
        self.assertEqual(len(e.getChromatogram(0).get_peaks()[1]), 48)

        if False:
            # Currently we don't deal with exceptions properly
            raised = False
            try:
                e.getChromatogram(2).get_peaks()
            except Exception as e:
                raised = True

            self.assertTrue(raised)
Esempio n. 3
0
    def test_readfile_content(self):
        e = pyopenms.OnDiscMSExperiment()
        pyopenms.IndexedMzMLFileLoader().load(self.filename, e)

        self.assertEqual(e.getNrSpectra(), 2)
        self.assertEqual(e.getNrChromatograms(), 1)

        s = e.getSpectrum(0)
        data = s.get_peaks()
        self.assertEqual(len(data), 19914)

        self.assertEqual(len(e.getSpectrum(1).get_peaks()), 19800)
        self.assertEqual(len(e.getChromatogram(0).get_peaks()), 48)

        raised = False
        try:
            e.getChromatogram(2).get_peaks()
        except Exception, e:
            raised = True
Esempio n. 4
0
    def test_readfile(self):
        e = pyopenms.OnDiscMSExperiment()
        success = pyopenms.IndexedMzMLFileLoader().load(self.filename, e)

        self.assertTrue(success)