Commit 2f51375a authored by Yan's avatar Yan
Browse files

Parameters log pt1

* Experimental parameters support for TSQ, without time subselection
* fixed file loading exception handling
parent 2b21c210
......@@ -59,38 +59,42 @@ def load_file(parent, chrom_plot, spc, d_set, ms_s, fn, chrom_s,
filter="Finnigan RAW files (*.raw, *.RAW)")[0]
if filename is not '' and os.path.isfile(filename)\
and not os.path.isdir(filename):
error = update_signal()
errormsg = []
def runfnc():
try:
d_set.clear()
chrom_s['timesarg'].clear()
[i.clear() for i in (
d_set, chrom_s['timesarg'], ms_s['params'],ms_s['headers'])]
[d_set.append(dict(chrom_dat=i[0], masses=i[1], matrix=i[2]))
for i in load_raw(filename, settings.value("tmp_location"))]
except rawprasslib.ParsingException as pex:
QtWidgets.QMessageBox.critical(
parent, "Opening of the file has failed!",
errormsg.append("Opening of the file has failed!")
errormsg.append(
"File is incompatible with the rawprasslib, "
"canceling request!\n\n"
"Error message:\n{}".format(pex.args[0]))
error.signal.emit()
return
[i.clear() for i in (ms_s['params'],ms_s['headers'])]
if autoparams == True:
try:
ms_s['params'], rawheaders = load_params(filename)
segments = [len(subset['chrom_dat'][0]) for subset in d_set]
indicies = [sum(segments[:i+1]) for i in
range(len(segments))]
indicies = [sum(segments[:i+1]) for i in range(len(segments))]
ms_s['headers'] = np.split(rawheaders, indicies)[:-1]
except Exception as pex:
QtWidgets.QMessageBox.critical(
parent, "Parameters readout has failed!",
"File is incompatible with the rawautoparams, "
"no parameters loaded!\n\n"
"Error message:\n{}".format(pex.args[0]))
errormsg.append("File is incompatible with the rawautoparams,")
errormsg.append(
"no parameters loaded!\n\n"
"Error message:\n{}".format(pex.args[0]))
error.signal.emit()
print("panoc baby")
gt.populate(chrom_plot, spc, d_set, ms_s, chrom_s)
fn[0] = filename
parent.setWindowTitle("Prasopes - {}".format(
os.path.basename(filename)))
update.signal.emit()
error.signal.connect(lambda:
QtWidgets.QMessageBox.critical(parent, errormsg[0], errormsg[1]))
loadthread.run = runfnc
loadthread.start()
......@@ -125,6 +129,28 @@ def update_spectrum(chromatogram, spect, ds, ms, fn, chrom, config):
spect.get_figure().canvas.draw()
def update_paramstable(table, ms, chrom):
if len(ms['params']) == 0:
table.setRowCount(0)
return
table.setRowCount(len(ms['params'][0]))
validator = QtGui.QDoubleValidator()
for row, paramname in enumerate(ms['params'][0]):
[table.setItem(row,col, QtWidgets.QTableWidgetItem())
for col in range(2)]
table.item(row,0).setText(paramname)
vals = [param[row] for param in ms['params'][1]]
if all([type(val) in [np.float32, np.float64] for val in vals]):
aver = np.average(vals)
minim = min(vals)
maxim = max(vals)
text = "{:.2f} (from {:.2f} to {:.2f})".format(aver, minim, maxim)
else:
values = [str(i) for i in np.unique(np.array(vals), axis=0)]
text = " or ".join(values)
table.item(row,1).setText(text)
def dropped(event, parent, chromatogram, spectrum, ds, ms, filename,
chrom, update, config, loadthread):
dropurl = event.mimeData().urls()[0].toLocalFile()
......@@ -353,6 +379,11 @@ def main():
toolBar.addSeparator()
toolBar.addAction(autozoomy)
paramsdock = QtWidgets.QDockWidget()
paramstable = dt.table(["name","value"], 100)
update.signal.connect(lambda: update_paramstable(paramstable, ms, chrom))
paramsdock.setWidget(paramstable)
fileModel = QtWidgets.QFileSystemModel()
fileModel.setRootPath('')
activeDir = fileModel.index(config.value("open_folder"))
......@@ -363,14 +394,12 @@ def main():
dirview = QtWidgets.QListView()
dirview.setModel(fileModel)
treedock = QtWidgets.QDockWidget()
def scrolltoonce():
fileModel.directoryLoaded.disconnect(scrolltoonce)
treeview.scrollTo(fileModel.index(config.value("open_folder")), 1)
fileModel.directoryLoaded.connect(scrolltoonce)
fileModel.directoryLoaded.connect(
lambda: treeview.resizeColumnToContents(0))
if not config.value("view/filebrowservisible",type=bool):
treedock.hide()
treedock.setWidget(QtWidgets.QWidget())
......@@ -386,20 +415,19 @@ def main():
update, config, loadthread, filename=fileModel.filePath(index))
for i in [treeview.doubleClicked, dirview.doubleClicked, dirview.clicked]:
i.connect(clickload)
#fileModel gots stuck sometimes, better give it a separate thread
#it complains at the start, but still works later
#and I did not found better solution
treedockThread = QtCore.QThread()
treedockThread.start()
fileModel.moveToThread(treedockThread)
def closeOverride(event, dock, action):
action.setChecked(False)
dock.hide()
event.ignore()
treedock.closeEvent = lambda event: closeOverride(
event, treedock, filebrowseract)
main_window.closeEvent = lambda event: treedockThread.quit()
main_window.dragEnterEvent = lambda event: drag_entered(event)
main_window.dropEvent = lambda event: dropped(
......@@ -411,6 +439,7 @@ def main():
main_window.addToolBar(QtCore.Qt.TopToolBarArea, toolBar)
main_window.addDockWidget(QtCore.Qt.LeftDockWidgetArea, treedock)
main_window.addDockWidget(QtCore.Qt.RightDockWidgetArea, paramsdock)
main_window.setStatusBar(barHandler.statusBar)
main_window.setFocus()
......
from PyQt5 import QtWidgets
from PyQt5 import QtCore
import numpy as np
import os.path
......@@ -37,3 +38,19 @@ def specttostr(spectrum, chrom_ds, fn, delim=" "):
def clip_spectstr(spectrum, chrom_ds, fn):
string = specttostr(spectrum, chrom_ds, fn, delim="\t")
QtWidgets.QApplication.clipboard().setText(string)
def table(labels, minsizex=600, minsizey=0):
"""creates a reasonable table"""
table = QtWidgets.QTableWidget(columnCount=len(labels))
table.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
QtWidgets.QSizePolicy.Expanding)
table.setHorizontalHeaderLabels(labels)
table.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
for n in range(table.columnCount()):
table.horizontalHeader().setSectionResizeMode(
n, QtWidgets.QHeaderView.Stretch)
table.setMinimumSize(minsizex, minsizey)
return table
......@@ -367,22 +367,6 @@ def add_line(ds, drls, drlspectrum):
ds, drls, drlspectrum))
def iontable(labels):
"""creates a table for ions"""
table = QtWidgets.QTableWidget(columnCount=len(labels))
table.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
QtWidgets.QSizePolicy.Expanding)
table.setHorizontalHeaderLabels(labels)
table.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
for n in range(table.columnCount()):
table.horizontalHeader().setSectionResizeMode(
n, QtWidgets.QHeaderView.Stretch)
table.setMinimumSize(600, 0)
return table
def load_drltables(parent, dataset, drls, drlspectrum):
filename = QtWidgets.QFileDialog.getOpenFileName(
caption="Load DRL config tables",
......@@ -680,8 +664,8 @@ def main_window(parent, ds, filename, cache, update_signal):
for i in range(drls['cors'].value()):
dcolums.append("corrected for ({})".format(i+1))
dcolums.append("factor ({})".format(i+1))
drls['dt'] = iontable(dcolums)
drls['pt'] = iontable(["Name", "Mass (m/z)", "Peak width",
drls['dt'] = dt.table(dcolums)
drls['pt'] = dt.table(["Name", "Mass (m/z)", "Peak width",
"profile"])
#TODO: DIRTY, DIRTY, DIRTY !!! do it nicer when I'll know how i want it
[drls['dt'].horizontalHeader().setSectionResizeMode(
......
......@@ -26,7 +26,7 @@ setup(
'PyQt5;platform_system=="Darwin"',
'PyQt5-sip;platform_system=="Darwin"',
'matplotlib>=3.0.0',
'rawprasslib'],
'rawprasslib>=0.0.4'],
entry_points={
'console_scripts': [
'prasopes = prasopes.__main__:main'
......
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