Commit b5d06662 authored by Yan's avatar Yan
Browse files

Support for timsTOF - pt2

* fixed selection of times
* fixed complex spectra
* odd/even support better (still not fixed completely)
* lost of things still broken
parent 3566136f
......@@ -23,6 +23,17 @@ class Dataset():
self.timemin = -np.inf
self.timemax = np.inf
def get_chromargs(self):
times = dt.argsubselect(np.concatenate(
[subset[0] for subset in self.chromatograms]),
self.timemin, self.timemax)
args = []
for subset in self.chromatograms:
goodtimes = np.where((times < len(subset[0])) & ~(times < 0))[0]
args.append(times[goodtimes])
times -= len(subset[0])
return args
def refresh(self):
"""implement per-case"""
return None
......@@ -71,24 +82,22 @@ class ThermoRawDataset(Dataset):
return chroms
def get_spectra(self):
times = dt.argsubselect(np.concatenate(
[subset[0][0] for subset in self.dataset]),
self.timemin, self.timemax)
args = []
for subset in self.dataset:
goodtimes = np.where((times < len(subset[0][0]))
& ~(times < 0))[0]
args.append(times[goodtimes])
times =- len(subset[0][0])
spectra = []
for i,subset in enumerate(self.dataset):
if cf.settings().value("view/oddeven", type=bool):
for j in (0,1):
yvalz = np.mean(subset[2][args[i][j::2]], axis=0)
args = self.get_chromargs()
spectra = []
for i,subset in enumerate(self.dataset):
if cf.settings().value("view/oddeven", type=bool):
for j in (0,1):
if len(subset[2][args[i*2+j][j::2]]):
yvalz = np.mean(subset[2][args[i*2+j][j::2]], axis=0)
spectra.append([subset[1], yvalz])
else:
else:
spectra.append([[],[]])
else:
if len(subset[2][args[i]]):
yvalz = np.mean(subset[2][args[i]], axis=0)
spectra.append([subset[1], yvalz])
else:
spectra.append([[],[]])
return spectra
......@@ -109,8 +118,9 @@ class BrukerTimsDataset(Dataset):
def get_chromatograms(self):
keys = ('retention_time', 'intensity')
times = self.dataset.retention_times / 60
intensities = [np.sum(i['intensity']) for i in self.dataset.query_iter(
self.dataset.ms1_frames, columns=('intensity',))]
intensities = np.asarray([
np.sum(i['intensity']) for i in self.dataset.query_iter(
self.dataset.ms1_frames, columns=('intensity',))])
return [[times,intensities]]
def get_spectra(self):
......
......@@ -238,44 +238,15 @@ def plot_subtime(augCanvas):
augCanvas.spectplot.clear()
augCanvas.chromplot.clear()
for i, subset in enumerate(augCanvas.ds):
selection = augCanvas.chrom['timesarg'][i]
if len(augCanvas.ms['headers']) == len(augCanvas.ds):
legend = legendize(augCanvas.ms['headers'][i][selection],
augCanvas.chrom)
else:
legend = None
if cf.settings().value("view/oddeven", type=bool):
for j in range(2):
chromx = subset['chrom_dat'][0, :][j::2]
chromy = subset['chrom_dat'][1, :][j::2]
pop_plot(chromx, chromy, augCanvas.chromplot,
augCanvas.chrom, i*2+j, legend)
if not np.array_equal(selection[j::2], []):
clr = i*2+j if selection[0] % 2 == 0\
else i*2+(1-j)
ms_x = subset['masses']
ms_y = np.mean(subset['matrix'][selection[j::2]], axis=0)
pop_plot(ms_x, ms_y, augCanvas.spectplot,
augCanvas.ms, clr, legend)
dots_x = subset['chrom_dat'][0, selection[j::2]]
dots_y = subset['chrom_dat'][1, selection[j::2]]
augCanvas.chromplot.plot(dots_x, dots_y, '.', color=(
colors[(clr) % len(colors)]/255))
else:
chromx = subset['chrom_dat'][0, :]
chromy = subset['chrom_dat'][1, :]
pop_plot(chromx, chromy, augCanvas.chromplot,
augCanvas.chrom, i, legend)
if not np.array_equal(selection, []):
ms_x = subset['masses']
ms_y = np.mean(subset['matrix'][selection], axis=0)
pop_plot(ms_x, ms_y, augCanvas.spectplot,
augCanvas.ms, i, legend)
dots_x = subset['chrom_dat'][0, selection]
dots_y = subset['chrom_dat'][1, selection]
augCanvas.chromplot.plot(dots_x, dots_y, '.', color=(
colors[i % len(colors)]/255))
chromargs = augCanvas.ds.get_chromargs()
populate(augCanvas)
chromxy = augCanvas.ds.get_chromatograms()
for i, args in enumerate(chromargs):
if len(args):
dots_x, dots_y = [chromxy[i][j][args] for j in (0,1)]
augCanvas.chromplot.plot(dots_x, dots_y, '.', color=(
colors[i % len(colors)]/255))
augCanvas.spectplot.set_xlim(slims[0])
if not cf.settings().value("view/autozoomy", type=bool):
......@@ -298,19 +269,7 @@ def pick_times(x_min, x_max, augCanvas):
"""subselect part of the chromatogram and plot it"""
augCanvas.ds.timemin = x_min
augCanvas.ds.timemax = x_max
populate(augCanvas)
"""augCanvas.chrom['t_start'] = x_min
augCanvas.chrom['t_end'] = x_max
times = dt.argsubselect(np.concatenate(
[subset['chrom_dat'][0] for subset in augCanvas.ds]), x_min, x_max)
augCanvas.chrom['timesarg'].clear()
for subset in augCanvas.ds:
goodtimes = np.where((times < len(subset['chrom_dat'][0]))
& ~(times < 0))[0]
augCanvas.chrom['timesarg'].append(times[goodtimes])
times = times - len(subset['chrom_dat'][0])
update_paramstable(augCanvas)
plot_subtime(augCanvas)"""
plot_subtime(augCanvas)
def shift_times(event, augCanvas):
......@@ -411,7 +370,6 @@ def ann_spec(ms_spec, msdata, ann_limit=0.01):
def pop_plot(xdata, ydata, plot, plot_data, colornum=0, legend=None, annotate=True):
"""Define and populate plot"""
if len(xdata):
print(colornum)
plot.plot(xdata, ydata, linewidth=1, color=(
colors[colornum % len(colors)]/255), label=legend)
plot.set_title(plot_data['name'], loc="right")
......@@ -501,24 +459,6 @@ def populate(augCanvas):
pop_plot(msxy[i][0], msxy[i][1], augCanvas.spectplot, augCanvas.ms, i, legend)
pop_plot(chromxy[i][0], chromxy[i][1], augCanvas.chromplot,
augCanvas.chrom, i, legend)
"""if cf.settings().value("view/oddeven", type=bool):
msx = subset['masses']
for j in range(2):
msy = np.mean(subset['matrix'][j::2], axis=0)
chromx = subset['chrom_dat'][0, :][j::2]
chromy = subset['chrom_dat'][1, :][j::2]
pop_plot(msx, msy, augCanvas.spectplot, augCanvas.ms,
i*2+j, legend)
pop_plot(chromx, chromy, augCanvas.chromplot,
augCanvas.chrom, i*2+j, legend)
else:
msx = subset['masses']
msy = np.mean(subset['matrix'], axis=0)
chromx = subset['chrom_dat'][0, :]
chromy = subset['chrom_dat'][1, :]
pop_plot(msx, msy, augCanvas.spectplot, augCanvas.ms, i, legend)
pop_plot(chromx, chromy, augCanvas.chromplot, augCanvas.chrom,
i, legend)"""
for ax in (augCanvas.spectplot, augCanvas.chromplot):
if not augCanvas.ms['headers'] == []:
ax.legend(loc=2)
......
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