Exemplo n.º 1
0
def main( file = None ):
    mzMLFile = 'profile-mass-spectrum.mzml'
    get_example_file.open_example(mzMLFile)
    run = pymzml.run.Reader("mzML_example_files/"+mzMLFile, MSn_Precision = 25e-6)
    p = pymzml.plot.Factory()
    for spec in run:
        p.newPlot()
        p.add(spec.peaks, color=(200,0,0), style='squares')
        p.add(spec.centroidedPeaks, color=(0,0,0), style='sticks')
        p.add(spec.reprofiledPeaks, color=(25,0,200), style='circles')
        p.save( filename="output/plotAspect.xhtml" , mzRange = [744.7,747] )
Exemplo n.º 2
0
def main(file=None):
    mzMLFile = 'profile-mass-spectrum.mzml'
    get_example_file.open_example(mzMLFile)
    run = pymzml.run.Reader("mzML_example_files/" + mzMLFile,
                            MSn_Precision=25e-6)
    p = pymzml.plot.Factory()
    for spec in run:
        p.newPlot()
        p.add(spec.peaks, color=(200, 0, 0), style='squares')
        p.add(spec.centroidedPeaks, color=(0, 0, 0), style='sticks')
        p.add(spec.reprofiledPeaks, color=(25, 0, 200), style='circles')
        p.save(filename="output/plotAspect.xhtml", mzRange=[744.7, 747])
Exemplo n.º 3
0
def main():

    ref = set([(801.266, 1), (419.115, 1), (460.227, 1), (723.888, 1),
               (948.349, 1), (406.261, 1), (919.143, 1), (536.459, 1),
               (1082.504, 1), (474.342, 1)])

    example_file = get_example_file.open_example('dta_example.mzML')

    run = pymzml.run.Reader(example_file,
                            MS1_Precision=5e-6,
                            MSn_Precision=20e-6)
    precursor_count_dict = ddict(int)
    for spectrum in run:
        if spectrum["ms level"] == 2:
            if "precursors" in spectrum.keys():
                precursor_count_dict[round(
                    float(spectrum["precursors"][0]["mz"]), 3)] += 1

    precursor_set = set()
    for precursor, frequency in sorted(precursor_count_dict.items(),
                                       key=itemgetter(1)):
        precursor_set.add((precursor, frequency))
    if precursor_set == ref:
        return True
    else:
        return False
Exemplo n.º 4
0
def main(verbose = False):
    file_n = 0
    
    successful = dict()
    
    for example_file in get_example_file.SHA256_DICT.keys():
        file_n += 1
        n = 1
        if verbose:
            print("{0}\t{1}\t{2}".format(file_n, n, example_file),file = sys.stderr)
        try:
            for spec in pymzml.run.Reader(get_example_file.open_example(example_file)):
                n += 1
                spec.peaks
                spec.centroidedPeaks
                spec.removeNoise('median')
                spec.hasPeak(100)
                spec.deRef()
                spec.extremeValues('mz')
                spec.extremeValues('i')
                successful[example_file] = True
        except:
            if verbose:
                raise
            successful[example_file] = False
            return False

    if verbose:
        for file in successful:
            print('{0}\t{1}'.format(file, successful[file]))
    return True
Exemplo n.º 5
0
def main(verbose=False):
    examplemzML = get_example_file.open_example('BSA1.mzML')
    if verbose:
        print("""
        comparing specs
        """)
    run = pymzml.run.Reader(examplemzML)
    tmp = []
    for spec in run:
        if spec['ms level'] == 1:
            if verbose:
                print("Parsing spec lvl 1 has id {0}".format(spec['id']))
            tmp.append(spec.deRef())
            if len(tmp) >= 3:
                break
    if verbose:
        print("Print total number of specs collected {0}".format(len(tmp)))

        print("cosine between spec 1 & 2 is ", tmp[0].similarityTo(tmp[1]))
        print("cosine score between spec 1 & 3 is ",
              tmp[0].similarityTo(tmp[2]))
        print("cosine score between spec 2 & 3 is ",
              tmp[1].similarityTo(tmp[2]))

        print("cosine score between first spec against itself ",
              tmp[0].similarityTo(tmp[0]))
    if tmp[0].similarityTo(tmp[0]) == 1:
        return True
    else:
        return False
Exemplo n.º 6
0
def main(verbose = False):
    file_n = 0
    
    successful = dict()
    
    for example_file in get_example_file.SHA256_DICT.keys():
        file_n += 1
        n = 1
        if verbose:
            print("{0}\t{1}\t{2}".format(file_n, n, example_file),file = sys.stderr)
        try:
            for spec in pymzml.run.Reader(get_example_file.open_example(example_file)):
                n += 1
                spec.peaks
                spec.centroidedPeaks
                spec.removeNoise('median')
                spec.hasPeak(100)
                spec.deRef()
                spec.extremeValues('mz')
                spec.extremeValues('i')
                successful[example_file] = True
        except:
            if verbose:
                raise
            successful[example_file] = False
            return False

    if verbose:
        for file in successful:
            print('{0}\t{1}'.format(file, successful[file]))
    return True
Exemplo n.º 7
0
def main(verbose = False):
    examplemzML = get_example_file.open_example('BSA1.mzML')
    if verbose:
        print("""
        comparing specs
        """)
    run = pymzml.run.Reader(examplemzML)
    tmp = []
    for spec in run:
        if spec['ms level'] == 1:
            if verbose:
                print("Parsing spec lvl 1 has id {0}".format(spec['id']))
            tmp.append(spec.deRef())
            if len(tmp) >= 3:
                break
    if verbose:
        print("Print total number of specs collected {0}".format(len(tmp) ) )
        
        print("cosine between spec 1 & 2 is ",tmp[0].similarityTo(tmp[1]))
        print("cosine score between spec 1 & 3 is ",tmp[0].similarityTo(tmp[2]))
        print("cosine score between spec 2 & 3 is ",tmp[1].similarityTo(tmp[2]))
        
        print("cosine score between first spec against itself ",tmp[0].similarityTo(tmp[0]))
    if tmp[0].similarityTo(tmp[0]) == 1:
        return True
    else:
        return False
Exemplo n.º 8
0
def main():
    answer = False
    pymzmlRun = pymzml.run.Reader(get_example_file.open_example('small.pwiz.1.1.mzML'))
    if pymzmlRun['TIC'].profile == [(0.004935, 15245068.0), (0.007896666666666666, 12901166.0), (0.011218333333333334, 586279.0), (0.022838333333333332, 441570.15625), (0.034925, 114331.703125), (0.04862, 130427.3046875), (0.06192333333333334, 580561.0625), (0.075015, 15148302.0), (0.07778833333333333, 10349958.0), (0.08120333333333334, 848427.3125), (0.09290333333333332, 456143.4375), (0.10480333333333333, 124170.3828125), (0.11721500000000001, 104264.796875), (0.13002166666666667, 147409.234375), (0.14345166666666667, 18257344.0), (0.14640833333333333, 11037852.0), (0.149755, 1102582.125), (0.16144166666666668, 360250.96875), (0.17337, 125874.828125), (0.18665833333333332, 142243.390625), (0.200695, 147414.578125), (0.2136733333333333, 17613074.0), (0.21674666666666667, 1597410.5), (0.22007333333333332, 990298.5), (0.23292333333333332, 447647.96875), (0.244745, 71677.03125), (0.2591716666666667, 119999.7421875), (0.2726633333333333, 152281.25), (0.28548333333333337, 22136832.0), (0.2888983333333333, 12434530.0), (0.3037033333333333, 379009.78125), (0.31565, 120473.4296875), (0.32852666666666663, 113763.3515625), (0.342915, 73607.4921875), (0.35855833333333337, 16495375.0), (0.36142833333333335, 6548706.5), (0.364755, 1041573.75), (0.37657833333333335, 626711.3125), (0.3886733333333333, 109042.7265625), (0.40196166666666666, 156294.984375), (0.4151316666666667, 79339.078125), (0.4284833333333333, 12015003.0), (0.4332216666666666, 13332331.0), (0.4365666666666667, 925073.25), (0.44832, 419351.46875), (0.46056499999999995, 88901.921875), (0.47310333333333326, 100616.1953125), (0.48723666666666665, 77939.0078125)]:
        answer = True

    return answer
