Commit 2194b3b7 authored by Yan's avatar Yan
Browse files

tofTools - pt3 - working visualization

* export still missing
parent d2cf80a3
......@@ -40,7 +40,10 @@ def settings():
("reactivity/index", 0),
("reactivity/activetab", 0),
("recents", ""),
("timstof/sampling", 500)}
("timstof/ms_sampling", 500),
("timstof/ms_bins", 0.001),
("timstof/mob_sampling", 5000),
("timstof/mob_bins", 0.0001)}
[settings.setValue(*i)
for i in defvals if not settings.contains(i[0])]
return settings
......@@ -139,7 +142,13 @@ def dial(parent):
timstoftab = QtWidgets.QWidget()
timstoflayout = QtWidgets.QVBoxLayout(timstoftab)
timstoflayout.addLayout(posvarconf(
"Maximum number of samples", "timstof/sampling", config))
"Maximum number of samples - MS", "timstof/ms_sampling", config))
timstoflayout.addLayout(posvarconf(
"Bins - MS", "timstof/ms_bins", config, "nonint"))
timstoflayout.addLayout(posvarconf(
"Maximum number of samples - mobility", "timstof/mob_sampling", config))
timstoflayout.addLayout(posvarconf(
"Bins - mobility", "timstof/mob_bins", config, "nonint"))
tabs.addTab(timstoftab, "timsTOF")
......
......@@ -15,6 +15,7 @@ import pathlib
import prasopes.config as cf
import prasopes.datatools as dt
logger = logging.getLogger('dsLogger')
class Dataset():
......@@ -135,6 +136,23 @@ class BrukerTimsDataset(Dataset):
self.mintime, self.maxtime = [self.chromatograms[i][0][i]
for i in (0,-1)]
def sampletimes(self, mint, maxt, timescap):
frames = dt.argsubselect(self.dataset.retention_times,
mint*60, maxt*60) + 1
framessel = frames if timescap >= len(frames) else np.linspace(
frames[0], frames[-1], timescap).astype('int')
return framessel
def binit(self, x, y, minstep, length):
sortx = np.sort(x)
stepsx = sortx[1:] - sortx[:-1]
binspos = np.where(stepsx > minstep)[0]
bins = sortx[:-1][binspos] + (stepsx[binspos]/2)
binpos = np.digitize(x, bins)
bindx = np.bincount(binpos, x) / np.bincount(binpos)
bindy = np.bincount(binpos, y) / length
return bindx, bindy
def get_chromatograms(self):
logger.info("getting timsTOF chromatogram")
keys = ('retention_time', 'intensity')
......@@ -149,20 +167,12 @@ class BrukerTimsDataset(Dataset):
logger.info("getting timsTOF spectra")
mint = mint or self.mintime
maxt = maxt or self.maxtime
#TODO: set in config
frames = dt.argsubselect(self.dataset.retention_times,
mint*60, maxt*60) + 1
timescap = cf.settings().value("timstof/sampling", type=int)
framessel = frames if timescap >= len(frames) else np.linspace(
frames[0], frames[-1], timescap).astype('int')
framessel = self.sampletimes(mint, maxt,
cf.settings().value("timstof/ms_sampling", type=int))
massints = self.dataset.query(framessel, columns=('mz', 'intensity'))
sortmasses = np.sort(massints['mz'])
masssteps = sortmasses[1:] - sortmasses[:-1]
binspos = np.where(masssteps > 0.001)[0]
bins = sortmasses[:-1][binspos] + (masssteps[binspos]/2)
binpos = np.digitize(massints['mz'], bins)
masses = np.bincount(binpos, massints['mz']) / np.bincount(binpos)
ints = np.bincount(binpos, massints['intensity']) / len(framessel)
masses, ints = self.binit(
massints['mz'], massints['intensity'],
cf.settings().value("timstof/ms_bins", type=float), len(framessel))
return [[masses, ints]]
def get_peakchrom(self, startm, endm):
......@@ -173,3 +183,19 @@ class BrukerTimsDataset(Dataset):
self.dataset.ms1_frames, columns=('intensity','mz'))],
np.clip(self.chromatograms[0][1], np.finfo(np.float32).eps, None))
return intensity
def get_mobilogram(self, startm, endm, mint=None, maxt=None):
logger.info("getting timsTOF mobilogram")
mint = mint or self.mintime
maxt = maxt or self.maxtime
framessel = self.sampletimes(mint, maxt,
cf.settings().value("timstof/mob_sampling", type=int))
massintstof = self.dataset.query(
framessel, columns=('mz', 'intensity', 'inv_ion_mobility'))
goodargs = dt.argsubselect(massintstof['mz'], startm, endm)
mobs, ints = self.binit(
massintstof['inv_ion_mobility'][goodargs],
massintstof['intensity'][goodargs],
cf.settings().value("timstof/mob_bins", type=float),
len(framessel))
return mobs, ints
......@@ -58,9 +58,30 @@ def update_profile(table, row, dataset):
def ionstable_changed(row, col, ds, table):
if col in (1,2,3,4):
update_profile(table, row, ds)
def pop_dial(augCanvas, dialspect, ionstable):
table.blockSignals(True)
table.item(row, 0).setBackground(QtGui.QBrush(
QtGui.QColor(*gt.colors[row % len(gt.colors)], alpha=50)))
table.blockSignals(False)
def pop_dial(augCanvas, dialspect, ionstable, labels):
ds = augCanvas.ds
dialspect.clear()
gt.pop_plot([], [], dialspect, labels)
for row in range(ionstable.rowCount()):
name = ionstable.item(row, 0).text()
startm = drl.floatize(ionstable, row, 3)\
- (drl.floatize(ionstable, row, 4) / 2)
endm = drl.floatize(ionstable, row, 3)\
+ (drl.floatize(ionstable, row, 4) / 2)
[tstart, tend] = [drl.floatize(ionstable, row, i) for i in (1,2)]
spectrum = ds.get_mobilogram(startm, endm, tstart, tend)
dialspect.plot(spectrum[0], spectrum[1], label=name,
color=(gt.colors[row % len(gt.colors)] / 255))
if ionstable.rowCount():
dialspect.autoscale(True)
dialspect.legend(loc=2)
dialspect.figure.canvas.draw()
return
......@@ -114,7 +135,7 @@ def main_window(parent, augCanvas, update_signal):
QtWidgets.QDialog.closeEvent(widget, event)
def update_fnc():
pop_dial(augCanvas, dialspect, ionstable)
pop_dial(augCanvas, dialspect, ionstable, reactlabels)
dial_widget = QtWidgets.QDialog(
parent, windowTitle='Mobilogram')
......
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