Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_xlsx(self):
xlfile = XLSX(
validation_path / 'xlsx_validation',
verbose=False
)
spec, xunit, yunit = xlfile.pullspectrum('example MS spectrum')
multispec = xlfile.pullmultispectrum('example multi-spectrum')
rsimparams = xlfile.pullrsimparams()
xlout = XLSX(
validation_path / 'xlsxtestout.xlsx',
create=True,
verbose=False
)
xlout.writespectrum(spec[0], spec[1], 'test single spectrum out', xunit, yunit)
for key, val in sorted(multispec.items()):
xlout.writemultispectrum(
multispec[key]['x'],
multispec[key]['y'],
def test_xlsx(self):
xlfile = XLSX(
validation_path / 'xlsx_validation',
verbose=False
)
spec, xunit, yunit = xlfile.pullspectrum('example MS spectrum')
multispec = xlfile.pullmultispectrum('example multi-spectrum')
rsimparams = xlfile.pullrsimparams()
xlout = XLSX(
validation_path / 'xlsxtestout.xlsx',
create=True,
verbose=False
)
xlout.writespectrum(spec[0], spec[1], 'test single spectrum out', xunit, yunit)
for key, val in sorted(multispec.items()):
xlout.writemultispectrum(
multispec[key]['x'],
multispec[key]['y'],
multispec[key]['xunit'],
multispec[key]['yunit'],
'Function Chromatograms',
key
)
xlout.save()
os.remove(
except KeyError:
raise KeyError('\nThe specified figure setting "%s" is not defined.\nPlease check your spelling' % setting)
if __name__ == '__main__':
os.chdir(curdir) # change to current working directory
keywords = presets(setting) # pull preset kwargs
if spectrum.lower().endswith('.mzml.gz') or spectrum.lower().endswith('.raw'): # if supplied with a mass spec file
mzml = mzML(spectrum)
exp = mzml.sum_scans()
keywords.update({'outname': mzml.filename.split('.')[0]}) # set default output filename
else: # otherwise assume that it is an excel file
xlfile = XLSX(spectrum, verbose=True) # load excel file
if sheetname is None: # otherwise use the first sheet
sheetname = xlfile.wb.sheetnames[0]
exp = xlfile.pullspectrum(sheetname, skiplines=skiplines)[0] # load spectrum from first sheet in workbook
keywords.update({ # set default output filename
'outname': f'{xlfile.bookname[:-5]} ({sheetname})',
})
keywords.update(override) # apply any user overrides
plot_mass_spectrum(exp, simdict, **keywords)
import gc
gc.collect()
st.printstart()
mzml = mzML(filename) # create mzML object
if start is None:
start = mzml.functions[1]['sr'][0] + 1
if end is None:
end = mzml.functions[1]['sr'][1] + 1
x, y = mzml.sum_scans(
start=start,
end=end,
dec=dec,
)
if save is not False:
if type(save) == str: # if a filename was provided for the Excel file
xlfile = XLSX(save, create=True)
else: # otherwise use the mzML filename
xlfile = XLSX(filename, create=True)
xlfile.writespectrum( # write the spectrum to file
x,
y,
'summed spectra (scans %d-%d)' % (start, end)
)
xlfile.save()
st.printend()
return x, y # return if specified
xvals = op.chart.Reference(ws, min_col=1, min_row=2, max_row=len(x) + 1) # define the x values
chart.x_axis.title = 'm/z' # x axis title
if norm is False: # if there is no normalized data
yvals = op.chart.Reference(ws, min_col=2, min_row=1, max_row=len(x) + 1)
chart.y_axis.title = 'Intensity (counts)'
if norm is True: # if there is normalized data
yvals = op.chart.Reference(ws, min_col=3, min_row=1, max_row=len(x) + 1)
chart.y_axis.title = 'Normalized Intensity'
series = op.chart.Series(yvals, xvals)
chart.series.append(series) # add the data to the chart
ws.add_chart(chart, 'E1') # add the chart to the worksheet
if __name__ == '__main__':
name = 'Useless delete this'
xlfile = XLSX(name, create=True)
st = ScriptTime()
st.printstart()
mzml = mzML(filename) # create mzML object
if start is None:
start = mzml.functions[1]['sr'][0] + 1
if end is None:
end = mzml.functions[1]['sr'][1] + 1
x, y = mzml.sum_scans(
start=start,
end=end,
dec=dec,
)
if save is not False:
if type(save) == str: # if a filename was provided for the Excel file
xlfile = XLSX(save, create=True)
else: # otherwise use the mzML filename
xlfile = XLSX(filename, create=True)
xlfile.writespectrum( # write the spectrum to file
x,
y,
'summed spectra (scans %d-%d)' % (start, end)
)
xlfile.save()
st.printend()
return x, y # return if specified
# ----------------------------------------------------------
# -------------------PROGRAM BEGINS-------------------------
# ----------------------------------------------------------
if verbose is True:
stime = ScriptTime()
stime.printstart()
n = check_integer(n, 'number of scans to sum') # checks integer input and converts to list
if type(xlsx) != dict:
if verbose is True:
sys.stdout.write('Loading processing parameters from excel file')
sys.stdout.flush()
xlfile = XLSX(xlsx, verbose=verbose)
sp = xlfile.pullrsimparams()
else: # if parameters were provided in place of an excel file
sp = xlsx
mskeys = ['+', '-']
for key in sp:
if 'formula' in sp[key] and sp[key]['formula'] is not None: # if formula is specified
sp[key]['mol'] = IPMolecule(sp[key]['formula']) # create Molecule object
sp[key]['bounds'] = sp[key]['mol'].calculate_bounds(
bounds_confidence
) # generate bounds from molecule object with this confidence interval
if verbose is True:
sys.stdout.write(' DONE\n')
rtime = {} # empty dictionaries for time and tic
tic = {}
# end m/z for the spectrum
endmz = 700
# colour for the plotted spectrum (see _Colour for more details)
colour = 'k'
# the excel file name to find the x,y values for the spectra
filename = 'Dy'
# the type of the spectrum (either 'continuum' or 'centroid')
spectype = 'continuum'
#########################################################################################
# there is no need to modify the rest of the script
if __name__ == '__main__':
xlfile = XLSX(filename) # load excel file
for sheet in xlfile.wb.sheetnames: # for each sheet
sys.stdout.write('Plotting spectrum "%s"' % sheet)
sys.stdout.flush()
spec = xlfile.pullspectrum(sheet, 8)[0] # pull spectrum
spec[1] = normalize(spec[1], 100.) # normalize to 100
outname = filename + ' - ' + sheet + ' (' + str(startmz) + '-' + str(endmz) + ')'
plot_mass_spectrum(
spec,
outname=outname,
spectype=spectype,
mz=[startmz, endmz],
padding=[0.1, 0.95, 0.13, 0.96],
verbose=False,
speccolour=colour
)