Commit 9fae08bb authored by Yan's avatar Yan
Browse files

More fixes, copying of parameters working

* sw is still haunted by bugs after uniting but its workable
parent f6740c3c
...@@ -78,8 +78,9 @@ class AugFigureCanvas(FigureCanvas): ...@@ -78,8 +78,9 @@ class AugFigureCanvas(FigureCanvas):
self.mass_selector = gt.AugSpanSelector(self.spectplot, self.ms) self.mass_selector = gt.AugSpanSelector(self.spectplot, self.ms)
#TODO: rewrite timeSelector to better shape when I'm done #TODO: rewrite timeSelector to better shape when I'm done
self.time_selector = SpanSelector(self.chromplot, lambda x_min, x_max: self.time_selector = SpanSelector(self.chromplot, lambda x_min, x_max:
gt.pick_times(x_min, x_max, self.spectplot, self.ds, self.chromplot, self.ms, self.chrom, self.paramstable), 'horizontal', useblit=True, rectprops=dict( gt.pick_times(x_min, x_max, self), 'horizontal',
alpha=0.15, facecolor='purple'), button=3) useblit=True, rectprops=dict(alpha=0.15, facecolor='purple'),
button=3)
def load_file(parent, augCanvas, update, settings, loadthread, filename=None): def load_file(parent, augCanvas, update, settings, loadthread, filename=None):
...@@ -215,8 +216,11 @@ def key_pressed(event, augCanvas, config): ...@@ -215,8 +216,11 @@ def key_pressed(event, augCanvas, config):
update_spectrum(augCanvas, config) update_spectrum(augCanvas, config)
if event.key() == QtCore.Qt.Key_C: if event.key() == QtCore.Qt.Key_C:
if event.modifiers().__int__() == QtCore.Qt.ControlModifier: if event.modifiers().__int__() == QtCore.Qt.ControlModifier:
imgt.clip_spect_img(augCanvas.ms, augCanvas.spectplot, if augCanvas.paramstable.underMouse():
augCanvas.filename) dt.clip_tablestr(augCanvas)
else:
imgt.clip_spect_img(augCanvas.ms, augCanvas.spectplot,
augCanvas.filename)
if event.modifiers().__int__() == QtCore.Qt.ControlModifier+\ if event.modifiers().__int__() == QtCore.Qt.ControlModifier+\
QtCore.Qt.ShiftModifier: QtCore.Qt.ShiftModifier:
dt.clip_spectstr(augCanvas) dt.clip_spectstr(augCanvas)
......
...@@ -40,6 +40,15 @@ def clip_spectstr(augCanvas): ...@@ -40,6 +40,15 @@ def clip_spectstr(augCanvas):
[QtWidgets.QApplication.clipboard().setText(string, i) for i in range(2)] [QtWidgets.QApplication.clipboard().setText(string, i) for i in range(2)]
def clip_tablestr(augCanvas):
pairs = [" ".join((augCanvas.paramstable.item(row, 1).text(),
augCanvas.paramstable.item(row, 2).text()))
for row in range(augCanvas.paramstable.rowCount())
if augCanvas.paramstable.cellWidget(row, 0).checkState()]
text = ", ".join(pairs)
[QtWidgets.QApplication.clipboard().setText(text, i) for i in range(2)]
def table(labels, minsizex=600, minsizey=0): def table(labels, minsizex=600, minsizey=0):
"""creates a reasonable table""" """creates a reasonable table"""
table = QtWidgets.QTableWidget(columnCount=len(labels)) table = QtWidgets.QTableWidget(columnCount=len(labels))
......
...@@ -183,83 +183,86 @@ def textedit_factory(axis, plot_data): ...@@ -183,83 +183,86 @@ def textedit_factory(axis, plot_data):
axis.figure.canvas.mpl_connect('pick_event', annpicked) axis.figure.canvas.mpl_connect('pick_event', annpicked)
def plot_subtime(mpl_spectrum, mpl_chromatogram, ds, ms_data, chrom_data): #def plot_subtime(mpl_spectrum, mpl_chromatogram, ds, ms_data, chrom_data):
def plot_subtime(augCanvas):
"""plot averaged spectrum of subselected part of the chromatogram""" """plot averaged spectrum of subselected part of the chromatogram"""
slims = [mpl_spectrum.get_xlim(), mpl_spectrum.get_ylim()] slims = [augCanvas.spectplot.get_xlim(), augCanvas.spectplot.get_ylim()]
chlims = [mpl_chromatogram.get_xlim(), mpl_chromatogram.get_ylim()] chlims = [augCanvas.chromplot.get_xlim(), augCanvas.chromplot.get_ylim()]
ms_data['annotation'].clear() augCanvas.ms['annotation'].clear()
mpl_spectrum.clear() augCanvas.spectplot.clear()
mpl_chromatogram.clear() augCanvas.chromplot.clear()
for i,subset in enumerate(ds): for i,subset in enumerate(augCanvas.ds):
selection = chrom_data['timesarg'][i] selection = augCanvas.chrom['timesarg'][i]
if len(ms_data['headers']) == len(ds): if len(augCanvas.ms['headers']) == len(augCanvas.ds):
legend = legendize(ms_data['headers'][i][selection], chrom_data) legend = legendize(augCanvas.ms['headers'][i][selection],
augCanvas.chrom)
else: else:
legend = None legend = None
if cf.settings().value("view/oddeven", type=bool): if cf.settings().value("view/oddeven", type=bool):
for j in range(2): for j in range(2):
chromx = subset['chrom_dat'][0, :][j::2] chromx = subset['chrom_dat'][0, :][j::2]
chromy = subset['chrom_dat'][1, :][j::2] chromy = subset['chrom_dat'][1, :][j::2]
pop_plot(chromx, chromy, mpl_chromatogram, chrom_data, i*2+j, pop_plot(chromx, chromy, augCanvas.chromplot,
legend) augCanvas.chrom, i*2+j, legend)
if not np.array_equal(selection[j::2], []): if not np.array_equal(selection[j::2], []):
clr = i*2+j if selection[0] % 2 == 0\ clr = i*2+j if selection[0] % 2 == 0\
else i*2+(1-j) else i*2+(1-j)
ms_x = subset['masses'] ms_x = subset['masses']
ms_y = np.mean(subset['matrix'][selection[j::2]], axis=0) ms_y = np.mean(subset['matrix'][selection[j::2]], axis=0)
pop_plot(ms_x, ms_y, mpl_spectrum, ms_data, clr, legend) pop_plot(ms_x, ms_y, augCanvas.spectplot,
augCanvas.ms, clr, legend)
dots_x = subset['chrom_dat'][0, selection[j::2]] dots_x = subset['chrom_dat'][0, selection[j::2]]
dots_y = subset['chrom_dat'][1, selection[j::2]] dots_y = subset['chrom_dat'][1, selection[j::2]]
mpl_chromatogram.plot(dots_x, dots_y, '.', color=( augCanvas.chromplot.plot(dots_x, dots_y, '.', color=(
colors[(clr) % len(colors)]/255)) colors[(clr) % len(colors)]/255))
else: else:
chromx = subset['chrom_dat'][0, :] chromx = subset['chrom_dat'][0, :]
chromy = subset['chrom_dat'][1, :] chromy = subset['chrom_dat'][1, :]
pop_plot(chromx, chromy, mpl_chromatogram, chrom_data, i, legend) pop_plot(chromx, chromy, augCanvas.chromplot,
augCanvas.chrom, i, legend)
if not np.array_equal(selection, []): if not np.array_equal(selection, []):
ms_x = subset['masses'] ms_x = subset['masses']
ms_y = np.mean(subset['matrix'][selection], axis=0) ms_y = np.mean(subset['matrix'][selection], axis=0)
pop_plot(ms_x, ms_y, mpl_spectrum, ms_data, i, legend) pop_plot(ms_x, ms_y, augCanvas.spectplot,
augCanvas.ms, i, legend)
dots_x = subset['chrom_dat'][0, selection] dots_x = subset['chrom_dat'][0, selection]
dots_y = subset['chrom_dat'][1, selection] dots_y = subset['chrom_dat'][1, selection]
mpl_chromatogram.plot(dots_x, dots_y, '.', color=( augCanvas.chromplot.plot(dots_x, dots_y, '.', color=(
colors[i % len(colors)]/255)) colors[i % len(colors)]/255))
mpl_spectrum.set_xlim(slims[0]) augCanvas.spectplot.set_xlim(slims[0])
if not cf.settings().value("view/autozoomy", type=bool): if not cf.settings().value("view/autozoomy", type=bool):
mpl_spectrum.set_ylim(slims[1]) augCanvas.spectplot.set_ylim(slims[1])
if not ms_data['headers'] == []: if not augCanvas.ms['headers'] == []:
mpl_spectrum.legend(loc=2) augCanvas.spectplot.legend(loc=2)
mpl_spectrum.get_legend().set_in_layout(False) augCanvas.spectplot.get_legend().set_in_layout(False)
mpl_chromatogram.legend(loc=2) augCanvas.chromplot.legend(loc=2)
mpl_chromatogram.get_legend().set_in_layout(False) augCanvas.chromplot.get_legend().set_in_layout(False)
else: else:
autozoomy(mpl_spectrum) autozoomy(augCanvas.spectplot)
ann_spec(mpl_spectrum, ms_data) ann_spec(augCanvas.spectplot, augCanvas.ms)
mpl_chromatogram.set_xlim(chlims[0]) augCanvas.chromplot.set_xlim(chlims[0])
mpl_chromatogram.set_ylim(chlims[1]) augCanvas.chromplot.set_ylim(chlims[1])
mpl_chromatogram.get_figure().canvas.draw() augCanvas.chromplot.get_figure().canvas.draw()
def pick_times(x_min, x_max, mpl_spectrum, data_set, mpl_chromatogram, def pick_times(x_min, x_max, augCanvas):
mass_spect, chrom_spect, table):
"""subselect part of the chromatogram and plot it""" """subselect part of the chromatogram and plot it"""
chrom_spect['t_start'] = x_min augCanvas.chrom['t_start'] = x_min
chrom_spect['t_end'] = x_max augCanvas.chrom['t_end'] = x_max
times = dt.argsubselect(np.concatenate( times = dt.argsubselect(np.concatenate(
[subset['chrom_dat'][0] for subset in data_set]), x_min, x_max) [subset['chrom_dat'][0] for subset in augCanvas.ds]), x_min, x_max)
chrom_spect['timesarg'].clear() augCanvas.chrom['timesarg'].clear()
for subset in data_set: for subset in augCanvas.ds:
goodtimes = np.where((times < len(subset['chrom_dat'][0])) & ~(times < 0))[0] goodtimes = np.where((times < len(subset['chrom_dat'][0])) & ~(times < 0))[0]
chrom_spect['timesarg'].append(times[goodtimes]) augCanvas.chrom['timesarg'].append(times[goodtimes])
times = times - len(subset['chrom_dat'][0]) times = times - len(subset['chrom_dat'][0])
update_paramstable(table, mass_spect, chrom_spect) update_paramstable(augCanvas)
plot_subtime(mpl_spectrum, mpl_chromatogram, data_set, mass_spect, plot_subtime(augCanvas)
chrom_spect)
def shift_times(event, spect, chrom, ds, ms_ds, chrom_ds): def shift_times(event, augCanvas):
"""shifts times when arrow is pressed""" """shifts times when arrow is pressed"""
if event.key() == QtCore.Qt.Key_Left: if event.key() == QtCore.Qt.Key_Left:
move = -1 move = -1
...@@ -267,14 +270,15 @@ def shift_times(event, spect, chrom, ds, ms_ds, chrom_ds): ...@@ -267,14 +270,15 @@ def shift_times(event, spect, chrom, ds, ms_ds, chrom_ds):
move = +1 move = +1
else: else:
return return
if not np.array_equal(chrom_ds['timesarg'], []): if not np.array_equal(augCanvas.chrom['timesarg'], []):
x_min, x_max = chrom_ds['t_start'], chrom_ds['t_end'] x_min, x_max = augCanvas.chrom['t_start'], augCanvas.chrom['t_end']
alltimes = np.concatenate([subset['chrom_dat'][0] for subset in ds]) alltimes = np.concatenate([subset['chrom_dat'][0] for subset
in augCanvas.ds])
times = dt.argsubselect(alltimes, x_min, x_max) + move times = dt.argsubselect(alltimes, x_min, x_max) + move
goodtimes = np.where((times < len(alltimes)) & ~(times <0))[0] goodtimes = np.where((times < len(alltimes)) & ~(times <0))[0]
if not np.array_equal(goodtimes, []): if not np.array_equal(goodtimes, []):
x_min, x_max = alltimes[times[goodtimes[[0,-1]]]] x_min, x_max = alltimes[times[goodtimes[[0,-1]]]]
pick_times(x_min, x_max, spect, ds, chrom, ms_ds, chrom_ds) pick_times(x_min, x_max, augCanvas)
def autozoomy(ms_spec): def autozoomy(ms_spec):
......
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