Exemplo n.º 9
0
def main(verbose=False):

    ref_intensities = set([
        9258.819334518503, 19141.735187697403, 20922.463809964283,
        10594.642802391083, 9193.546071711491
    ])

    example_file = get_example_file.open_example('deconvolution.mzML.gz')

    run = pymzml.run.Reader(example_file,
                            MS1_Precision=5e-6,
                            MSn_Precision=20e-6)

    highest_i_list = list()

    for spectrum in run:
        if spectrum["ms level"] == 2:
            if spectrum["id"] == 1770:
                for mz, i in spectrum.highestPeaks(5):
                    highest_i_list.append(i)

    if set(highest_i_list) == set(ref_intensities):
        if verbose:
            print("Function .highestPeaks worked properly")
        return True
    else:
        return False
Exemplo n.º 10
0
def main():
    """
    Accessing positive or negative polarity of scan using obo 1.1.0

    usage:

        ./polarity.py

    """
    example_file = get_example_file.open_example("small.pwiz.1.1.mzML")
    run = pymzml.run.Reader(example_file, obo_version="1.1.0")
    for spec in run:
        negative_polarity = spec["negative scan"]
        if negative_polarity is None:
            negative_polarity = False
        if negative_polarity == "":
            negative_polarity = True
        positive_polarity = spec["positive scan"]
        if positive_polarity is None:
            positive_polarity = False
        if positive_polarity == "":
            positive_polarity = True
        else:
            positive_polarity = False
        print("Polarity negative {0} - Polarity positive {1}".format(
            negative_polarity, positive_polarity))
        exit(1)

    return
Exemplo n.º 11
0
 def setUp(self):
     example_file = get_example_file.open_example('deconvolution.mzML.gz')
     run = pymzml.run.Reader(example_file, MS1_Precision = 5e-6, MSn_Precision = 20e-6)
     for spec in run:
         # there is only one spectrum, so just read this
         self.spec = spec
         break
Exemplo n.º 12
0
def main():
    """
    Accessing positive or negative polarity of scan using obo 1.1.0

    usage:

        ./polarity.py

    """
    example_file = get_example_file.open_example('small.pwiz.1.1.mzML')
    run = pymzml.run.Reader(
        example_file,
        obo_version='1.1.0',
    )
    for spec in run:
        negative_polarity = spec['negative scan']
        if negative_polarity is None:
            negative_polarity = False
        if negative_polarity == '':
            negative_polarity = True
        positive_polarity = spec['positive scan']
        if positive_polarity is None:
            positive_polarity = False
        if positive_polarity == '':
            positive_polarity = True
        else:
            positive_polarity = False
        print('Polarity negative {0} - Polarity positive {1}'.format(
            negative_polarity, positive_polarity))
        exit(1)

    return
Exemplo n.º 13
0
def main(verbose = False):
    example_file = get_example_file.open_example('small.pwiz.1.1.mzML')
    run = pymzml.run.Reader(
        example_file,
        MSn_Precision = 250e-6,
        obo_version = '1.1.0',
        extraAccessions = [
            ('MS:1000129',['value']),
            ('MS:1000130',['value'])
        ]
    )
    for spec in run:
        negative_polarity = spec.get('MS:1000129', False)
        if negative_polarity == '':
            negative_polarity = True
        positive_polarity = spec.get('MS:1000130', False)
        if positive_polarity == '':
            positive_polarity = True
        print(
            'Polarity negative {0} - Polarity positive {1}'.format(
                negative_polarity,
                positive_polarity
            )
        )
        exit(1)

    return True
Exemplo n.º 14
0
 def setUp(self):
     example_file = get_example_file.open_example('deconvolution.mzML.gz')
     run = pymzml.run.Reader(example_file,
                             MS1_Precision=5e-6,
                             MSn_Precision=20e-6)
     for spec in run:
         # there is only one spectrum, so just read this
         self.spec = spec
         break
