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))
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)
def callback(msms: Spectrum, file_name: str): """ builds our data list :param msms: :param file_name: :return: """ data.append(msms.convert(msms))
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)
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
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 )
def callback(msms: Spectrum, file_name: str): nonlocal count count = count + 1 converted = msms.convert(msms)
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)
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 )
def callback(msms: Spectrum, file_name: str): nonlocal data data.append(msms.convert(msms))
def callback(msms: Spectrum, file_name: str): nonlocal data if msms is not None: data.append(msms.convert(msms))