Commit 37381649 authored by Yan's avatar Yan
Browse files

DRL table loading works

* better input sanitization will be needed someday in future
parent f22afd99
...@@ -83,7 +83,7 @@ def main(): ...@@ -83,7 +83,7 @@ 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, mass_selector, spectrum, drlcache), main_window, ds, filename, drlcache),
QtCore.Qt.CTRL + QtCore.Qt.Key_D) QtCore.Qt.CTRL + QtCore.Qt.Key_D)
main_widget = QtWidgets.QWidget(main_window) main_widget = QtWidgets.QWidget(main_window)
......
...@@ -151,7 +151,7 @@ def remove_rows(ptable, dtable): ...@@ -151,7 +151,7 @@ def remove_rows(ptable, dtable):
dtable.cellWidget(i,2).setCurrentIndex(index-1) dtable.cellWidget(i,2).setCurrentIndex(index-1)
def setDoubleCell(table,row,column): def setDoubleCell(table, row, column):
"""populate table cell with float-validated posititve text""" """populate table cell with float-validated posititve text"""
table.setCellWidget(row,column,QtWidgets.QLineEdit()) table.setCellWidget(row,column,QtWidgets.QLineEdit())
validator = QtGui.QDoubleValidator() validator = QtGui.QDoubleValidator()
...@@ -164,7 +164,7 @@ def setDoubleCell(table,row,column): ...@@ -164,7 +164,7 @@ def setDoubleCell(table,row,column):
return table.cellWidget(row,column) return table.cellWidget(row,column)
def add_line(parent_widget, mass_selector, spectrum, ds, parenttable, def add_line(parent_widget, ds, parenttable,
daughtertable, drlspectrum): daughtertable, drlspectrum):
"""add parent ion to the table""" """add parent ion to the table"""
ion_graph = Figure(figsize=(3, 1.5), dpi=100, facecolor="None") ion_graph = Figure(figsize=(3, 1.5), dpi=100, facecolor="None")
...@@ -239,12 +239,48 @@ def iontable(labels, exp_col): ...@@ -239,12 +239,48 @@ def iontable(labels, exp_col):
return table return table
def load_drlconfig(ptable, dtable): def load_drltables(parent, ptable, dtable, dataset, drlspectrum):
#will be substituted with something that can vwork in future filename = QtWidgets.QFileDialog.getOpenFileName(
if 0 == 1: caption="Load DRL config tables",
filter="comma-separated values (*.csv)")[0]
if filename is not '':
names = []
start_masses = []
end_masses = []
states = []
corrected_to = []
corr_factors = []
with open(filename, 'r') as cfile:
rawdata = cfile.read().splitlines()
for i in range(1,len(rawdata)):
rawline=rawdata[i].split(",")
if len(rawline) != 6 or int(rawline[3]) not in range(3) \
or int(rawline[4]) not in range(len(rawdata)):
QtWidgets.QMessageBox.warning(
parent, "Load DRL config tables",
"Config file corrupted on line {},"
" cancelling request".format(i+1))
return
for j, k in enumerate((names, start_masses, end_masses,
states, corrected_to, corr_factors)):
k.append(rawline[j])
for row in reversed(range(ptable.rowCount())): for row in reversed(range(ptable.rowCount())):
dtable.removeRow(row) dtable.removeRow(row)
ptable.removeRow(row) ptable.removeRow(row)
#first populate only parent table
for i in range(len(names)):
add_line(parent, dataset, ptable, dtable, drlspectrum)
print(names[i])
ptable.cellWidget(i, 0).setText(names[i])
ptable.cellWidget(i, 1).setText(start_masses[i])
ptable.cellWidget(i, 2).setText(end_masses[i])
#and after that daughter table
for i in range(len(names)):
dtable.cellWidget(i, 2).setCurrentIndex(
int(corrected_to[i]))
dtable.cellWidget(i, 3).setText(corr_factors[i])
dtable.cellWidget(i, 1).setCheckState(int(states[i]))
def save_drlconfig(ptable, dtable, parent): def save_drlconfig(ptable, dtable, parent):
...@@ -267,6 +303,7 @@ def save_drlconfig(ptable, dtable, parent): ...@@ -267,6 +303,7 @@ def save_drlconfig(ptable, dtable, parent):
expf.write("{}\n".format((",".join(map(str, vals))))) expf.write("{}\n".format((",".join(map(str, vals)))))
expf.close() expf.close()
def export_drlspectrum(parent, fn, ptable, dtable, ds): def export_drlspectrum(parent, fn, ptable, dtable, ds):
if fn[0] is None: if fn[0] is None:
QtWidgets.QMessageBox.warning( QtWidgets.QMessageBox.warning(
...@@ -288,8 +325,7 @@ def export_drlspectrum(parent, fn, ptable, dtable, ds): ...@@ -288,8 +325,7 @@ def export_drlspectrum(parent, fn, ptable, dtable, ds):
expf.close() expf.close()
def dialog(parent, ds, filename, cache):
def dialog(parent, ds, filename, mass_selector, spectrum, cache):
"""constructs a dialog window""" """constructs a dialog window"""
def savecache(cache,pt,dt,canvas): def savecache(cache,pt,dt,canvas):
...@@ -330,17 +366,17 @@ def dialog(parent, ds, filename, mass_selector, spectrum, cache): ...@@ -330,17 +366,17 @@ def dialog(parent, ds, filename, mass_selector, spectrum, cache):
pt = iontable(["Name", "start (m/z)", "end (m/z)", "profile"], 2) pt = iontable(["Name", "start (m/z)", "end (m/z)", "profile"], 2)
for i in range(5): for i in range(5):
add_line(dial_widget, mass_selector, spectrum, ds, pt, dt, add_line(dial_widget, ds, pt, dt, chromplot)
chromplot)
else: else:
pt = cache[0] pt = cache[0]
dt = cache[1] dt = cache[1]
graph_canvas = cache[2] graph_canvas = cache[2]
btn_add.clicked.connect(lambda: add_line( btn_add.clicked.connect(lambda: add_line(
dial_widget, mass_selector, spectrum, ds, pt, dt, chromplot)) dial_widget, ds, pt, dt, chromplot))
btn_rem.clicked.connect(lambda: remove_rows(pt,dt)) btn_rem.clicked.connect(lambda: remove_rows(pt,dt))
drl_load.clicked.connect(lambda: load_drlconfig(pt, dt)) drl_load.clicked.connect(lambda: load_drltables(
dial_widget, pt, dt, ds, chromplot))
drl_save.clicked.connect(lambda: save_drlconfig( drl_save.clicked.connect(lambda: save_drlconfig(
pt, dt, dial_widget)) pt, dt, dial_widget))
drl_export.clicked.connect(lambda: export_drlspectrum( drl_export.clicked.connect(lambda: export_drlspectrum(
......
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