Commit 1f461fe4 authored by Yan's avatar Yan
Browse files

Fixed Drltools (at least partly)

* not tested everything in DRLtools, but core seems working.
parent 69d9975c
......@@ -45,6 +45,10 @@ class Dataset():
"""implement per-case"""
raise NotImplementedError
def get_peakchrom(self, masstart, massend):
"""implement per-case"""
raise NotImplementedError
def get_spectra(self, mint=None, maxt=None):
mint = mint or self.mintime
maxt = maxt or self.maxtime
......@@ -105,6 +109,13 @@ class ThermoRawDataset(Dataset):
spectra.append([[],[]])
return spectra
def get_peakchrom(self, masstart, massend):
intensity = np.concatenate([np.divide(np.sum(subset[2].T[
dt.argsubselect(subset[1], startm, endm)].T, axis=1),
np.clip(subset[0][1], np.finfo(np.float32).eps, None))
for subset in self.dataset])
return intensity
class BrukerTimsDataset(Dataset):
def __init__(self, rawfile):
......@@ -141,3 +152,11 @@ class BrukerTimsDataset(Dataset):
masses = np.bincount(binpos, massints['mz']) / np.bincount(binpos)
ints = np.bincount(binpos, massints['intensity']) / self.dataset.max_frame
return [[masses, ints]]
def get_peakchrom(self, startm, endm):
intensity = np.divide([
np.sum(i['intensity'][dt.argsubselect(i['mz'], startm, endm)])
for i in self.dataset.query_iter(
self.dataset.ms1_frames, columns=('intensity','mz'))],
np.clip(self.chromatograms[0][1], np.finfo(np.float32).eps, None))
return intensity
......@@ -33,19 +33,18 @@ def floatize(table, row, column, nonneg=True):
return outfloat
def get_massargs(pt, row, subset):
def get_massargs(pt, row, masses):
startm = floatize(pt, row, 1) - (floatize(pt, row, 2) / 2)
endm = floatize(pt, row, 1) + (floatize(pt, row, 2) / 2)
massargs = dt.argsubselect(subset['masses'], startm, endm)
massargs = dt.argsubselect(masses, startm, endm)
return massargs
def get_intensity(row, ds, drls):
# prevent division by 0
intensity = np.concatenate([np.divide(np.sum(subset['matrix'].T[
get_massargs(drls['pt'], row, subset)].T, axis=1),
np.clip(subset['chrom_dat'][1], np.finfo(np.float32).eps, None))
for subset in ds])
startm = floatize(drls['pt'], row, 1) - (floatize(drls['pt'], row, 2) / 2)
endm = floatize(drls['pt'], row, 1) + (floatize(drls['pt'], row, 2) / 2)
intensity = ds.get_peakchrom(startm, endm)
return intensity
......@@ -53,8 +52,8 @@ def get_daughterset(ds, drls):
"""Fuction to acquire the curves of the daugher ions"""
logger.info("getting set of the daughter ions")
names = []
times = np.concatenate([sub['chrom_dat'][0, :] - drls['tshift'].value()
for sub in ds])
times = np.concatenate([sub[0] - drls['tshift'].value()
for sub in ds.chromatograms])
intensities = []
for row in range(drls['dt'].rowCount()):
if drls['dt'].cellWidget(row, 0).checkState() == 2:
......
......@@ -36,19 +36,19 @@ def update_profile(pt, row, dataset):
"""parent table profile spectrum updating procedure"""
logger.debug("updating parent table row {} profile".format(row))
# Dont do anything to graph when the spectrum is not populated
if len(dataset) == 0:
if not dataset:
return
spectrum = pt.cellWidget(row, 3).figure.get_axes()[0]
spectrum.clear()
limits = []
for i, subset in enumerate(dataset):
masses = subset['masses']
massargs = drl.get_massargs(pt, row, subset)
yshape = np.mean(subset['matrix'], axis=0)
spectrum.plot(masses, yshape, ':', color='gray')
spectrum.plot(masses[massargs], yshape[massargs], color=gt.colors[
i % len(gt.colors)]/255)
limits.append((masses[massargs[[0, -1]]], max(yshape[massargs])))
spectra = dataset.get_spectra(-np.inf, np.inf)
for i,spectxy in enumerate(spectra):
massargs = drl.get_massargs(pt, row, spectxy[0])
spectrum.plot(spectxy[0], spectxy[1], ':', color='gray')
spectrum.plot(spectxy[0][massargs], spectxy[1][massargs],
color=gt.colors[i % len(gt.colors)]/255)
limits.append((spectxy[0][massargs[[0, -1]]],
max(spectxy[1][massargs])))
widest = np.argmax([abs(lim[0][1]-lim[0][0]) for lim in limits])
xmin, xmax = limits[widest][0]
xex = max((xmax-xmin)*0.25, 0.20)
......@@ -62,7 +62,7 @@ def update_drlspectrum(ds, drls, drlspectrum):
"""Generic DRL spectrum updating procedure"""
logger.info("updating DRL spectrum")
# Do not do anything when the data set is not populated.
if len(ds) == 0:
if not ds:
return
names, times, intensities = drl.get_daughterset(ds, drls)
......@@ -353,8 +353,8 @@ def save_drlconfig(drls, parent, exp_f_name=None):
expf.close()
def export_drlspectrum(parent, fn, ds, drls):
if fn[0] is None:
def export_drlspectrum(parent, ds, drls):
if not ds:
QtWidgets.QMessageBox.warning(
None, "Export DRL dat aset",
"No file opened. Nothing to export, canceling request")
......@@ -378,7 +378,7 @@ def export_drlspectrum(parent, fn, ds, drls):
None, "Export DRL data", options=(
QtWidgets.QFileDialog.DontConfirmOverwrite |
QtWidgets.QFileDialog.HideNameFilterDetails),
directory=fn[0][:-4])[0]
directory=ds.filename[0][:-4])[0]
if fname == '':
return
exp_f_name = list(map(lambda x: "{}/{}-{}.csv".format(
......@@ -543,7 +543,6 @@ def select_all_btn_up(ds, drls, drlspectrum, state=None):
def main_window(parent, augCanvas, update_signal):
"""constructs a dialog window"""
ds = augCanvas.ds
filename = augCanvas.ds.filename
cache = augCanvas.drlcache
def onclose(widget, event, buffer, drls,
......@@ -638,7 +637,7 @@ def main_window(parent, augCanvas, update_signal):
drls, main_widget))
drl_print.clicked.connect(lambda: print_graph(ds, drls))
drl_export.clicked.connect(lambda: export_drlspectrum(
main_widget, filename, ds, drls))
main_widget, ds, drls))
drl_reactivity.clicked.connect(lambda: rt.main_window(parent,
augCanvas, update_signal, drls))
......
Markdown is supported
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