Commit 8ccb50ef authored by Yan's avatar Yan
Browse files

Parameters change support - pt6

* drltools roughly fixed
* not tested!!
parent c14eca65
...@@ -44,41 +44,45 @@ def floatize(table, row, column, nonneg=True): ...@@ -44,41 +44,45 @@ def floatize(table, row, column, nonneg=True):
return outfloat return outfloat
def get_massargs(pt, row, ds): def get_massargs(pt, row, subset):
startm = floatize(pt, row, 1) - (floatize(pt, row, 2) / 2) startm = floatize(pt, row, 1) - (floatize(pt, row, 2) / 2)
endm = floatize(pt, row, 1) + (floatize(pt, row, 2) / 2) endm = floatize(pt, row, 1) + (floatize(pt, row, 2) / 2)
massargs = dt.argsubselect(ds['masses'], startm, endm) massargs = dt.argsubselect(subset['masses'], startm, endm)
return massargs return massargs
def update_profile(pt, row, dataset): def update_profile(pt, row, dataset):
"""parent table profile spectrum updating procedure""" """parent table profile spectrum updating procedure"""
# Dont do anything to graph when the spectrum is not populated
logger.debug("updating parent table row {} profile".format(row)) logger.debug("updating parent table row {} profile".format(row))
if isinstance(dataset['masses'], type(None)): # Dont do anything to graph when the spectrum is not populated
if len(dataset) == 0:
return return
spectrum = pt.cellWidget(row, 3).figure.get_axes()[0] spectrum = pt.cellWidget(row, 3).figure.get_axes()[0]
masses = dataset['masses']
massargs = get_massargs(pt, row, dataset)
yshape = np.mean(dataset['matrix'], axis=0)
spectrum.clear() spectrum.clear()
spectrum.plot(masses, yshape, ':', color='gray') limits = []
spectrum.plot(masses[massargs], yshape[massargs], 'r') for i,subset in enumerate(dataset):
xex = max((masses[massargs[-1]]-masses[massargs[0]])*0.25, 0.20) masses = subset['masses']
spectrum.set_xlim(masses[massargs[0]]-xex, massargs = get_massargs(pt, row, subset)
masses[massargs[-1]]+xex) yshape = np.mean(subset['matrix'], axis=0)
ymax = max(yshape[massargs]) 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])))
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)
spectrum.set_xlim(xmin-xex, xmax+xex)
ymax = max([lim[1] for lim in limits])
spectrum.set_ylim(ymax*-0.1, ymax*1.2) spectrum.set_ylim(ymax*-0.1, ymax*1.2)
spectrum.figure.canvas.draw() spectrum.figure.canvas.draw()
def get_intensity(row, ds, drls): def get_intensity(row, ds, drls):
massargs = get_massargs(drls['pt'], row, ds)
#prevent division by 0 #prevent division by 0
intensity = np.divide(np.sum( ds['matrix'].T[massargs].T, axis=1), intensity = np.concatenate([np.divide(np.sum(subset['matrix'].T[
np.clip(ds['chrom_dat'][1], np.nextafter( get_massargs(drls['pt'],row,subset)].T, axis=1),
0, 1, dtype=np.float32), None)) np.clip(subset['chrom_dat'][1], np.finfo(np.float32).eps, None))
for subset in ds])
return intensity return intensity
...@@ -86,7 +90,7 @@ def get_daughterset(ds, drls): ...@@ -86,7 +90,7 @@ def get_daughterset(ds, drls):
"""Fuction to acquire the curves of the daugher ions""" """Fuction to acquire the curves of the daugher ions"""
logger.info("getting set of the daughter ions") logger.info("getting set of the daughter ions")
names = [] names = []
times = ds['chrom_dat'][0, :] - drls['tshift'].value() times = np.concatenate([sub['chrom_dat'][0, :] - drls['tshift'].value() for sub in ds])
intensities = [] intensities = []
for row in range(drls['dt'].rowCount()): for row in range(drls['dt'].rowCount()):
if drls['dt'].cellWidget(row, 0).checkState() == 2: if drls['dt'].cellWidget(row, 0).checkState() == 2:
...@@ -104,14 +108,13 @@ def get_daughterset(ds, drls): ...@@ -104,14 +108,13 @@ def get_daughterset(ds, drls):
cortext = " + ".join(corlist) cortext = " + ".join(corlist)
intensities.append(intensity) intensities.append(intensity)
names.append("{} - ({})".format( names.append("{} - ({})".format(
drls['dt'].item(row, 0).text(), drls['dt'].item(row, 0).text(), cortext))
cortext))
return names, times, intensities return names, times, intensities
def get_parentset(ds, drls): def get_parentset(ds, drls):
names = [] names = []
times = ds['chrom_dat'][0, :] times = np.concatenate([sub['chrom_dat'][0, :] for sub in ds])
intensities = [] intensities = []
rowlist = [] rowlist = []
for row in range(drls['dt'].rowCount()): for row in range(drls['dt'].rowCount()):
...@@ -134,12 +137,12 @@ def update_drlspectrum(ds, drls, drlspectrum): ...@@ -134,12 +137,12 @@ def update_drlspectrum(ds, drls, drlspectrum):
"""Generic DRL spectrum updating procedure""" """Generic DRL spectrum updating procedure"""
logger.info("updating DRL spectrum") logger.info("updating DRL spectrum")
# Do not do anything when the data set is not populated. # Do not do anything when the data set is not populated.
if isinstance(ds['masses'], type(None)): if len(ds) == 0:
return return
names, times, intensities = get_daughterset(ds, drls) names, times, intensities = get_daughterset(ds, drls)
drlspectrum.clear() drlspectrum.clear()
gt.pop_plot(drlspectrum, drls['graphlabels']) gt.pop_plot(0, 0, drlspectrum, drls['graphlabels'])
drlspectrum.axvline(0, 0, 0.9, color="#FF000088", linestyle=":") drlspectrum.axvline(0, 0, 0.9, color="#FF000088", linestyle=":")
if drls['cutoff'].value() != 0: if drls['cutoff'].value() != 0:
...@@ -158,8 +161,8 @@ def update_drlspectrum(ds, drls, drlspectrum): ...@@ -158,8 +161,8 @@ def update_drlspectrum(ds, drls, drlspectrum):
if drls['rel'].checkState() == 2: if drls['rel'].checkState() == 2:
#Do not divide by 0 #Do not divide by 0
intensity = np.divide(intensity, np.clip(np.sum( intensity = np.divide(intensity, np.clip(np.sum(
intensities, 0), np.nextafter( intensities, 0), np.finfo(np.float32).eps, None),
0, 1, dtype=np.float32), None), dtype=np.float64) dtype=np.float64)
drlspectrum.plot(times, intensity, label=label, drlspectrum.plot(times, intensity, label=label,
color=(gt.colors[row % len(gt.colors)] / 255)) color=(gt.colors[row % len(gt.colors)] / 255))
i += 1 i += 1
...@@ -661,8 +664,7 @@ def main_window(parent, ds, filename, cache, update_signal): ...@@ -661,8 +664,7 @@ def main_window(parent, ds, filename, cache, update_signal):
drls['checkAll'] = QtWidgets.QCheckBox("Select all") drls['checkAll'] = QtWidgets.QCheckBox("Select all")
drls['cors'] = QtWidgets.QSpinBox(minimum=0) drls['cors'] = QtWidgets.QSpinBox(minimum=0)
drls['cors'].setValue(3) drls['cors'].setValue(3)
drls['graphlabels'] = dict(x=[0], y=[0], line=None, name="", drls['graphlabels'] = dict(line=None, name="", xlabel="time(min)",
xlabel="time(min)",
ylabel="relative intensity") ylabel="relative intensity")
dial_graph = Figure(figsize=(5, 2), dpi=100, facecolor="None") dial_graph = Figure(figsize=(5, 2), dpi=100, facecolor="None")
...@@ -672,7 +674,7 @@ def main_window(parent, ds, filename, cache, update_signal): ...@@ -672,7 +674,7 @@ def main_window(parent, ds, filename, cache, update_signal):
graph_canvas.setAutoFillBackground(False) graph_canvas.setAutoFillBackground(False)
gt.pan_factory(chromplot) gt.pan_factory(chromplot)
gt.zoom_factory(chromplot, 1.15) gt.zoom_factory(chromplot, 1.15)
gt.pop_plot(chromplot, drls['graphlabels']) gt.pop_plot(0, 0, chromplot, drls['graphlabels'])
dcolums = ["Name"] dcolums = ["Name"]
for i in range(drls['cors'].value()): for i in range(drls['cors'].value()):
......
...@@ -24,7 +24,7 @@ def paint_image(mass_spec, spect, painttarget=None): ...@@ -24,7 +24,7 @@ def paint_image(mass_spec, spect, painttarget=None):
printplot.set_xlim(spect.get_xlim()) printplot.set_xlim(spect.get_xlim())
printplot.set_ylim(spect.get_ylim()) printplot.set_ylim(spect.get_ylim())
data = [line.get_data() for line in spect.lines] data = [line.get_data() for line in spect.lines]
[gt.pop_plot(*line, printplot, mass_spec) for line in data] [gt.pop_plot(*line, printplot, mass_spec, i) for i,line in enumerate(data)]
printplot.locator_params(nbins=xtics, axis='x') printplot.locator_params(nbins=xtics, axis='x')
cache_file = BytesIO() cache_file = BytesIO()
paintfig.savefig(cache_file) paintfig.savefig(cache_file)
......
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