Commit c59fd2bc authored by Yan's avatar Yan
Browse files

Add parent improvement, add daughter initialized

* Add parent code still remains ugly, but it works slightly better
* Daugher table needs desition about its form now.
parent 4f3a3efa
......@@ -37,26 +37,38 @@ def add_parent(parent_widget, mass_selector, spectrum, ds, parenttable):
graph_canvas.setFocusPolicy(QtCore.Qt.ClickFocus)
gt.pop_plot(ionspect, ion)
def add_ion(start_mz, end_mz, table, dialog):
newrow = table.rowCount()
table.setRowCount(newrow+1)
table.setItem(newrow,0,QtWidgets.QTableWidgetItem())
table.horizontalHeader().setSectionResizeMode(
1, QtWidgets.QHeaderView.ResizeToContents)
table.horizontalHeader().setSectionResizeMode(
2, QtWidgets.QHeaderView.ResizeToContents)
table.setCellWidget(newrow,1,start_mz)
table.setCellWidget(newrow,2,end_mz)
dialog.close()
def end_bindings(bindings, axis):
fig = axis.get_figure()
for i in bindings:
axis.canvas.mpl_disconnect(i)
return
def update_fields(x_min, x_max, startw, endw):
endw.setValue(x_max)
startw.setValue(x_min)
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()
start_mz.setValue(start)
end_mz.setValue(end)
#TODO: maybe find a way how this should be called only once
#Dont do anything to graph when the spectrum is not populated
if (start == 0 and start == end) or type(dataset['masses']) == type(None):
return
#TODO: make the function more economical both in CPU load and in linecount
start_mass = None
end_mass = None
......@@ -90,47 +102,42 @@ def add_parent(parent_widget, mass_selector, spectrum, ds, parenttable):
spectrum.set_ylim(ymax*-0.1, ymax*1.1)
spectrum.figure.canvas.draw()
def update_fields(x_min, x_max, startw, endw, spectrum, ion_set, dataset):
endw.setValue(x_max)
startw.setValue(x_min)
update_parent(startw, endw, spectrum, ion_set, dataset)
def activate_altselector(event, mass_selector, picker):
if event.key == 'shift':
mass_selector.active = False
picker.active = True
def deactivate_altselector(event, mass_selector, picker):
if event.name == 'motion_notify_event' \
or (event.name == 'key_release_event'
and event.key == 'shift'):
mass_selector.active = True
picker.active = False
def add_ion(start_mz, end_mz, table, dialog):
newrow = table.rowCount()
table.setRowCount(newrow+1)
col2 = QtWidgets.QTableWidgetItem()
col2.setText("bagr")
table.setCellWidget(newrow,1,start_mz)
table.setCellWidget(newrow,2,end_mz)
dialog.close()
def deactivate_altselector(mass_selector, picker):
mass_selector.active = True
picker.active = False
def deactivate_keyrelease(event, mass_selector, picker):
if event.key == 'shift':
deactivate_altselector(mass_selector, picker)
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)))
event: deactivate_keyrelease(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)))
event: deactivate_altselector(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.editingFinished.connect(lambda: update_parent(
start_mz, end_mz, ionspect, ion, ds))
end_mz = QtWidgets.QDoubleSpinBox(maximum=999999)
end_mz.valueChanged.connect(lambda: update_parent(
end_mz.editingFinished.connect(lambda: update_parent(
start_mz, end_mz, ionspect, ion, ds))
submit = QtWidgets.QPushButton("&Submit")
......@@ -165,7 +172,8 @@ def add_parent(parent_widget, mass_selector, spectrum, ds, parenttable):
main_layout.addLayout(butt_layout)
picker = SpanSelector(spectrum, lambda x_min, x_max:
update_fields(x_min, x_max, start_mz, end_mz),
update_fields(x_min, x_max, start_mz, end_mz,
ionspect, ion, ds),
'horizontal', useblit=True, rectprops=dict(
alpha=0.15, facecolor='orange'), button=3)
picker.active = False
......@@ -173,6 +181,85 @@ def add_parent(parent_widget, mass_selector, spectrum, ds, parenttable):
ap_dial.show()
def add_daughter(parent_widget, p_table, d_table):
ad_dial = QtWidgets.QDialog(parent_widget, windowTitle='Add line')
parent_widget.finished.connect(ad_dial.close)
if p_table.rowCount() is 0:
QtWidgets.QMessageBox.warning(parent_widget,
'Add line', "The Raw ions table is empty, "
"cancelling request")
return
def add_ion(parent_widget, parent, correction, cf, ptable, dtable):
pn = parent.currentIndex()
corr = correction.currentIndex()-1
cf = cf.value()
print(pn,corr,cf)
print(ptable.cellWidget(pn,1).value())
start_mz = QtWidgets.QDoubleSpinBox(maximum=999999)
start_mz.setValue(ptable.cellWidget(pn,1).value())
end_mz = QtWidgets.QDoubleSpinBox(maximum=999999)
end_mz.setValue(ptable.cellWidget(pn,2).value())
newrow = dtable.rowCount()
dtable.setRowCount(newrow+1)
dtable.setItem(newrow,0,QtWidgets.QTableWidgetItem())
dtable.item(newrow,0).setText(ptable.item(pn,0).text())
dtable.horizontalHeader().setSectionResizeMode(
1, QtWidgets.QHeaderView.ResizeToContents)
dtable.horizontalHeader().setSectionResizeMode(
2, QtWidgets.QHeaderView.ResizeToContents)
dtable.setCellWidget(newrow,1,start_mz)
dtable.setCellWidget(newrow,2,end_mz)
ion_list = []
for i in range(p_table.rowCount()):
if type(p_table.item(i,0)) is not type(None):
name = p_table.item(i,0).text()
else:
name = ""
text = "{} ({}-{})".format(
name, p_table.cellWidget(i,1).value(),
p_table.cellWidget(i,2).value())
ion_list.append(text)
p_sel = QtWidgets.QComboBox()
p_sel.addItems(ion_list)
c_sel = QtWidgets.QComboBox()
c_sel.addItem(None)
c_sel.addItems(ion_list)
corr_factor = QtWidgets.QDoubleSpinBox(maximum=1337)
submit = QtWidgets.QPushButton("&Submit")
cancel = QtWidgets.QPushButton("Cancel")
cancel.clicked.connect(ad_dial.close)
main_layout = QtWidgets.QVBoxLayout(ad_dial)
data_layout = QtWidgets.QHBoxLayout()
butt_layout = QtWidgets.QHBoxLayout()
butt_layout.addStretch(1)
butt_layout.addWidget(submit)
submit.clicked.connect(lambda: add_ion(
ad_dial, p_sel, c_sel, corr_factor, p_table, d_table))
butt_layout.addWidget(cancel)
data_layout.addWidget(QtWidgets.QLabel("parent ion:"))
data_layout.addWidget(p_sel)
data_layout.addSpacing(20)
data_layout.addWidget(QtWidgets.QLabel("Correct to:"))
data_layout.addWidget(c_sel)
data_layout.addWidget(QtWidgets.QLabel("mutliplied by:"))
data_layout.addWidget(corr_factor)
data_layout.addWidget(QtWidgets.QLabel("%"))
main_layout.addLayout(data_layout)
main_layout.addLayout(butt_layout)
ad_dial.show()
def iontable(labels, exp_col):
"""creates a table for ions"""
def remove_rows(table):
......@@ -183,17 +270,23 @@ def iontable(labels, exp_col):
table.removeRow(row)
table = QtWidgets.QTableWidget(columnCount=len(labels))
table.setSizePolicy(QtWidgets.QSizePolicy.Fixed,
table.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
QtWidgets.QSizePolicy.Expanding)
table.setHorizontalHeaderLabels(labels)
tx = table.verticalHeader().width() \
table.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
for n in range(table.columnCount()):
table.horizontalHeader().setSectionResizeMode(
n, QtWidgets.QHeaderView.Stretch)
table.setMinimumSize(600,0)
"""tx = table.verticalHeader().width() \
+ table.verticalScrollBar().height()
for n in range(len(labels)):
tx = tx + table.columnWidth(n)
table.setMinimumSize(tx, 0)
table.horizontalHeader().setSectionResizeMode(
exp_col, QtWidgets.QHeaderView.Stretch)
table.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
table.setMinimumSize(tx, 0)"""
"""table.horizontalHeader().setSectionResizeMode(
exp_col, QtWidgets.QHeaderView.ResizeToContents)"""
table_add = QtWidgets.QPushButton("Add")
table_rem = QtWidgets.QPushButton("Remove")
table_rem.clicked.connect(lambda: remove_rows(table))
......@@ -231,9 +324,11 @@ def dialog(parent, ds, filename, mass_selector, spectrum):
# dt = daughtertable
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", "factor"], 2)
add_corr = QtWidgets.QPushButton("Add correction")
dt_butlayout.addWidget(add_corr)
dt_add.clicked.connect(lambda: add_daughter(
dial_widget, pt, dt))
main_layout = QtWidgets.QVBoxLayout(dial_widget)
sub_layout = QtWidgets.QHBoxLayout()
......
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