示例#1
0
 def callback(msms: PySpectrum, file_name: str):
     if msms is not None:
         highest = msms.highest_peaks(1)[0]
         spectra = msms.convert(msms).spectra
         splash = Splash().splash(Spectrum(spectra,
                                           SpectrumType.MS))
         out.write("{};{};{};{};{};{}\n".format(
             msms.ms_level, highest[0], highest[1],
             msms.scan_time[0], splash, spectra))
示例#2
0
 def test_add_tow_custom_specs(self):
     spec1 = Spectrum()
     spec2 = Spectrum()
     spec1.set_peaks([(100, 200)], "raw")
     spec2.set_peaks([(100, 200), (200, 300)], "raw")
     spec1 += spec2
     centroided_mz = spec1.peaks("centroided")[:, 0]
     centroided_i = spec1.peaks("centroided")[:, 1]
     assert np.allclose(centroided_mz, [100, 200], rtol=5e-6)
     assert np.allclose(centroided_i, [400, 300], atol=0.002)
示例#3
0
 def callback(msms: Spectrum, file_name: str):
     """
     builds our data list
     :param msms:
     :param file_name:
     :return:
     """
     data.append(msms.convert(msms))
示例#4
0
    def toSpectra(self, spectra: Spectrum) -> Spectra:
        peaks = spectra.peaks("centroided")

        f = lambda x: "{}:{}".format(x[0], x[1])
        result = []
        for x in peaks:
            result.append(f(x))

        result = " ".join(result)
        return Spectra(spectra=result)
示例#5
0
        def callback(msms: PySpectrum, file_name: str):
            with db.atomic() as transaction:
                if msms is None:
                    self.extract_record(file_name)

                else:
                    # 3. load sample object
                    record = MZMLSampleRecord.get(
                        MZMLSampleRecord.file_name == file_name)
                    # 3. associated msms spectra to it

                    try:
                        # 4. commit transaction
                        highest = msms.highest_peaks(1)[0]
                        spectra = msms.convert(msms, mode="raw").spectra
                        precurosr = msms.selected_precursors[0] if len(
                            msms.selected_precursors) > 0 else {}
                        scannumber = msms.index

                        splash = Splash().splash(
                            Spectrum(spectra, SpectrumType.MS))

                        spectra = MZMLMSMSSpectraRecord.create(
                            sample=record,
                            msms=spectra,
                            rt=msms.scan_time[0],
                            splash=splash,
                            scan_number=scannumber,
                            level=msms.ms_level,
                            base_peak=highest[0],
                            base_peak_intensity=highest[1],
                            precursor=precurosr['mz']
                            if 'mz' in precurosr else 0,
                            precursor_intensity=precurosr['i']
                            if 'i' in precurosr else 0,
                            precursor_charge=precurosr['charge']
                            if 'charge' in precurosr else 0,
                            ion_count=len(msms.peaks("centroided")))
                    except IndexError as e:
                        # not able to find highest peak
                        pass
示例#6
0
 def test_add_specs_to_empty_spec(self):
     spec1 = Spectrum()
     spec2 = Spectrum()
     spec2.set_peaks([(100, 200)], 'raw')
     spec1 += spec2
     centroided_mz = spec1.peaks('centroided')[:,0]
     centroided_i  = spec1.peaks('centroided')[:,1]
     assert np.allclose(
         centroided_mz,
         [100],
         rtol=5e-6
     )
     assert np.allclose(
         centroided_i,
         [200],
         atol=0.002
     )
示例#7
0
    def callback(msms: Spectrum, file_name: str):
        nonlocal count
        count = count + 1

        converted = msms.convert(msms)
示例#8
0
    def test_average_spectra(self):
        spec0 = Spectrum()
        spec1 = Spectrum()
        spec2 = Spectrum()

        spec1.set_peaks(np.array([(100, 200.0)]), "centroided")
        spec2.set_peaks(np.array([(100, 200.0), (200, 300.0)]), "centroided")

        scaled1 = spec1 / spec1.peaks("centroided")[:, 1].sum()
        spec0 += scaled1

        scaled2 = spec2 / spec2.peaks("centroided")[:, 1].sum()
        spec0 += scaled2

        centroided_peaks = spec0.peaks("centroided")
        assert np.allclose(centroided_peaks[:, 0], [100, 200])
        assert np.allclose(centroided_peaks[:, 1], [1.4, 0.6], atol=0.0001)
示例#9
0
    def test_average_spectra(self):
        spec0 = Spectrum()
        spec1 = Spectrum()
        spec2 = Spectrum()

        spec1.set_peaks(np.array([(100, 200)]), 'centroided')
        spec2.set_peaks(np.array([(100, 200), (200, 300)]), 'centroided')

        spec0 += (spec1 / spec1.peaks('centroided')[:,1].sum())
        spec0 += (spec2 / spec2.peaks('centroided')[:,1].sum())

        centroided_peaks = spec0.peaks('centroided')
        assert np.allclose(
            centroided_peaks[:,0],
            [100, 200]
        )
        assert np.allclose(
            centroided_peaks[:,1],
            [1.4, 0.6],
            atol=0.0001
        )
示例#10
0
 def callback(msms: Spectrum, file_name: str):
     nonlocal data
     data.append(msms.convert(msms))
示例#11
0
 def callback(msms: Spectrum, file_name: str):
     nonlocal data
     if msms is not None:
         data.append(msms.convert(msms))