Commit 3f3c0edb authored by Yan's avatar Yan
Browse files

DRL evolution - pt5/5

* amount of "correct to" columns can be changed now in a software itself
* fix for deletion of multiple rows - now the SW survives
* time shift is now noted in the exported file (has been done in
previous commit, forget to note it)
parent 35ca446d
......@@ -83,7 +83,8 @@ def main():
drl_logger = logging.getLogger('drlLogger')
logging.basicConfig()
p_logger.setLevel("WARN")
drl_logger.setLevel("INFO")
#drl_logger.setLevel("INFO")
drl_logger.setLevel("DEBUG")
graph = Figure(figsize=(5, 4), dpi=100, facecolor="None")
......
......@@ -6,6 +6,7 @@ from PyQt5 import QtWidgets
from PyQt5 import QtGui
from PyQt5 import QtPrintSupport
from copy import copy
import gc
import matplotlib
import numpy as np
import prasopes.datatools as dt
......@@ -19,12 +20,13 @@ matplotlib.use("Qt5Agg")
logger = logging.getLogger('drlLogger')
class HBar(QtWidgets.QFrame):
"""horizontal bar class"""
class StretchWidget(QtWidgets.QWidget):
"""horizontal stretch class"""
def __init__(self):
super(HBar, self).__init__()
super(StretchWidget, self).__init__()
self._main = QtWidgets.QWidget()
self.setFrameShape(QtWidgets.QFrame.HLine)
self.setSizePolicy(QtWidgets.QSizePolicy.Expanding
,QtWidgets.QSizePolicy.Preferred)
def floatize(table, row, column, nonneg=True):
......@@ -79,7 +81,6 @@ def get_intensity(row, ds, drls):
def get_daughterset(ds, drls):
"""Fuction to acquire the curves of the daugher ions"""
logger.info("getting set of the daughter ions")
# TODO: write a less resources demanding function - probably "per-line"
names = []
times = ds['chrom_dat'][0, :] - drls['tshift'].value()
intensities = []
......@@ -87,7 +88,7 @@ def get_daughterset(ds, drls):
if drls['dt'].cellWidget(row, 0).checkState() == 2:
intensity = get_intensity(row, ds, drls)
corlist = []
for i in range(drls['cors']):
for i in range(drls['cors'].value()):
cor = drls['dt'].cellWidget(row, 1+i*2).currentIndex() - 1
if cor not in (-2, -1):
factor = floatize(drls['dt'], row, 2+i*2, False)
......@@ -108,7 +109,6 @@ def get_parentset(ds, drls):
names = []
times = ds['chrom_dat'][0, :]
intensities = []
# TODO: resolve intensities trouble
rowlist = []
for row in range(drls['dt'].rowCount()):
if drls['dt'].cellWidget(row, 0).checkState() == 2:
......@@ -135,7 +135,6 @@ def update_drlspectrum(ds, drls, drlspectrum):
[200, 50, 0], [255, 0, 200], [0, 100, 0],
[0, 100, 255], [100, 100, 100]])
# TODO: write a less resources demanding function
names, times, intensities = get_daughterset(ds, drls)
for i in range(len(drlspectrum.lines)):
drlspectrum.lines[0].remove()
......@@ -190,7 +189,7 @@ def update_corrfors(drls):
"""update corrections selection layout of the daughter table"""
ionlist = gettableitemlist(drls['pt'])
for row in range(drls['dt'].rowCount()):
for i in range(drls['cors']):
for i in range(drls['cors'].value()):
corfor = drls['dt'].cellWidget(row, 1+i*2)
index = corfor.currentIndex()
corfor.blockSignals(True)
......@@ -226,13 +225,46 @@ def corr_changed(correction, ds, drls, drlspectrum):
for j in range(drls['dt'].columnCount()):
if correction == drls['dt'].cellWidget(i, 1+j*2):
row, column = i, 1 + j*2
logger.debug('''Change of the "correct to" on '''
'''row {}, column {}'''.format(
row + 1, column + 1))
if (drls['dt'].cellWidget(row, 0).checkState() == 2
and floatize(drls['dt'], row, column+1, False) != 0):
update_drlspectrum(ds, drls, drlspectrum)
def corcount_changed(ds, drls, drlspectrum):
"""routine called by change of the correction factors count"""
logger.info('''change in the correction count detected''')
diff = int(drls['cors'].value() - ((drls['dt'].columnCount() - 1) / 2))
if diff == 0:
return
elif diff > 0:
drls['dt'].setColumnCount(1 + (drls['cors'].value() * 2))
newcors = []
for col in range(drls['dt'].columnCount() - (diff * 2),
drls['dt'].columnCount(), 2):
for row in range(drls['dt'].rowCount()):
drls['dt'].setCellWidget(
row, col, QtWidgets.QComboBox())
drls['dt'].cellWidget(row, col).setFrame(False)
drls['dt'].setItem(
row, col+1, QtWidgets.QTableWidgetItem())
newcors.append(drls['dt'].cellWidget(row, col))
list(map(lambda x: x.currentIndexChanged.connect(lambda:
corr_changed(x, ds, drls, drlspectrum)), newcors))
update_corrfors(drls)
dcolums = ["Name"]
for i in range(drls['cors'].value()):
dcolums.append("corrected for ({})".format(i+1))
dcolums.append("factor ({})".format(i+1))
drls['dt'].setHorizontalHeaderLabels(dcolums)
else:
drls['dt'].setColumnCount(1 + (drls['cors'].value() * 2))
update_drlspectrum(ds, drls, drlspectrum)
def remove_rows(ds, drls, drlspectrum, rows=None):
# TODO: maybe nicer selection in future, but this works for now
logger.info("remowing rows")
if rows == None:
rows = reversed(list(set(
......@@ -243,7 +275,7 @@ def remove_rows(ds, drls, drlspectrum, rows=None):
drls['dt'].removeRow(row)
drls['pt'].removeRow(row)
for i in range(drls['dt'].rowCount()):
for cornum in range(drls['cors']):
for cornum in range(drls['cors'].value()):
corfor = drls['dt'].cellWidget(i, 1+cornum*2)
cors.append(corfor)
corfor.disconnect()
......@@ -258,8 +290,8 @@ def remove_rows(ds, drls, drlspectrum, rows=None):
corfor.setCurrentIndex(index-1)
else:
corfor.setCurrentIndex(index)
list(map(lambda x: x.currentIndexChanged.connect(lambda:
corr_changed(x, ds, drls, drlspectrum)), cors))
list(map(lambda x: x.currentIndexChanged.connect(lambda:
corr_changed(x, ds, drls, drlspectrum)), cors))
def add_line(ds, drls, drlspectrum):
......@@ -294,7 +326,7 @@ def add_line(ds, drls, drlspectrum):
drls['dt'].setItem(newrow, 0, dname)
drls['dt'].setCellWidget(newrow, 0, checkbox)
for i in range(drls['cors']):
for i in range(drls['cors'].value()):
col = copy(1+i*2)
drls['dt'].setCellWidget(newrow, col, QtWidgets.QComboBox())
drls['dt'].cellWidget(newrow, col).setFrame(False)
......@@ -303,11 +335,8 @@ def add_line(ds, drls, drlspectrum):
drls['pt'].blockSignals(False)
drls['dt'].blockSignals(False)
#dirty hack, but if if cycle is applied it assigns all cellWidgets
#to a maximal value of i (as this is the value of i after the end
#of the cycle)
cors = list(map(lambda x: drls['dt'].cellWidget(newrow, 1+x*2),
range(drls['cors'])))
range(drls['cors'].value())))
list(map(lambda x: x.currentIndexChanged.connect(lambda:
corr_changed(x, ds, drls, drlspectrum)), cors))
......@@ -354,7 +383,6 @@ def load_drltables(parent, dataset, drls, drlspectrum):
corrections.append([])
for i in range(1, len(rawdata)):
rawline = rawdata[i].split(",")
# TODO: rawline[4] can be -1 - decide if accept this behaviour
n = len(rawline)
if n < 6 or not n % 2 == 0 or (int(rawline[3]) not in
range(3)) or not (set(map(int, rawline[4:n:2])) &
......@@ -377,6 +405,7 @@ def load_drltables(parent, dataset, drls, drlspectrum):
drls['pt'].item(i, 1).setText(start_masses[i])
drls['pt'].item(i, 2).setText(end_masses[i])
# and after that the daughter table
drls['cors'].setValue(int(1 + (len(names) / 2)))
for i in range(len(names)):
for j in range(int((len(rawline)-4)/2)):
drls['dt'].cellWidget(i, 1+j*2).setCurrentIndex(
......@@ -393,7 +422,7 @@ def save_drlconfig(drls, parent, exp_f_name=None):
"csv", parent)
if exp_f_name is not '':
corlist = []
for i in range(drls['cors']):
for i in range(drls['cors'].value()):
corlist.append("corrected_to_{}, factor_{} ".format(
i+1, i+1))
cortext = ", ".join(corlist)
......@@ -405,7 +434,7 @@ def save_drlconfig(drls, parent, exp_f_name=None):
for i in range(3):
vals.append(drls['pt'].item(row, i).text())
vals.append(drls['dt'].cellWidget(row, 0).checkState())
for i in range(drls['cors']):
for i in range(drls['cors'].value()):
vals.append(drls['dt'].cellWidget(row, 1+i*2).currentIndex())
vals.append(drls['dt'].item(row, 2+i*2).text())
expf.write("{}\n".format((",".join(map(str, vals)))))
......@@ -553,6 +582,7 @@ def key_pressed(event, ds, drls, drlspectrum):
and event.modifiers().__int__() == QtCore.Qt.ControlModifier:
paste_clip(ds, drls, drlspectrum)
def select_all_btn_up(ds, drls, drlspectrum, state=None):
logger.info('''Change of the select-all button detected''')
if state in (0,2):
......@@ -585,11 +615,11 @@ def main_window(parent, ds, filename, cache):
# pt = parenttable
# dt = daughtertable
drls = dict(pt=None, dt=None, tshift=None, cors=3, rel=None,
drls = dict(pt=None, dt=None, tshift=None, cors=None, rel=None,
checkAll=None)
window = QtWidgets.QMainWindow(
parent, windowTitle='Delayed reactant labelling')
parent, windowTitle='Delayed reactant labeling')
main_widget = QtWidgets.QWidget(window)
window.setCentralWidget(main_widget)
......@@ -611,10 +641,9 @@ def main_window(parent, ds, filename, cache):
time_title = QtWidgets.QLabel("Time shift (min):")
drls['tshift'] = QtWidgets.QDoubleSpinBox(
minimum=-100, maximum=1440, decimals=3)
drls['rel'] = QtWidgets.QCheckBox("Steady state approximation")
drls['checkAll'] = QtWidgets.QCheckBox("Select all")
drls['cors'] = QtWidgets.QSpinBox(minimum=0)
drl_load = QtWidgets.QPushButton("&Load")
drl_save = QtWidgets.QPushButton("&Save")
......@@ -628,7 +657,8 @@ def main_window(parent, ds, filename, cache):
if cache == [None, None]:
dcolums = ["Name"]
for i in range(drls['cors']):
drls['cors'].setValue(3)
for i in range(drls['cors'].value()):
dcolums.append("corrected for ({})".format(i+1))
dcolums.append("factor ({})".format(i+1))
drls['dt'] = iontable(dcolums)
......@@ -661,16 +691,14 @@ def main_window(parent, ds, filename, cache):
drls['pt'].itemChanged.connect(lambda item: ptable_changed(
item.row(), item.column(), ds, drls, chromplot))
drls['dt'].itemChanged.connect(lambda item: dtable_changed(
item.row(), item.column(), ds, drls, chromplot))
drls['tshift'].valueChanged.connect(lambda: update_drlspectrum(
ds, drls, chromplot))
drls['cors'].valueChanged.connect(lambda: corcount_changed(
ds, drls, chromplot))
drls['rel'].stateChanged.connect(lambda: update_drlspectrum(
ds, drls, chromplot))
drls['checkAll'].stateChanged.connect(lambda state:
select_all_btn_up(ds, drls, chromplot, state))
......@@ -683,10 +711,7 @@ def main_window(parent, ds, filename, cache):
actionBar.addWidget(drl_load)
actionBar.addWidget(drl_save)
actionBar.addWidget(drl_print)
stretchWidget = QtWidgets.QWidget()
stretchWidget.setSizePolicy(QtWidgets.QSizePolicy.Expanding
,QtWidgets.QSizePolicy.Preferred)
actionBar.addWidget(stretchWidget)
actionBar.addWidget(StretchWidget())
actionBar.addWidget(drl_export)
actionBar.addWidget(close)
......@@ -694,8 +719,15 @@ def main_window(parent, ds, filename, cache):
dtdock.setWidget(QtWidgets.QWidget())
dtdock_layout = QtWidgets.QVBoxLayout(dtdock.widget())
dtdock.setWindowTitle("Corrected ions table")
dtdock_layout.addWidget(drls['checkAll'])
dt_butlayout = QtWidgets.QHBoxLayout()
dt_butlayout.addWidget(drls['checkAll'])
dt_butlayout.addWidget(StretchWidget())
dt_butlayout.addWidget(QtWidgets.QLabel("Number of corrections:"))
dt_butlayout.addWidget(drls['cors'])
dt_butlayout.addWidget(StretchWidget())
dtdock_layout.addLayout(dt_butlayout)
dtdock_layout.addWidget(drls['dt'])
window.addDockWidget(QtCore.Qt.BottomDockWidgetArea, dtdock)
ptdock = QtWidgets.QDockWidget()
ptdock.setWidget(QtWidgets.QWidget())
......@@ -707,8 +739,6 @@ def main_window(parent, ds, filename, cache):
pt_butlayout.addWidget(btn_rem)
pt_butlayout.addStretch(0)
ptdock_layout.addLayout(pt_butlayout)
window.addDockWidget(QtCore.Qt.BottomDockWidgetArea, dtdock)
window.addDockWidget(QtCore.Qt.RightDockWidgetArea, ptdock)
main_layout = QtWidgets.QVBoxLayout(main_widget)
......
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