How to use the pythoms.tome.bindata function in pythoms

To help you get started, we’ve selected a few pythoms 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 larsyunker / PythoMS / PyRSIR.py View on Github external
sum_spectra[fn] = sum_spectra[fn].trim()  # convert Spectrum objects into x,y lists

    # if max(n) > 1: # run combine functions if n > 1
    for num in n:  # for each n to sum
        if verbose is True:
            sys.stdout.write('\r%d Summing species traces.' % num)
        sumkey = str(num) + 'sum'
        for key in sp:  # bin each species
            if sp[key]['affin'] in mskeys or mzml.functions[sp[key]['function']][
                'type'] == 'MS':  # if species is MS related
                sp[key][sumkey] = bindata(num, sp[key]['raw'])
        for mode in mskeys:
            sumkey = str(num) + 'sum' + mode
            modekey = 'raw' + mode
            if modekey in rtime.keys():  # if there is data for that mode
                rtime[sumkey] = bindata(num, rtime[modekey], num)
                tic[sumkey] = bindata(num, tic[modekey])
    if verbose is True:
        sys.stdout.write(' DONE\n')
        sys.stdout.flush()
    # else:
    #    for key in sp: # create key for normalization
    #        sp[key]['1sum'] = sp[key]['raw']

    for num in n:  # normalize each peak's chromatogram
        if verbose is True:
            sys.stdout.write('\r%d Normalizing species traces.' % num)
            sys.stdout.flush()
        sumkey = str(num) + 'sum'
        normkey = str(num) + 'norm'
        for mode in mskeys:
            modekey = 'raw' + mode
github larsyunker / PythoMS / PyRSIR.py View on Github external
tic[mode] = mzml.functions[func]['tic']
            # if 'formula' in sp[key] and sp[key]['formula'] is not None:
            #     sp[key]['match'] = sp[key]['mol'].compare(sp[key]['spectrum'])
        if combine_spectra is True:
            for fn in sum_spectra:
                sum_spectra[fn] = sum_spectra[fn].trim()  # convert Spectrum objects into x,y lists

    # if max(n) > 1: # run combine functions if n > 1
    for num in n:  # for each n to sum
        if verbose is True:
            sys.stdout.write('\r%d Summing species traces.' % num)
        sumkey = str(num) + 'sum'
        for key in sp:  # bin each species
            if sp[key]['affin'] in mskeys or mzml.functions[sp[key]['function']][
                'type'] == 'MS':  # if species is MS related
                sp[key][sumkey] = bindata(num, sp[key]['raw'])
        for mode in mskeys:
            sumkey = str(num) + 'sum' + mode
            modekey = 'raw' + mode
            if modekey in rtime.keys():  # if there is data for that mode
                rtime[sumkey] = bindata(num, rtime[modekey], num)
                tic[sumkey] = bindata(num, tic[modekey])
    if verbose is True:
        sys.stdout.write(' DONE\n')
        sys.stdout.flush()
    # else:
    #    for key in sp: # create key for normalization
    #        sp[key]['1sum'] = sp[key]['raw']

    for num in n:  # normalize each peak's chromatogram
        if verbose is True:
            sys.stdout.write('\r%d Normalizing species traces.' % num)
github larsyunker / PythoMS / video frame renderer.py View on Github external
}
mzml, sp, rtime = pyrsir(filename, sp, 1, **pyrsirkw)[:3]  # run pyrsir

sstart = mzml.scan_index(scr[0])  # index of start scan
send = mzml.scan_index(scr[1])  # index of last scan
for key in sp:
    sp[key]['raw'] = sp[key]['raw'][sstart:send + 1]  # trim to scan range
for key in rtime:
    rtime[key] = rtime[key][sstart:send + 1]  # trim to scan range
spec = mzml.retrieve_scans(scr[0], scr[1], mz[0], mz[1], outside=True)  # pull all spectra within scan range
sys.stdout.write('%s summing and normalizing species traces' % str(n))
sumkey = str(n) + 'sum'
normkey = str(n) + 'norm'
sumsp = []
for key in sp:
    sp[key][sumkey] = bindata(n, sp[key]['raw'])  # bin each species
    sp[key]['colour'] = Colour(sp[key]['colour']).mpl  # convert colour into matplotlib format
    for ind, val in enumerate(sp[key][sumkey]):  # for normalization
        try:
            sumsp[ind] += val
        except IndexError:
            sumsp.append(val)

for mode in mskeys:
    sumkey = str(n) + 'sum' + mode
    modekey = 'raw' + mode
    if modekey in rtime.keys():  # if there is data for that mode
        rtime[sumkey] = bindata(n, rtime[modekey], n)
        for ind, val in enumerate(rtime[sumkey]):
            rtime[sumkey][ind] = val - inj  # shift time data to zero at injection point
        for key in sp:  # for each species
            if sp[key]['affin'] in mskeys:  # if species has affinity
github larsyunker / PythoMS / video frame renderer.py View on Github external
normkey = str(n) + 'norm'
sumsp = []
for key in sp:
    sp[key][sumkey] = bindata(n, sp[key]['raw'])  # bin each species
    sp[key]['colour'] = Colour(sp[key]['colour']).mpl  # convert colour into matplotlib format
    for ind, val in enumerate(sp[key][sumkey]):  # for normalization
        try:
            sumsp[ind] += val
        except IndexError:
            sumsp.append(val)

for mode in mskeys:
    sumkey = str(n) + 'sum' + mode
    modekey = 'raw' + mode
    if modekey in rtime.keys():  # if there is data for that mode
        rtime[sumkey] = bindata(n, rtime[modekey], n)
        for ind, val in enumerate(rtime[sumkey]):
            rtime[sumkey][ind] = val - inj  # shift time data to zero at injection point
        for key in sp:  # for each species
            if sp[key]['affin'] in mskeys:  # if species has affinity
                spkey = str(n) + 'sum'
                sp[key][normkey] = []
                for ind, val in enumerate(sp[key][spkey]):
                    sp[key][normkey].append(val / (sumsp[ind] + 0.01))  # +0.01 to avoid div/0 errors
sys.stdout.write(' DONE\n')
sys.stdout.flush()

# bin and normalize mass spectra
spec = [msfignorm(*spectrum) for spectrum in binnspectra(spec, n, start=mz[0], end=mz[1])]

# initial figure setup
fig, [specax, traceax] = pl.subplots(