Commit d777f9bd authored by Yan's avatar Yan
Browse files

Experimental support for scan headers

* scan headers now partly supported so they can be debugged in future.
parent 3297b611
......@@ -11,6 +11,11 @@ from PyQt5 import QtPrintSupport
from rawprasslib import load_raw
from rawprasslib import rawprasslib
from prasopes.predictmz import predict as getmzpattern
try:
from rawautoparams import load_params
autoparams = True
except:
autoparams = False
import numpy as np
import prasopes.config as cf
import prasopes.datatools as dt
......@@ -55,7 +60,19 @@ def load_file(parent, chrom_plot, spc, d_set, ms_s, fn, chrom_s,
"canceling request!\n\n"
"Error message:\n{}".format(pex.args[0]))
return
[i.clear() for i in (ms_s['params'],ms_s['headers'])]
if autoparams == True:
try:
ms_s['params'], rawheaders = load_params(filename)
segments = [len(subset['chrom_dat'][0]) for subset in d_set]
indicies = [sum(segments[:i+1]) for i in range(len(segments))]
ms_s['headers'] = np.split(rawheaders, indicies)[:-1]
except Exception as pex:
QtWidgets.QMessageBox.critical(
parent, "Parameters readout has failed!",
"File is incompatible with the rawautoparams, "
"no parameters loaded!\n\n"
"Error message:\n{}".format(pex.args[0]))
gt.populate(chrom_plot, spc, d_set, ms_s, chrom_s)
fn[0] = filename
parent.setWindowTitle("Prasopes - {}".format(
......@@ -147,9 +164,11 @@ def about(parent):
def main():
print(autoparams)
ds = []
ms = dict(annotation=[], name="Spectrum", xlabel="m/z",
ylabel="ion count", xtics=20, predict=None)
ylabel="ion count", xtics=20, predict=None,
params=[], headers=[])
chrom = dict(x=[0], y=[0], t_start=None, t_end=None,
name="Chromatogram", xlabel="time(min)",
ylabel="total ion count", timesarg=[])
......
......@@ -109,18 +109,22 @@ def plot_subtime(mpl_spectrum, mpl_chromatogram, ds, ms_data, chrom_data):
for i,subset in enumerate(ds):
selection = chrom_data['timesarg'][i]
if len(ms_data['headers']) == len(ds):
legend = legendize(ms_data['headers'][i][selection])
else:
legend = None
if cf.settings().value("view/oddeven", type=bool):
for j in range(2):
chromx = subset['chrom_dat'][0, :][j::2]
chromy = subset['chrom_dat'][1, :][j::2]
pop_plot(chromx, chromy, mpl_chromatogram, chrom_data,
colornum=i*2+j)
pop_plot(chromx, chromy, mpl_chromatogram, chrom_data, i*2+j,
legend)
if not np.array_equal(selection[j::2], []):
clr = i*2+j if selection[0] % 2 == 0\
else i*2+(1-j)
ms_x = subset['masses']
ms_y = np.mean(subset['matrix'][selection[j::2]], axis=0)
pop_plot(ms_x, ms_y, mpl_spectrum, ms_data, colornum=clr)
pop_plot(ms_x, ms_y, mpl_spectrum, ms_data, clr, legend)
dots_x = subset['chrom_dat'][0, selection[j::2]]
dots_y = subset['chrom_dat'][1, selection[j::2]]
mpl_chromatogram.plot(dots_x, dots_y, '.', color=(
......@@ -128,11 +132,11 @@ def plot_subtime(mpl_spectrum, mpl_chromatogram, ds, ms_data, chrom_data):
else:
chromx = subset['chrom_dat'][0, :]
chromy = subset['chrom_dat'][1, :]
pop_plot(chromx, chromy, mpl_chromatogram, chrom_data, colornum=i)
pop_plot(chromx, chromy, mpl_chromatogram, chrom_data, i, legend)
if not np.array_equal(selection, []):
ms_x = subset['masses']
ms_y = np.mean(subset['matrix'][selection], axis=0)
pop_plot(ms_x, ms_y, mpl_spectrum, ms_data, colornum=i)
pop_plot(ms_x, ms_y, mpl_spectrum, ms_data, i, legend)
dots_x = subset['chrom_dat'][0, selection]
dots_y = subset['chrom_dat'][1, selection]
mpl_chromatogram.plot(dots_x, dots_y, '.', color=(
......@@ -141,6 +145,9 @@ def plot_subtime(mpl_spectrum, mpl_chromatogram, ds, ms_data, chrom_data):
mpl_spectrum.set_xlim(slims[0])
if not cf.settings().value("view/autozoomy", type=bool):
mpl_spectrum.set_ylim(slims[1])
if not ms_data['headers'] == []:
mpl_spectrum.legend(loc=2)
mpl_chromatogram.legend(loc=2)
else:
autozoomy(mpl_spectrum)
ann_spec(mpl_spectrum, ms_data)
......@@ -246,10 +253,10 @@ def ann_spec(ms_spec, msdata, ann_limit=0.01):
xy=(peak['x'], peak['y']), textcoords='data'))
def pop_plot(xdata, ydata, plot, plot_data, colornum=0):
def pop_plot(xdata, ydata, plot, plot_data, colornum=0, legend=None):
"""Define and populate plot"""
plot.plot(xdata, ydata, linewidth=1, color=
(colors[colornum % len(colors)]/255))
(colors[colornum % len(colors)]/255), label=legend)
plot.set_title(plot_data['name'], loc="right")
plot.set_xlabel(plot_data['xlabel'])
plot.set_ylabel(plot_data['ylabel'])
......@@ -264,6 +271,25 @@ def pop_plot(xdata, ydata, plot, plot_data, colornum=0):
plot.tick_params(axis='y', which='minor', left=False)
def legendize(rawlegend):
#sanity check
if len(rawlegend) == 0:
return None
marks = ["-","+"]
quads = ["q3","q1"]
def translate(wut):
if wut[1] in (0,1):
text = "{}{}ms; m/z = {:.1f}-{:.1f}".format(
marks[int(wut[0])], quads[int(wut[1])], *wut[4:])
else:
text = "{}ms^{} {:.2f}@{:.1f}V; m/z = {:.1f}-{:.1f}".format(
marks[int(wut[0])], *wut[1:])
return text
strdata = [translate(i) for i in np.unique(np.array(rawlegend), axis=0)]
strtext = " and ".join(strdata)
return strtext
def populate(mpl_chromatogram, mpl_spectrum, data_set,
ms_data, chrom_data):
"""populate the GUI plots with desired dataset"""
......@@ -288,22 +314,28 @@ def populate(mpl_chromatogram, mpl_spectrum, data_set,
chrom_data['t_start'] = data_set[0]['chrom_dat'][0, 0]
chrom_data['t_end'] = data_set[-1]['chrom_dat'][0, -1]
for i,subset in enumerate(data_set):
if len(ms_data['headers']) == len(data_set):
legend = legendize(ms_data['headers'][i])
else:
legend = None
if cf.settings().value("view/oddeven", type=bool):
msx = subset['masses']
for j in range(2):
msy = np.mean(subset['matrix'][j::2], axis=0)
chromx = subset['chrom_dat'][0, :][j::2]
chromy = subset['chrom_dat'][1, :][j::2]
pop_plot(msx, msy, mpl_spectrum, ms_data, i*2+j)
pop_plot(chromx, chromy, mpl_chromatogram, chrom_data, i*2+j)
pop_plot(msx, msy, mpl_spectrum, ms_data, i*2+j, legend)
pop_plot(chromx, chromy, mpl_chromatogram, chrom_data, i*2+j, legend)
else:
msx = subset['masses']
msy = np.mean(subset['matrix'], axis=0)
chromx = subset['chrom_dat'][0, :]
chromy = subset['chrom_dat'][1, :]
pop_plot(msx, msy, mpl_spectrum, ms_data, i)
pop_plot(chromx, chromy, mpl_chromatogram, chrom_data, i)
pop_plot(msx, msy, mpl_spectrum, ms_data, i, legend)
pop_plot(chromx, chromy, mpl_chromatogram, chrom_data, i, legend)
for ax in (mpl_spectrum, mpl_chromatogram):
if not ms_data['headers'] == []:
ax.legend(loc=2)
ax.autoscale(True)
ax.set_ylim(ax.get_ylim()[1]*-0.01, ax.get_ylim()[1]*1.1)
ax.figure.canvas.draw()
......
......@@ -24,7 +24,14 @@ def paint_image(mass_spec, spect, painttarget=None):
printplot.set_xlim(spect.get_xlim())
printplot.set_ylim(spect.get_ylim())
data = [line.get_data() for line in spect.lines]
[gt.pop_plot(*line, printplot, mass_spec, i) for i,line in enumerate(data)]
if len(mass_spec['headers']) != 0:
legend = spect.get_legend().get_texts()
[gt.pop_plot(*line, printplot, mass_spec, i, legend[i].get_text())
for i,line in enumerate(data)]
printplot.legend(loc=2)
else:
[gt.pop_plot(*line, printplot, mass_spec, i)
for i,line in enumerate(data)]
printplot.locator_params(nbins=xtics, axis='x')
cache_file = BytesIO()
paintfig.savefig(cache_file)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment