Commit 0c286a23 authored by Yan's avatar Yan
Browse files

Constrained layout, intensity selector

* modded code to accept constrained layout in main GUI without major
issues
* added intensity selector - in a dirty way for now
parent 0da40869
......@@ -174,7 +174,11 @@ def oddeven_changed(chromatogram, spectrum, ds, ms, filename, chrom, config,
update_spectrum(chromatogram, spectrum, ds, ms, filename, chrom, config)
def key_pressed(event, chrom, spect, ds, ms_ds, fn, chrom_ds, config):
def key_pressed(event, chrom, spect, ds, ms_ds, fn, chrom_ds, config,
mass_selector, intensity_selector):
if event.modifiers() == QtCore.Qt.ShiftModifier:
mass_selector.active = False
intensity_selector.active = True
if event.key() == QtCore.Qt.Key_F5:
update_spectrum(chrom, spect, ds, ms_ds, fn, chrom_ds, config)
if event.key() == QtCore.Qt.Key_C:
......@@ -187,6 +191,12 @@ def key_pressed(event, chrom, spect, ds, ms_ds, fn, chrom_ds, config):
gt.shift_times(event, spect, chrom, ds, ms_ds, chrom_ds)
def key_released(event, spect, mass_selector, intensity_selector):
if event.key() == QtCore.Qt.Key_Shift:
mass_selector.active = True
intensity_selector.active = False
def about(parent):
"""constructs window with "about" info"""
QtWidgets.QMessageBox.information(
......@@ -237,11 +247,10 @@ def main():
paramstable = dt.table(["","name","value"], 100)
paramstable.horizontalHeader().setSectionResizeMode(
0, QtWidgets.QHeaderView.ResizeToContents)
graph = Figure(figsize=(5, 4), dpi=100, facecolor="None")
graph = Figure(figsize=(5, 4), dpi=100, facecolor="None", constrained_layout=True)
grid = graph.add_gridspec(2, 1)
chromatogram = graph.add_subplot(grid[0,0], facecolor=(1, 1, 1, 0.8))
spectrum = graph.add_subplot(grid[1,0], facecolor=(1, 1, 1, 0.8))
graph.tight_layout()
mpl_canvas = FigureCanvas(graph)
mpl_canvas.setStyleSheet("background-color:transparent;")
mpl_canvas.setAutoFillBackground(False)
......@@ -256,6 +265,12 @@ def main():
x_min, x_max, spectrum, ms), 'horizontal', minspan=0.01,
useblit=True, rectprops=dict(alpha=0.15, facecolor='purple'),
button=3)
intensity_selector = SpanSelector(
spectrum, lambda y_min, y_max: gt.pick_intensities(
y_max, spectrum, ms), 'vertical', minspan=0.01,
useblit=True, rectprops=dict(alpha=0.15, facecolor='purple'),
button=3)
intensity_selector.active=False
time_selector = SpanSelector(
chromatogram, lambda x_min, x_max: gt.pick_times(
x_min, x_max, spectrum, ds, chromatogram, ms, chrom, paramstable),
......@@ -426,7 +441,10 @@ def main():
chrom, update, config)
main_window.setAcceptDrops(True)
main_window.keyPressEvent = lambda event: key_pressed(event, chromatogram,
spectrum, ds, ms, filename, chrom, config)
spectrum, ds, ms, filename, chrom, config,
mass_selector, intensity_selector)
main_window.keyReleaseEvent = lambda event: key_released(event, spectrum,
mass_selector, intensity_selector)
main_window.addToolBar(QtCore.Qt.TopToolBarArea, toolBar)
main_window.addDockWidget(QtCore.Qt.LeftDockWidgetArea, treedock)
......
from PyQt5 import QtWidgets
from PyQt5 import QtCore
from matplotlib.widgets import SpanSelector
import numpy as np
import prasopes.datatools as dt
import prasopes.config as cf
import matplotlib
from PyQt5 import QtWidgets
from PyQt5 import QtCore
colors = np.array([[0, 0, 0], [255, 0, 0], [0, 255, 0], [0, 0, 255],
......@@ -13,6 +14,20 @@ colors = np.array([[0, 0, 0], [255, 0, 0], [0, 255, 0], [0, 0, 255],
ann_bbox = dict(boxstyle="round", fc="w", ec="0.5", alpha=0.5)
def pick_masses(vmin, vmax, ax, data):
"""zoom the spectrum in x axis by mass range"""
ax.set_xlim(vmin, vmax)
autozoomy(ax)
ann_spec(ax, data)
def pick_intensities(vmax, ax, data):
"""zoom the spectrum in y axis by top intensity from range"""
ax.set_ylim(-vmax*0.01, vmax)
ann_spec(ax, data)
def zoom_factory(axis, base_scale, plot_data=None):
"""returns zooming functionality to axis"""
def zoom_fun(event, pd, ax, scale):
......@@ -78,6 +93,7 @@ def pan_factory(axis, plot=None):
action, id_drag, id_release, pd, ax))
def drag_fun(event, ax):
ax.figure.set_constrained_layout(False)
ax.drag_pan(1, 'x', event.x, event.y)
ax.figure.canvas.draw()
......@@ -88,6 +104,7 @@ def pan_factory(axis, plot=None):
if type(pd) is dict and "annotation" in pd:
ann_spec(ax, pd)
ax.figure.canvas.draw()
ax.figure.set_constrained_layout(True)
fig = axis.get_figure()
fig.canvas.mpl_connect('button_press_event',
......@@ -115,13 +132,6 @@ def textedit_factory(axis, plot_data):
axis.figure.canvas.mpl_connect('pick_event', annpicked)
def pick_masses(x_min, x_max, ms_spec, msdata):
"""zoom the spectrum in x axis by mass range"""
ms_spec.set_xlim(x_min, x_max)
autozoomy(ms_spec)
ann_spec(ms_spec, msdata)
def plot_subtime(mpl_spectrum, mpl_chromatogram, ds, ms_data, chrom_data):
"""plot averaged spectrum of subselected part of the chromatogram"""
slims = [mpl_spectrum.get_xlim(), mpl_spectrum.get_ylim()]
......@@ -221,9 +231,9 @@ def autozoomy(ms_spec):
ms_spec.autoscale(True, 'y')
gap = 0.01
ymax = np.max([np.max(line.get_data()[1][dt.argsubselect(
line.get_data()[0], *ms_spec.get_xlim())])
line.get_data()[0], *ms_spec.get_xlim())])*1.1
for line in ms_spec.lines])
ms_spec.set_ylim(-ymax*gap, ymax*1.1)
ms_spec.set_ylim(-ymax*gap, ymax)
ms_spec.figure.canvas.draw()
def ann_spec(ms_spec, msdata, ann_limit=0.01):
......@@ -373,6 +383,7 @@ def populate(mpl_chromatogram, mpl_spectrum, data_set,
for ax in (mpl_spectrum, mpl_chromatogram):
if not ms_data['headers'] == []:
ax.legend(loc=2)
ax.get_legend().set_in_layout(False)
ax.autoscale(True)
ax.set_ylim(ax.get_ylim()[1]*-0.01, ax.get_ylim()[1]*1.1)
ax.figure.canvas.draw()
......
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