Commit f4def8f2 authored by Yan's avatar Yan
Browse files

Added DRL cache, minor DRL fixes

* Undecided where to keep pushbuttons
* Added verification that mass does not end-up empty
parent 781531ed
......@@ -33,6 +33,7 @@ def main():
name="Chromatogram", xlabel="time(min)",
ylabel="total ion count")
filename = [None]
drlcache = [None, None]
p_logger = logging.getLogger('parseLogger')
logging.basicConfig()
......@@ -82,7 +83,7 @@ def main():
tools_menu.addAction('&TSQ zce', lambda: zce.dialog(
main_window, ds, filename), QtCore.Qt.CTRL + QtCore.Qt.Key_T)
tools_menu.addAction('&DRL..', lambda: drl.dialog(
main_window, ds, filename, mass_selector, spectrum),
main_window, ds, filename, mass_selector, spectrum, drlcache),
QtCore.Qt.CTRL + QtCore.Qt.Key_D)
main_widget = QtWidgets.QWidget(main_window)
......
......@@ -26,8 +26,8 @@ def update_spectrum(start, end, spectrum, dataset):
return
#TODO: make the function more economical both in CPU load and in linecount
nlen = len(dataset['masses'])
start_mass = None
mlen = len(dataset['masses'])
start_mass = None
end_mass = None
for i, mass in enumerate(dataset['masses'][0:]):
if mass > start and start_mass is None:
......@@ -35,9 +35,9 @@ def update_spectrum(start, end, spectrum, dataset):
if mass > end and end_mass is None:
end_mass = i
if end_mass is None:
end_mass = len(dataset['masses'])
end_mass = mlen
if start_mass is None:
start_mass = len(dataset['masses'])-1
start_mass = mlen-1
if start_mass == end_mass:
if start_mass == 0:
end_mass = 1
......@@ -73,22 +73,14 @@ def getTableItemList(ptable):
return ion_list
def update_daughter(pname, start_mz, end_mz, dname, ptable, dtable):
"""update daugher Ion name and "corr to" selection"""
dname.setText("{} ({:.2f}-{:.2f})".format(
pname.text(),float(start_mz.text()),float(end_mz.text())))
for i in (range(dtable.rowCount())):
index = dtable.cellWidget(i,2).currentIndex()
dtable.cellWidget(i,2).clear()
dtable.cellWidget(i,2).addItem("")
dtable.cellWidget(i,2).addItems(getTableItemList(ptable))
dtable.cellWidget(i,2).setCurrentIndex(index)
def update_drl(start_mz, end_mz, spectrum, dataset, pname, dname,
ptable, dtable):
"""keeps start < end and updates spectrum and daughter table"""
"""cares that masses are in order and valid, then refresh tables"""
for line in start_mz, end_mz:
status = QtGui.QDoubleValidator().validate(line.text(),0)[0]
if status in (0, 1):
line.setText("0.00")
start = float(start_mz.text())
end = float(end_mz.text())
......@@ -97,12 +89,21 @@ def update_drl(start_mz, end_mz, spectrum, dataset, pname, dname,
start_mz.setText(str(start))
end_mz.setText(str(end))
dname.setText("{} ({:.2f}-{:.2f})".format(
pname.text(),float(start_mz.text()),float(end_mz.text())))
for i in (range(dtable.rowCount())):
index = dtable.cellWidget(i,2).currentIndex()
dtable.cellWidget(i,2).clear()
dtable.cellWidget(i,2).addItem("")
dtable.cellWidget(i,2).addItems(getTableItemList(ptable))
dtable.cellWidget(i,2).setCurrentIndex(index)
update_spectrum(start, end, spectrum, dataset)
update_daughter(pname, start_mz, end_mz, dname, ptable, dtable)
def remove_rows(ptable, dtable):
# TODO: maybe better selection in future, but this works for now
# TODO: maybe nicer selection in future, but this works for now
rows = reversed(list(set(
map(lambda index: index.row(), ptable.selectedIndexes()))))
for row in rows:
......@@ -152,6 +153,8 @@ def add_line(parent_widget, mass_selector, spectrum, ds, parenttable, daughterta
parenttable.setCellWidget(newrow, 3, graph_canvas)
daughtertable.setRowCount(newrow + 1)
#TODO: decide which box will be used in the final version
daughtertable.setItem(newrow,0, QtWidgets.QTableWidgetItem())
daughtertable.item(newrow,0).setFlags(daughtertable.item(newrow,0).flags()
& ~QtCore.Qt.ItemIsSelectable)
......@@ -159,7 +162,9 @@ def add_line(parent_widget, mass_selector, spectrum, ds, parenttable, daughterta
dname = QtWidgets.QTableWidgetItem()
dname.setFlags(dname.flags() & ~QtCore.Qt.ItemIsEditable)
dname.setTextAlignment(QtCore.Qt.AlignRight)
daughtertable.setItem(newrow, 1, dname)
daughtertable.setCellWidget(newrow, 1, QtWidgets.QCheckBox())
corto = QtWidgets.QComboBox()
corto.setFrame(False)
......@@ -172,8 +177,9 @@ def add_line(parent_widget, mass_selector, spectrum, ds, parenttable, daughterta
update_drl(start_mz, end_mz, ionspect, ds, pname, dname,
parenttable, daughtertable)
pname.editingFinished.connect(lambda: update_daughter(
pname, start_mz, end_mz, dname, parenttable, daughtertable))
pname.editingFinished.connect(lambda: update_drl(
start_mz, end_mz, ionspect, ds, pname, dname, parenttable,
daughtertable))
start_mz.editingFinished.connect(lambda: update_drl(
start_mz, end_mz, ionspect, ds, pname, dname, parenttable,
daughtertable))
......@@ -198,9 +204,12 @@ def iontable(labels, exp_col):
return table
def dialog(parent, ds, filename, mass_selector, spectrum):
def dialog(parent, ds, filename, mass_selector, spectrum, cache):
"""constructs a dialog window"""
def savecache(cache,pt,dt):
cache[0], cache[1] = pt, dt
dial_widget = QtWidgets.QDialog(
parent, windowTitle='Delayed reactant labelling')
......@@ -216,31 +225,41 @@ def dialog(parent, ds, filename, mass_selector, spectrum):
close = QtWidgets.QPushButton("&Close")
close.clicked.connect(dial_widget.close)
btn_add = QtWidgets.QPushButton("&Add")
btn_rem = QtWidgets.QPushButton("Remove")
# pt = parenttable
pt = iontable(["Name", "start (m/z)", "end (m/z)", "profile"], 2)
# dt = daughtertable
dt = iontable(["","Name", "corrected to", "factor"], 2)
dt.horizontalHeader().setSectionResizeMode(
if cache == [None, None]:
dt = iontable(["","Name", "corrected to", "factor"], 2)
dt.horizontalHeader().setSectionResizeMode(
0, QtWidgets.QHeaderView.ResizeToContents)
dt.horizontalHeader().setSectionResizeMode(
dt.horizontalHeader().setSectionResizeMode(
3, QtWidgets.QHeaderView.Fixed)
btn_add = QtWidgets.QPushButton("&Add")
btn_rem = QtWidgets.QPushButton("Remove")
pt_butlayout = QtWidgets.QHBoxLayout()
pt_butlayout.addWidget(btn_add)
pt_butlayout.addWidget(btn_rem)
pt_butlayout.addStretch(0)
pt = iontable(["Name", "start (m/z)", "end (m/z)", "profile"], 2)
for i in range(5):
add_line(dial_widget, mass_selector, spectrum, ds, pt, dt)
else:
pt = cache[0]
dt = cache[1]
btn_add.clicked.connect(lambda: add_line(
dial_widget, mass_selector, spectrum, ds, pt, dt))
btn_rem.clicked.connect(lambda: remove_rows(pt,dt))
dial_widget.finished.connect(lambda: savecache(cache, pt, dt))
main_layout = QtWidgets.QVBoxLayout(dial_widget)
sub_layout = QtWidgets.QHBoxLayout()
tablelayout = QtWidgets.QVBoxLayout()
pt_butlayout = QtWidgets.QHBoxLayout()
main_butlayout = QtWidgets.QHBoxLayout()
pt_butlayout.addWidget(btn_add)
pt_butlayout.addWidget(btn_rem)
pt_butlayout.addStretch(0)
main_layout.addLayout(sub_layout)
main_layout.addWidget(HBar())
main_layout.addLayout(main_butlayout)
......
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