Commit 4f3a3efa authored by 3Yan's avatar 3Yan
Browse files

Small bugfix in main, add_parent_ion working in DRL!

* still preliminary - code is messy there
parent 5d5f2112
...@@ -53,12 +53,12 @@ def main(): ...@@ -53,12 +53,12 @@ def main():
gt.zoom_factory(chromatogram, 1.15) gt.zoom_factory(chromatogram, 1.15)
gt.pan_factory(spectrum, ms) gt.pan_factory(spectrum, ms)
gt.zoom_factory(spectrum, 1.15, ms) gt.zoom_factory(spectrum, 1.15, ms)
gt.mass_selector = SpanSelector( mass_selector = SpanSelector(
spectrum, lambda x_min, x_max: gt.pick_masses( spectrum, lambda x_min, x_max: gt.pick_masses(
x_min, x_max, spectrum, ms), x_min, x_max, spectrum, ms),
'horizontal', useblit=True, rectprops=dict( 'horizontal', useblit=True, rectprops=dict(
alpha=0.15, facecolor='purple'), button=3) alpha=0.15, facecolor='purple'), button=3)
gt.time_selector = SpanSelector( time_selector = SpanSelector(
chromatogram, lambda x_min, x_max: gt.pick_times( chromatogram, lambda x_min, x_max: gt.pick_times(
x_min, x_max, spectrum, ds, chromatogram, ms, chrom), x_min, x_max, spectrum, ds, chromatogram, ms, chrom),
'horizontal', useblit=True, rectprops=dict( 'horizontal', useblit=True, rectprops=dict(
...@@ -82,7 +82,8 @@ def main(): ...@@ -82,7 +82,8 @@ def main():
tools_menu.addAction('&TSQ zce', lambda: zce.dialog( tools_menu.addAction('&TSQ zce', lambda: zce.dialog(
main_window, ds, filename), QtCore.Qt.CTRL + QtCore.Qt.Key_T) main_window, ds, filename), QtCore.Qt.CTRL + QtCore.Qt.Key_T)
tools_menu.addAction('&DRL..', lambda: drl.dialog( tools_menu.addAction('&DRL..', lambda: drl.dialog(
main_window, ds, filename), QtCore.Qt.CTRL + QtCore.Qt.Key_D) main_window, ds, filename, mass_selector, spectrum),
QtCore.Qt.CTRL + QtCore.Qt.Key_D)
main_widget = QtWidgets.QWidget(main_window) main_widget = QtWidgets.QWidget(main_window)
main_window.setCentralWidget(main_widget) main_window.setCentralWidget(main_widget)
...@@ -5,6 +5,7 @@ from matplotlib.figure import Figure ...@@ -5,6 +5,7 @@ from matplotlib.figure import Figure
from matplotlib.widgets import SpanSelector from matplotlib.widgets import SpanSelector
from PyQt5 import QtCore from PyQt5 import QtCore
from PyQt5 import QtWidgets from PyQt5 import QtWidgets
import prasopes.graphtools as gt
import sys import sys
import matplotlib import matplotlib
import numpy as np import numpy as np
...@@ -19,8 +20,168 @@ class HBar(QtWidgets.QFrame): ...@@ -19,8 +20,168 @@ class HBar(QtWidgets.QFrame):
self.setFrameShape(QtWidgets.QFrame.HLine) self.setFrameShape(QtWidgets.QFrame.HLine)
def add_parent(parent_widget, mass_selector, spectrum, ds, parenttable):
"""add parent ion to the table"""
ap_dial = QtWidgets.QDialog(parent_widget, windowTitle='Add Ion')
ion = dict(x=[0], y=[0], line=None, name="", xlabel="m/z",
ylabel="ion count", annotation=[])
ion_graph = Figure(figsize=(3, 1.5), dpi=100, facecolor="None")
ionspect = ion_graph.add_subplot(111, facecolor=(1, 1, 1, 0.8))
graph_canvas = FigureCanvas(ion_graph)
gt.pop_plot(ionspect, ion)
def end_bindings(bindings, axis):
fig = axis.get_figure()
for i in bindings:
def update_fields(x_min, x_max, startw, endw):
def update_parent(start_mz, end_mz, spectrum, ion_set, dataset):
start = start_mz.value()
end = end_mz.value()
if start > end:
start = end_mz.value()
end = start_mz.value()
#TODO: maybe find a way how this should be called only once
#TODO: make the function more economical both in CPU load and in linecount
start_mass = None
end_mass = None
for i, mass in enumerate(dataset['masses'][0:]):
if mass > start and start_mass is None:
start_mass = i
if mass > end and end_mass is None:
end_mass = i
if end_mass is None:
end_mass = len(dataset['masses'])
if start_mass is None:
start_mass = len(dataset['masses'])-1
if start_mass == end_mass:
if start_mass == 0:
end_mass = 1
start_mass -= 1
end_mass = start_mass + 2
gt.pop_plot(spectrum, ion_set)
yshape = np.mean(dataset['matrix'], axis=0)
dots_x = dataset['masses']
dots_y = yshape
full_x = dataset['masses'][start_mass:end_mass]
full_y = yshape[start_mass:end_mass]
spectrum.plot(dots_x, dots_y, ':', color='gray')
spectrum.plot(full_x, full_y, 'r')
xex = (dataset['masses'][end_mass-1]-dataset['masses'][start_mass])*0.25
ymax = max(yshape[start_mass:end_mass])
spectrum.set_ylim(ymax*-0.1, ymax*1.1)
def activate_altselector(event, mass_selector, picker):
if event.key == 'shift': = False = True
def deactivate_altselector(event, mass_selector, picker):
if == 'motion_notify_event' \
or ( == 'key_release_event'
and event.key == 'shift'): = True = False
def add_ion(start_mz, end_mz, table, dialog):
newrow = table.rowCount()
col2 = QtWidgets.QTableWidgetItem()
ax = spectrum.get_figure()
bindings = []
bindings.append(ax.canvas.mpl_connect('key_press_event', lambda
event: activate_altselector(event, mass_selector, picker)))
bindings.append(ax.canvas.mpl_connect('key_release_event', lambda
event: deactivate_altselector(event, mass_selector, picker)))
# TODO: somehow manage if user enters with shift pressed, but
# figure_enter_event cannot handle this :( and with QT it is PIA
bindings.append(ax.canvas.mpl_connect('figure_leave_event', lambda
event: deactivate_altselector(event, mass_selector, picker)))
ap_dial.finished.connect(lambda: end_bindings(bindings, ax))
start_mz = QtWidgets.QDoubleSpinBox(maximum=999999)
start_mz.valueChanged.connect(lambda: update_parent(
start_mz, end_mz, ionspect, ion, ds))
end_mz = QtWidgets.QDoubleSpinBox(maximum=999999)
end_mz.valueChanged.connect(lambda: update_parent(
start_mz, end_mz, ionspect, ion, ds))
submit = QtWidgets.QPushButton("&Submit")
submit.clicked.connect(lambda: add_ion(start_mz, end_mz, parenttable, ap_dial))
cancel = QtWidgets.QPushButton("Cancel")
main_layout = QtWidgets.QVBoxLayout(ap_dial)
data_layout = QtWidgets.QHBoxLayout()
butt_layout = QtWidgets.QHBoxLayout()
main_layout.addWidget(QtWidgets.QLabel("Press shift in "
"the chromatogram window and \n"
"select the ion range by the right mouse button\n"
"or fill the columns manually"))
main_layout.addWidget(graph_canvas, 1)
picker = SpanSelector(spectrum, lambda x_min, x_max:
update_fields(x_min, x_max, start_mz, end_mz),
'horizontal', useblit=True, rectprops=dict(
alpha=0.15, facecolor='orange'), button=3) = False
def iontable(labels, exp_col): def iontable(labels, exp_col):
"""creates a table for ions""" """creates a table for ions"""
def remove_rows(table):
# TODO: maybe better selection in future, but this works for now
rows = reversed(list(set(
map(lambda index: index.row(), table.selectedIndexes()))))
for row in rows:
table = QtWidgets.QTableWidget(columnCount=len(labels)) table = QtWidgets.QTableWidget(columnCount=len(labels))
table.setSizePolicy(QtWidgets.QSizePolicy.Fixed, table.setSizePolicy(QtWidgets.QSizePolicy.Fixed,
QtWidgets.QSizePolicy.Expanding) QtWidgets.QSizePolicy.Expanding)
...@@ -35,6 +196,7 @@ def iontable(labels, exp_col): ...@@ -35,6 +196,7 @@ def iontable(labels, exp_col):
table.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn) table.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
table_add = QtWidgets.QPushButton("Add") table_add = QtWidgets.QPushButton("Add")
table_rem = QtWidgets.QPushButton("Remove") table_rem = QtWidgets.QPushButton("Remove")
table_rem.clicked.connect(lambda: remove_rows(table))
table_butlayout = QtWidgets.QHBoxLayout() table_butlayout = QtWidgets.QHBoxLayout()
table_butlayout.addWidget(table_add) table_butlayout.addWidget(table_add)
table_butlayout.addWidget(table_rem) table_butlayout.addWidget(table_rem)
...@@ -42,8 +204,9 @@ def iontable(labels, exp_col): ...@@ -42,8 +204,9 @@ def iontable(labels, exp_col):
return table, table_butlayout, table_add, table_rem return table, table_butlayout, table_add, table_rem
def dialog(parent, ds, filename): def dialog(parent, ds, filename, mass_selector, spectrum):
"""constructs a dialog window""" """constructs a dialog window"""
dial_widget = QtWidgets.QDialog( dial_widget = QtWidgets.QDialog(
parent, windowTitle='Delayed reactant labelling') parent, windowTitle='Delayed reactant labelling')
...@@ -53,15 +216,19 @@ def dialog(parent, ds, filename): ...@@ -53,15 +216,19 @@ def dialog(parent, ds, filename):
graph_canvas.setStyleSheet("background-color:transparent;") graph_canvas.setStyleSheet("background-color:transparent;")
graph_canvas.setAutoFillBackground(False) graph_canvas.setAutoFillBackground(False)
drl_load = QtWidgets.QPushButton("Load") drl_load = QtWidgets.QPushButton("&Load")
drl_save = QtWidgets.QPushButton("Save") drl_save = QtWidgets.QPushButton("&Save")
drl_export = QtWidgets.QPushButton("Export") drl_export = QtWidgets.QPushButton("&Export")
close = QtWidgets.QPushButton("Close") close = QtWidgets.QPushButton("&Close")
close.clicked.connect(dial_widget.close) close.clicked.connect(dial_widget.close)
# pt = parenttable # pt = parenttable
pt, pt_butlayout, pt_add, pt_rem = iontable( pt, pt_butlayout, pt_add, pt_rem = iontable(
["Name", "start (m/z)", "end (m/z)", "profile"], 2) ["Name", "start (m/z)", "end (m/z)", "profile"], 2)
pt_add.clicked.connect(lambda: add_parent(
dial_widget, mass_selector, spectrum, ds, pt))
# dt = daughtertable # dt = daughtertable
dt, dt_butlayout, dt_add, dt_rem = iontable( dt, dt_butlayout, dt_add, dt_rem = iontable(
["Name", "start (m/z)", "end (m/z)", "corr to"], 2) ["Name", "start (m/z)", "end (m/z)", "corr to"], 2)
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