Exemplo n.º 15
0
def deconvolution():
    example_file = get_example_file.open_example('deconvolution.mzML.gz')
    run = pymzml.run.Reader(example_file,
                            MS1_Precision=5e-6,
                            MSn_Precision=20e-6)
    for spec in run:
        charge_dict = dict()
        for mz, i, charge, n in spec._get_deisotopedMZ_for_chargeDeconvolution(
        ):
            charge_dict[mz] = charge

        p = pymzml.plot.Factory()

        tmp = spec.deRef()
        tmp.reduce((590, 615))

        p.newPlot(header='centroided I', mzRange=[590, 615])
        p.add(spec.centroidedPeaks, color=(200, 00, 00), style='sticks')
        for mz, i in tmp.centroidedPeaks:
            try:
                p.add([(mz, 'mz = {0}, z = {1}'.format(mz, charge_dict[mz]))],
                      color=(000, 200, 00),
                      style='label')
            except KeyError:
                p.add([(mz, 'mz = {0}'.format(mz))],
                      color=(000, 200, 00),
                      style='label')

        tmp = spec.deRef()
        tmp.reduce((1190, 1215))

        p.newPlot(header='centroided II', mzRange=[1190, 1215])
        p.add(spec.centroidedPeaks, color=(200, 00, 00), style='sticks')
        for mz, i in tmp.centroidedPeaks:
            try:
                p.add([(mz, 'mz = {0}, z = {1}'.format(mz, charge_dict[mz]))],
                      color=(000, 200, 00),
                      style='label')
            except KeyError:
                p.add([(mz, 'mz = {0}'.format(mz))],
                      color=(000, 200, 00),
                      style='label')

        p.newPlot(header='deconvoluted', mzRange=[1190, 1215])
        p.add(spec.deconvolutedPeaks, color=(200, 00, 00), style='sticks')

        tmp = spec.deRef()
        tmp.reduce((1190, 1215))
        for mass, i in tmp.deconvolutedPeaks:
            p.add([(mass, 'mass = {0}'.format(mass))],
                  color=(000, 200, 00),
                  style='label')

        p.save(filename="output/deconvolution.xhtml", )
Exemplo n.º 16
0
def main(verbose = False):
    example_file = get_example_file.open_example('small.pwiz.1.1.mzML')
    run = pymzml.run.Reader(example_file, MS1_Precision = 20e-6, MSn_Precision = 20e-6)
    timeDependentIntensities = []
    for spectrum in run:
        if spectrum['ms level'] == 1:
            matchList = spectrum.hasPeak(MASS_2_FOLLOW)
            if matchList != []:
                for mz,I in matchList:
                    timeDependentIntensities.append( [ spectrum['scan time'], I , mz ])
    print('RT   \ti   \tmz')
    for rt, i, mz in timeDependentIntensities:
        print('{0:5.3f}\t{1:13.4f}\t{2:10}'.format( rt, i, mz ))
    return
Exemplo n.º 17
0
def main(verbose=False):
    example_file = get_example_file.open_example('small.pwiz.1.1.mzML')
    run = pymzml.run.Reader(example_file, MSn_Precision=250e-6)
    spectrum = run[1]
    if verbose:
        print(spectrum['id'], spectrum['ms level'])
    for element in spectrum.xmlTree:
        if verbose:
            print('-' * 40)
            print(element)
            print(element.get('accession'))
            print(element.tag)
            print(element.items())

    return True
Exemplo n.º 18
0
def main(verbose = False):
    example_file = get_example_file.open_example('small.pwiz.1.1.mzML')
    run = pymzml.run.Reader(example_file, MSn_Precision = 250e-6)
    spectrum = run[1]
    if verbose:
        print(spectrum['id'], spectrum['ms level'])
    for element in spectrum.xmlTree:
        if verbose:
            print('-'*40)
            print(element)
            print(element.get('accession') )
            print(element.tag)
            print(element.items())
    
    return True
Exemplo n.º 19
0
def main():

    mzMLFile = "profile-mass-spectrum.mzml"
    example_file = get_example_file.open_example(mzMLFile)

    run = pymzml.run.Reader(example_file, MSn_Precision=250e-6)
    p = pymzml.plot.Factory()

    for spec in run:
        p.newPlot()
        p.add(spec.peaks, color=(200, 00, 00), style="circles")
        p.add(spec.centroidedPeaks, color=(00, 00, 00), style="sticks")
        p.add(spec.reprofiledPeaks, color=(00, 255, 00), style="circles")
        p.save(filename="output/plotAspect.xhtml", mzRange=[744.7, 747])
        break
    return
