Commit 419704a2 authored by 3Yan's avatar 3Yan
Browse files

DRL evolution - pt1

* multiple corrections pt1
* steady state aproximation
* time shift
parent c5403c9d
......@@ -73,20 +73,24 @@ def get_daughterset(ds, drls):
names = []
times = ds['chrom_dat'][0, :] - drls['tshift'].value()
intensities = []
# TODO: resolve intensities trouble
for row in range(drls['dt'].rowCount()):
if drls['dt'].cellWidget(row, 0).checkState() == 2:
intensity = get_intensity(row, ds, drls)
cor = drls['dt'].cellWidget(row, 1).currentIndex() - 1
if cor not in (-2, -1):
factor = floatize(drls['dt'], row, 2)
correction = get_intensity(cor, ds, drls) * factor
intensity = intensity - correction
corlist = []
for i in range(drls['cors']):
cor = drls['dt'].cellWidget(row, 1+i*2).currentIndex() - 1
if cor not in (-2, -1):
factor = floatize(drls['dt'], row, 2+i*2)
correction = get_intensity(cor, ds, drls) * factor
intensity = intensity - correction
corlist.append("{} * {}".format(
drls['dt'].item(row,2+i*2).text(),
drls['dt'].cellWidget(row,1+i*2).currentText()))
cortext = " + ".join(corlist)
intensities.append(intensity)
names.append("{} - {} * {}".format(
names.append("{} - ({})".format(
drls['dt'].item(row, 0).text(),
drls['dt'].item(row,2).text(),
drls['dt'].cellWidget(row,1).currentText()))
cortext))
return names, times, intensities
......@@ -124,8 +128,7 @@ def update_drlspectrum(ds, drls, drlspectrum):
for i in range(len(drlspectrum.lines)):
drlspectrum.lines[0].remove()
drlspectrum.axvline(
drls['tshift'].value(), color="#FF000088", linestyle=":")
drlspectrum.axvline(0, color="#FF000088", linestyle=":")
i = 0
for row in range(drls['dt'].rowCount()):
......@@ -135,15 +138,20 @@ def update_drlspectrum(ds, drls, drlspectrum):
QtGui.QColor(*colors[row % len(colors)], alpha=50)))
drls['dt'].blockSignals(False)
label = " {}".format(drls['pt'].item(row, 0).text())
drlspectrum.plot(times, intensities[i], label=label,
intensity = intensities[i]
if drls['rel'].checkState() == 2:
intensity = intensity / np.sum(intensities, 0)
drlspectrum.plot(times, intensity, label=label,
color=(colors[row % len(colors)] / 255))
i += 1
else:
drls['dt'].item(row, 0).setBackground(QtGui.QBrush())
if len(names) != 0:
drlspectrum.set_ylim(top=np.amax(intensities)*1.1,
bottom=np.amax(intensities)*-0.01)
gmax = np.amax(intensities)
if drls['rel'].checkState() == 2:
gmax = 1
drlspectrum.set_ylim(top=gmax*1.1, bottom=gmax*-0.01)
drlspectrum.legend(loc=2)
drlspectrum.figure.canvas.draw()
......@@ -167,14 +175,15 @@ def update_corrfors(drls):
"""update corrections selection layout of the daughter table"""
ionlist = gettableitemlist(drls['pt'])
for row in range(drls['dt'].rowCount()):
corfor = drls['dt'].cellWidget(row, 1)
index = corfor.currentIndex()
corfor.blockSignals(True)
corfor.clear()
corfor.addItem("")
corfor.addItems(ionlist)
corfor.setCurrentIndex(index)
corfor.blockSignals(False)
for i in range(drls['cors']):
corfor = drls['dt'].cellWidget(row, 1+i*2)
index = corfor.currentIndex()
corfor.blockSignals(True)
corfor.clear()
corfor.addItem("")
corfor.addItems(ionlist)
corfor.setCurrentIndex(index)
corfor.blockSignals(False)
def ptable_changed(row, column, ds, drls, drlspectrum):
......@@ -187,6 +196,7 @@ def ptable_changed(row, column, ds, drls, drlspectrum):
def dtable_changed(row, column, ds, drls, drlspectrum):
"""routine called by change of the dtable spectra"""
#TODO: multiple corrections not incorporated!!!
if drls['dt'].cellWidget(row, 0).checkState() == 2:
if (column == 0)\
or (column == 2
......@@ -196,6 +206,7 @@ def dtable_changed(row, column, ds, drls, drlspectrum):
def corr_changed(row, ds, drls, drlspectrum):
"""routine called by change of correction for ion"""
#TODO: multiple corrections not incorporated!!!
if (drls['dt'].cellWidget(row, 0).checkState() == 2
and floatize(drls['dt'], row, 2) != 0):
update_drlspectrum(ds, drls, drlspectrum)
......@@ -211,21 +222,22 @@ def remove_rows(ds, drls, drlspectrum, rows=None):
drls['dt'].removeRow(row)
drls['pt'].removeRow(row)
for i in range(drls['dt'].rowCount()):
corfor = drls['dt'].cellWidget(i, 1)
corfor.disconnect()
index = corfor.currentIndex()
corfor.clear()
corfor.addItem("")
corfor.addItems(gettableitemlist(drls['pt']))
if index == row+1:
corfor.setCurrentIndex(0)
corr_changed(i, ds, drls, drlspectrum)
elif index > row+1:
corfor.setCurrentIndex(index-1)
else:
corfor.setCurrentIndex(index)
corfor.currentIndexChanged.connect(lambda:
corr_changed(i, ds, drls, drlspectrum))
for cornum in range(drls['cors']):
corfor = drls['dt'].cellWidget(i, 1+cornum*2)
corfor.disconnect()
index = corfor.currentIndex()
corfor.clear()
corfor.addItem("")
corfor.addItems(gettableitemlist(drls['pt']))
if index == row+1:
corfor.setCurrentIndex(0)
corr_changed(i, ds, drls, drlspectrum)
elif index > row+1:
corfor.setCurrentIndex(index-1)
else:
corfor.setCurrentIndex(index)
corfor.currentIndexChanged.connect(lambda:
corr_changed(i, ds, drls, drlspectrum))
def add_line(ds, drls, drlspectrum):
......@@ -258,11 +270,15 @@ def add_line(ds, drls, drlspectrum):
dname.setTextAlignment(QtCore.Qt.AlignRight)
drls['dt'].setItem(newrow, 0, dname)
drls['dt'].setCellWidget(newrow, 0, checkbox)
corfor = QtWidgets.QComboBox()
corfor.setFocusProxy(drls['dt'])
corfor.setFrame(False)
drls['dt'].setCellWidget(newrow, 1, corfor)
drls['dt'].setItem(newrow, 2, QtWidgets.QTableWidgetItem())
for i in range(drls['cors']):
corfor = QtWidgets.QComboBox()
corfor.setFocusProxy(drls['dt'])
corfor.setFrame(False)
drls['dt'].setCellWidget(newrow, 1+i*2, corfor)
drls['dt'].setItem(newrow, 2+i*2, QtWidgets.QTableWidgetItem())
corfor.currentIndexChanged.connect(lambda: corr_changed(
newrow, ds, drls, drlspectrum))
drls['pt'].blockSignals(False)
drls['dt'].blockSignals(False)
......@@ -271,8 +287,6 @@ def add_line(ds, drls, drlspectrum):
checkbox.stateChanged.connect(lambda: update_drlspectrum(
ds, drls, drlspectrum))
corfor.currentIndexChanged.connect(lambda: corr_changed(
newrow, ds, drls, drlspectrum))
def iontable(labels):
......@@ -303,12 +317,14 @@ def load_drltables(parent, dataset, drls, drlspectrum):
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(",")
# TODO: rawline[4] can be -1 - decide if accept this behaviour
if len(rawline) != 6 or int(rawline[3]) not in range(3) \
# TODO: not checking if multiple corrections are sane
if len(rawline) < 6 or int(rawline[3]) not in range(3) \
or int(rawline[4]) not in range(-1,len(rawdata)):
QtWidgets.QMessageBox.warning(
parent, "Load DRL config tables",
......@@ -329,9 +345,10 @@ def load_drltables(parent, dataset, drls, drlspectrum):
drls['pt'].item(i, 2).setText(end_masses[i])
# and after that the daughter table
for i in range(len(names)):
drls['dt'].cellWidget(i, 1).setCurrentIndex(
int(corrected_to[i]))
drls['dt'].item(i, 2).setText(corr_factors[i])
for j in range((len(names)-1)/2):
drls['dt'].cellWidget(i, 1+j*2).setCurrentIndex(
int(corrected_to[i]))
drls['dt'].item(i, 2+j*2).setText(corr_factors[i])
drls['dt'].cellWidget(i, 0).setCheckState(int(states[i]))
......@@ -342,16 +359,22 @@ def save_drlconfig(drls, parent, exp_f_name=None):
"Save DRL table layout", "comma-separated values (*.csv)",
"csv", parent)
if exp_f_name is not '':
corlist = []
for i in range(drls['cors']):
corlist.append("corrected_to_{}, factor_{} ".format(
i+1, i+1))
cortext = ", ".join(corlist)
expf = open(exp_f_name, 'w')
expf.write("#ion_name, start m/z, end m/z, visible,"
"corrected_to, factor\n")
"{}\n".format(cortext))
for row in range(drls['pt'].rowCount()):
vals = []
for i in range(3):
vals.append(drls['pt'].item(row, i).text())
vals.append(drls['dt'].cellWidget(row, 0).checkState())
vals.append(drls['dt'].cellWidget(row, 1).currentIndex())
vals.append(drls['dt'].item(row, 2).text())
for i in range(drls['cors']):
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)))))
expf.close()
......@@ -453,7 +476,7 @@ def clip_range(drls):
QtWidgets.QApplication.clipboard().setText(("\n").join(rows))
def paste_clip(drls, ds, drlspectrum):
def paste_clip(ds, drls, drlspectrum):
activeObject = QtWidgets.QApplication.focusWidget()
if activeObject in (drls['pt'], drls['dt'])\
and activeObject.selectedRanges() != []:
......@@ -504,7 +527,7 @@ def main_window(parent, ds, filename, cache):
# pt = parenttable
# dt = daughtertable
drls = dict(pt=None, dt=None, tshift=None)
drls = dict(pt=None, dt=None, tshift=None, cors=3, rel=None)
window = QtWidgets.QMainWindow(
parent, windowTitle='Delayed reactant labelling')
......@@ -530,6 +553,8 @@ def main_window(parent, ds, filename, cache):
drls['tshift'] = QtWidgets.QDoubleSpinBox(
minimum=-100, maximum=1440, decimals=3)
drls['rel'] = QtWidgets.QCheckBox("Steady state approximation")
drl_load = QtWidgets.QPushButton("&Load")
drl_save = QtWidgets.QPushButton("&Save")
drl_export = QtWidgets.QPushButton("&Export")
......@@ -541,10 +566,17 @@ def main_window(parent, ds, filename, cache):
btn_rem = QtWidgets.QPushButton("Remove")
if cache == [None, None]:
drls['dt'] = iontable(["Name", "corrected for", "factor"])
dcolums = ["Name"]
for i in range(drls['cors']):
dcolums.append("corrected for ({})".format(i+1))
dcolums.append("factor ({})".format(i+1))
drls['dt'] = iontable(dcolums)
drls['pt'] = iontable(["Name", "start (m/z)", "end (m/z)",
"profile"])
#TODO: DIRTY, DIRTY, DIRTY !!! do it nicer when I'll know how i want it
for n in range(drls['dt'].columnCount()):
drls['dt'].horizontalHeader().setSectionResizeMode(
n, QtWidgets.QHeaderView.Interactive)
add_line(ds, drls, chromplot)
else:
drls = cache[0]
......@@ -575,6 +607,9 @@ def main_window(parent, ds, filename, cache):
drls['tshift'].valueChanged.connect(lambda: update_drlspectrum(
ds, drls, chromplot))
drls['rel'].stateChanged.connect(lambda: update_drlspectrum(
ds, drls, chromplot))
main_layout = QtWidgets.QVBoxLayout(main_widget)
sub_layout = QtWidgets.QHBoxLayout()
graph_layout = QtWidgets.QVBoxLayout()
......@@ -605,6 +640,8 @@ def main_window(parent, ds, filename, cache):
graphparams_layout.addWidget(time_title)
graphparams_layout.addWidget(drls['tshift'])
graphparams_layout.addStretch(1)
graphparams_layout.addWidget(drls['rel'])
graphparams_layout.addStretch(1)
tablelayout.addWidget(QtWidgets.QLabel("Raw ions table:"))
tablelayout.addWidget(drls['pt'])
......
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