How to use the pyopenms.MSSpectrum function in pyopenms

To help you get started, we’ve selected a few pyopenms examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github msproteomicstools / msproteomicstools / analysis / data_conversion / MSE2mzML.py View on Github external
rt = float(rt_[2])*60
    # Convert to mz/int pairs, then into separate arrays filtering out zero-intensity peaks
    pairs = [it.split() for it in stack[3:] if len(it.strip()) > 0 and float(it.split()[1]) > 0.0]
    try:
        mz = [float(it[0]) for it in pairs]
        intensity = [float(it[1]) for it in pairs]
    except ValueError:
        print("Could not convert", len(stack), "with pairs" , len(pairs))
        return
    assert len(mz) == len(intensity)
    #
    print("Handle scan at rt", rt)
    peaks = np.ndarray(shape=(len(mz), 2), dtype=np.float32)
    peaks[:,0] = mz
    peaks[:,1] = intensity
    s = pyopenms.MSSpectrum()
    s.set_peaks(peaks)
    s.setRT(rt)
    # set MSLevel to 1 for all
    s.setMSLevel(1)
    outexp.addSpectrum(s)
github msproteomicstools / msproteomicstools / analysis / scripts / DIA / convertMassLynxTomzML.py View on Github external
pairs = [it.split() for it in stack[3:] if len(it.strip()) > 0 and float(it.split()[1]) > 0.0]
    #mz = [float(it.split()[0]) for it in stack[3:] if len(it.strip()) > 0]
    #intensity = [float(it.split()[1]) for it in stack[3:] if len(it.strip()) > 0]
    try:
        mz = [float(it[0]) for it in pairs]
        intensity = [float(it[1]) for it in pairs]
    except ValueError:
        print("Could not convert", len(stack), "with pairs" , len(pairs))
        return
    assert len(mz) == len(intensity)
    #
    print("Handle scan at rt", rt)
    peaks = np.ndarray(shape=(len(mz), 2), dtype=np.float32)
    peaks[:,0] = mz
    peaks[:,1] = intensity
    s = pyopenms.MSSpectrum()
    s.set_peaks(peaks)
    s.setRT(rt)
    s.setMSLevel(1)
    outexp.addSpectrum(s)
github msproteomicstools / msproteomicstools / analysis / scripts / DIA / makeSwathFile.py View on Github external
def getSwathExperiment(nr_scans, nr_swathes, precusorsisolation):
    exp = pyopenms.MSExperiment()
    for spec_cnt in range(1, nr_scans):
        ms1_spec = pyopenms.MSSpectrum()
        ms1_spec.setMSLevel(1)
        ms1_spec.setRT(spec_cnt*10)
        middle_scan = nr_scans/2
        intensity = norm.pdf( (spec_cnt- middle_scan )/4.0 )
        pk_list = [ [500.01, intensity*3000], [510.05, intensity*3000] ]
        peaks = numpy.array(pk_list, dtype=numpy.float32)
        ms1_spec.set_peaks(peaks)
        exp.addSpectrum(ms1_spec)
        # Swath 1: 500.01, 500.15, 500.25
        # Swath 2: 501.01, 501.15, 501.25
        # Swath 3: 502.01, 502.15, 502.25
        # Swath 4: 504.01, 504.15, 504.25
        # Swath 5: 505.01, 505.15, 505.25
        for i in range(nr_swathes):
            middle_scan = nr_scans/2 + i # shift the middle of the gaussian by one in each scan
            intensity = norm.pdf( (spec_cnt - middle_scan )/4.0 )
github msproteomicstools / msproteomicstools / analysis / scripts / DIA / makeSwathFile.py View on Github external
middle_scan = nr_scans/2
        intensity = norm.pdf( (spec_cnt- middle_scan )/4.0 )
        pk_list = [ [500.01, intensity*3000], [510.05, intensity*3000] ]
        peaks = numpy.array(pk_list, dtype=numpy.float32)
        ms1_spec.set_peaks(peaks)
        exp.addSpectrum(ms1_spec)
        # Swath 1: 500.01, 500.15, 500.25
        # Swath 2: 501.01, 501.15, 501.25
        # Swath 3: 502.01, 502.15, 502.25
        # Swath 4: 504.01, 504.15, 504.25
        # Swath 5: 505.01, 505.15, 505.25
        for i in range(nr_swathes):
            middle_scan = nr_scans/2 + i # shift the middle of the gaussian by one in each scan
            intensity = norm.pdf( (spec_cnt - middle_scan )/4.0 )
            intensity *= 1.2 # 20% higher intensity in each swath
            spec = pyopenms.MSSpectrum()
            spec.setMSLevel(2)
            spec.setRT(spec_cnt*10+ i+1)
            prec = pyopenms.Precursor()
            if precusorsisolation == "OpenSwath":
                prec.setIsolationWindowLowerOffset(400 + i*25)
                prec.setIsolationWindowUpperOffset(425 + i*25)
            elif precusorsisolation == "Pwiz":
                prec.setIsolationWindowLowerOffset(12.5)
                prec.setIsolationWindowUpperOffset(12.5)
            elif precusorsisolation == "Missing":
                pass
            else:
                raise Exception("precusorsisolation needs to be {Missing,Pwiz,OpenSwath}")
            prec.setMZ(400 + i *25 + 12.5);
            spec.setPrecursors( [prec])
            pk_list = [ [500.01+i, intensity*3000] , [500.15+i, intensity*3000/2.0], [500.25+i, intensity*3000/3.0]  ]