Exemplo n.º 20
0
def deconvolution():
    example_file = get_example_file.open_example('deconvolution.mzML.gz')
    run = pymzml.run.Reader(example_file, MS1_Precision = 5e-6, MSn_Precision = 20e-6)
    for spec in run:
        charge_dict = dict()
        for mz, i, charge, n in spec._get_deisotopedMZ_for_chargeDeconvolution():
            charge_dict[mz] = charge
        
        
        p   = pymzml.plot.Factory()
        
        tmp = spec.deRef()
        tmp.reduce((590, 615))
    
        p.newPlot(header = 'centroided I', mzRange = [590, 615])
        p.add(spec.centroidedPeaks, color=(200,00,00), style='sticks')
        for mz, i in tmp.centroidedPeaks:
            try:
                p.add([ (mz,'mz = {0}, z = {1}'.format(mz, charge_dict[mz]) ) ], color=(000,200,00), style='label' )
            except KeyError:
                p.add([ (mz,'mz = {0}'.format(mz) ) ], color=(000,200,00), style='label' )

        tmp = spec.deRef()
        tmp.reduce((1190, 1215))

        p.newPlot(header = 'centroided II', mzRange = [1190, 1215])
        p.add(spec.centroidedPeaks, color=(200,00,00), style='sticks')
        for mz, i in tmp.centroidedPeaks:
            try:
                p.add([ (mz,'mz = {0}, z = {1}'.format(mz, charge_dict[mz]) ) ], color=(000,200,00), style='label' )
            except KeyError:
                p.add([ (mz,'mz = {0}'.format(mz) ) ], color=(000,200,00), style='label' )        
        
        
        
        p.newPlot(header = 'deconvoluted', mzRange = [1190, 1215])
        p.add(spec.deconvolutedPeaks, color=(200,00,00), style='sticks')

        tmp = spec.deRef()
        tmp.reduce((1190, 1215))
        for mass, i in tmp.deconvolutedPeaks:
            p.add([ (mass,'mass = {0}'.format(mass) ) ], color=(000,200,00), style='label' )  
        
        p.save(filename = "output/deconvolution.xhtml",)
Exemplo n.º 21
0
def main():
    
    ref = set([(801.266,1),(419.115,1),(460.227,1),(723.888,1),(948.349,1),(406.261,1),(919.143,1),(536.459, 1),(1082.504,1),(474.342, 1)])

    
    example_file = get_example_file.open_example('dta_example.mzML')
    
    run = pymzml.run.Reader(example_file, MS1_Precision = 5e-6, MSn_Precision = 20e-6)
    precursor_count_dict = ddict(int)
    for spectrum in run:
        if spectrum["ms level"] == 2:
            if "precursors" in spectrum.keys():
                precursor_count_dict[round(float(spectrum["precursors"][0]["mz"]),3)] += 1

    precursor_set = set()
    for precursor, frequency in sorted(precursor_count_dict.items(), key = itemgetter(1)):
        precursor_set.add((precursor, frequency))
    if precursor_set == ref:
        return True
    else:
        return False
Exemplo n.º 22
0
def main( file = None):

    if file == None:
        mzMLFile = 'profile-mass-spectrum.mzml'
        example_file = get_example_file.open_example(mzMLFile)
    else:
        example_file = file

    run = pymzml.run.Reader(example_file, MSn_Precision = 250e-6)
    p   = pymzml.plot.Factory()
    from collections import defaultdict as ddict
    checks = ddict(int)
    for spec in run:
        if spec['id'] <= 1000:
            continue
        if sum(checks.values()) > 55:
            break
        if checks[1] > 30:
            continue
        if checks[2] > 30:
            continue
        p.newPlot(header = '{ms level}'.format(**spec))
        # p.add(spec.peaks, color=(200,00,00), style='circles')
        p.add(spec.reprofiledPeaks, color=(100,100,100), style='triangle')
        p.add(spec.centroidedPeaks, color=(00,00,00), style='sticks')
        checks[ int(spec['ms level']) ] += 1

    p.save( filename="output/plotAspect_all.xhtml" )
    exit(1)

    specs = [ 4927,4930,4934,4936,4938,4942,4946,4948,4950,4954,4955,4957,4959,4962,4965,4967,4971,4976,4979,4982,4985,4990,4991,4995,4999,5004]
    for specID in specs:
        spec = run[ specID ]
        p.newPlot()
        # p.add(spec.peaks, color=(200,00,00), style='circles')
        p.add(spec.reprofiledPeaks, color=(100,100,100), style='triangle')
        p.add(spec.centroidedPeaks, color=(00,00,00), style='sticks')
        # break
    p.save( filename="output/plotAspect.xhtml" , mzRange = [840.,853.] )
    return
Exemplo n.º 23
0
def main(verbose = False):
    
    ref_intensities = set([9258.819334518503, 19141.735187697403, 20922.463809964283, 10594.642802391083, 9193.546071711491])
    
    example_file = get_example_file.open_example('deconvolution.mzML.gz')
    
    run = pymzml.run.Reader(example_file, MS1_Precision = 5e-6, MSn_Precision = 20e-6)
    
    highest_i_list = list()
    
    for spectrum in run:
        if spectrum["ms level"] == 2:
            if spectrum["id"] == 1770:
                for mz,i  in spectrum.highestPeaks(5):
                    highest_i_list.append(i)

    if set(highest_i_list) == set(ref_intensities):
        if verbose:
            print("Function .highestPeaks worked properly")
        return True
    else:
        return False
Exemplo n.º 24
0
def main( file = None):

    if file == None:
        mzMLFile = 'profile-mass-spectrum.mzml'
        example_file = get_example_file.open_example(mzMLFile)
    else:
        example_file = file

    run = pymzml.run.Reader(example_file, MSn_Precision = 250e-6)
    p   = pymzml.plot.Factory()
    specs = [ 4927,4930,4934,4936,4938,4942,4946,4948,4950,4954,4955,4957,4959,4962,4965,4967,4971,4976,4979,4982,4985,4990,4991,4995,4999,5004]


    for specID in specs:
        spec = run[ specID ]
        p.newPlot()
        # p.add(spec.peaks, color=(200,00,00), style='circles')
        p.add(spec.reprofiledPeaks, color=(100,100,100), style='triangle')
        p.add(spec.centroidedPeaks, color=(00,00,00), style='sticks')
        # break
    p.save( filename="output/plotAspect.xhtml" , mzRange = [840.,853.] )
    return
Exemplo n.º 25
0
def main(verbose=False):
    example_file = get_example_file.open_example('deconvolution.mzML.gz')
    run = pymzml.run.Reader(example_file,
                            MS1_Precision=5e-6,
                            MSn_Precision=20e-6)
    for spectrum in run:
        if verbose:
            print("Processing spectrum #{0}".format(spectrum['id']), end="\r")
            print('')
        if spectrum['ms level'] == 2:
            test1 = spectrum.hasDeconvolutedPeak(1044.559675129575)
            test2 = spectrum.hasDeconvolutedPeak(1044.5804)
            test3 = spectrum.hasDeconvolutedPeak(1044.5806)
            test4 = spectrum.hasDeconvolutedPeak(1044.5800)
            test5 = spectrum.hasDeconvolutedPeak(6000)
            test6 = spectrum.hasPeak(1016.5402567492666)
            test7 = spectrum.hasPeak(6000)

            tests = [False, False, False, False, False, False, False]
            if test1 == [(1044.559675129575, 3809.4356300564586)]:
                tests[0] = True
            if test2 == [(1044.559675129575, 3809.4356300564586)]:
                tests[1] = True
            if test3 == []:
                tests[2] = True
            if test4 == [(1044.559675129575, 3809.4356300564586)]:
                tests[3] = True
            if test5 == []:
                tests[4] = True
            if test6 == [(1016.5402567492666, 19141.735187697403)]:
                tests[5] = True
            if test7 == []:
                tests[6] = True

            all = True
            for i in range(len(tests)):
                if not tests[i]:
                    all = False

            if all:
                if verbose:
                    print('All tests were successful.')
            else:
                print(tests)

            if verbose:
                print('deconvoluted peaks list:')
                print('')
                print('centroided peaks list:')
                print(spectrum.centroidedPeaks)
                print('')
                print('deconvolutedPeaks list:')
                print(spectrum.deconvolutedPeaks)
                print('')
                print(
                    "1044.559675129575 in deconvoluted spectrum? (should be)",
                    test1)
                print(
                    "1044.559675129575 + 20 ppm = 1044.5804 in deconvoluted spectrum? (should be)",
                    test2)
                print(
                    "1044.559675129575 + >20 ppm = 1044.5806 in deconvoluted spectrum? (shouldn't)",
                    test3)
                print("1044.5800 in deconvoluted spectrum? (should be)", test4)
                print("6000 in deconvoluted spectrum (shouldn't)?", test5)
                print("1016.5402567492666 in centroided peaks (True)", test6)
                print("6000 in centroided peaks (None)", test7)

            if all:
                return True
Exemplo n.º 26
0
Example:

>>> example_file = get_example_file.open_example('small.pwiz.1.1.mzML')
>>> run  = pymzml.run.Reader(example_file, MS1_Precision = 5e-6)
>>> run2 = pymzml.run.Writer(filename = 'write_test.mzML', run= run , overwrite = True)
>>> specOfIntrest = run[2]
>>> run2.addSpec(spec)
>>> run2.save()


"""

from __future__ import print_function
import pymzml
import get_example_file

if __name__ == '__main__':  
    example_file = get_example_file.open_example('small.pwiz.1.1.mzML')
    run  = pymzml.run.Reader(
        example_file,
        MS1_Precision = 5e-6
    )
    run2 = pymzml.run.Writer(
        filename = 'write_test.mzML',
        run= run,
        overwrite = True
    )
    spec = run[1]
    run2.addSpec(spec)
    run2.save()    
Exemplo n.º 27
0
def main(verbose = False):
    example_file = get_example_file.open_example('deconvolution.mzML.gz')
    run = pymzml.run.Reader(example_file, MS1_Precision = 5e-6, MSn_Precision = 20e-6)
    for spectrum in run:
        if verbose:
            print("Processing spectrum #{0}".format(spectrum['id']), end="\r")
            print('')
        if spectrum['ms level'] == 2:
            test1 = spectrum.hasDeconvolutedPeak(1044.559675129575)
            test2 = spectrum.hasDeconvolutedPeak(1044.5804)
            test3 = spectrum.hasDeconvolutedPeak(1044.5806)
            test4 = spectrum.hasDeconvolutedPeak(1044.5800)
            test5 = spectrum.hasDeconvolutedPeak(6000)
            test6 = spectrum.hasPeak(1016.5402567492666)
            test7 = spectrum.hasPeak(6000)

            tests = [False, False, False, False, False, False, False]
            if test1 == [(1044.559675129575, 3809.4356300564586)]:
                tests[0] = True
            if test2 == [(1044.559675129575, 3809.4356300564586)]:
                tests[1] = True
            if test3 == []:
                tests[2] = True
            if test4 == [(1044.559675129575, 3809.4356300564586)]:
                tests[3] = True
            if test5 == []:
                tests[4] = True
            if test6 == [(1016.5402567492666, 19141.735187697403)]:
                tests[5] = True
            if test7 == []:
                tests[6] = True

            all = True
            for i in range(len(tests)):
                if not tests[i]:
                    all = False

            if all:
                if verbose:
                    print('All tests were successful.')
            else:
                print(tests)




            if verbose:
                print('deconvoluted peaks list:')
                print('')
                print('centroided peaks list:')
                print(spectrum.centroidedPeaks)
                print('')
                print('deconvolutedPeaks list:')
                print(spectrum.deconvolutedPeaks)
                print('')
                print("1044.559675129575 in deconvoluted spectrum? (should be)", test1)
                print("1044.559675129575 + 20 ppm = 1044.5804 in deconvoluted spectrum? (should be)", test2)
                print("1044.559675129575 + >20 ppm = 1044.5806 in deconvoluted spectrum? (shouldn't)", test3)
                print("1044.5800 in deconvoluted spectrum? (should be)", test4)
                print("6000 in deconvoluted spectrum (shouldn't)?", test5)
                print("1016.5402567492666 in centroided peaks (True)", test6)
                print("6000 in centroided peaks (None)", test7)

            if all:
                return True