Projects/laydi
Projects
/
laydi
Archived
7
0
Fork 0

Added information content drag'n'drop to z loadings plot.

This commit is contained in:
Einar Ryeng 2007-08-06 16:20:39 +00:00
parent 72e300c95e
commit 4b80baf225
3 changed files with 121 additions and 115 deletions

View File

@ -51,7 +51,7 @@ class BlmScatterPlot(plots.ScatterPlot):
absi= ordi = 0 absi= ordi = 0
self._absi = absi self._absi = absi
self._ordi = ordi self._ordi = ordi
self._cmap = cm.jet self._cmap = cm.summer
dataset_1 = model.as_dataset(part_name) dataset_1 = model.as_dataset(part_name)
id_dim = dataset_1.get_dim_name(0) id_dim = dataset_1.get_dim_name(0)
sel_dim = dataset_1.get_dim_name(1) sel_dim = dataset_1.get_dim_name(1)
@ -185,10 +185,17 @@ class LplsXLoadingPlot(BlmScatterPlot):
title = "Lpls x-loadings (%s)" %model._dataset['X'].get_name() title = "Lpls x-loadings (%s)" %model._dataset['X'].get_name()
BlmScatterPlot.__init__(self, title, model, absi, ordi, part_name='P', color_by='tsqx') BlmScatterPlot.__init__(self, title, model, absi, ordi, part_name='P', color_by='tsqx')
class LplsZLoadingPlot(BlmScatterPlot): class LplsZLoadingPlot(BlmScatterPlot, plots.PlotThresholder):
def __init__(self, model, absi=0, ordi=1): def __init__(self, model, absi=0, ordi=1):
title = "Lpls z-loadings (%s)" %model._dataset['Z'].get_name() title = "Lpls z-loadings (%s)" %model._dataset['Z'].get_name()
BlmScatterPlot.__init__(self, title, model, absi, ordi, part_name='L', color_by='tsqz') BlmScatterPlot.__init__(self, title, model, absi, ordi, part_name='L', color_by='tsqz')
plots.PlotThresholder.__init__(self, "IC")
def _update_color_from_dataset(self, ds):
BlmScatterPlot._update_color_from_dataset(self, ds)
self.set_threshold_dataset(ds)
class LplsXCorrelationPlot(BlmScatterPlot): class LplsXCorrelationPlot(BlmScatterPlot):
def __init__(self, model, absi=0, ordi=1): def __init__(self, model, absi=0, ordi=1):

View File

@ -382,6 +382,7 @@ class ScatterPlot(Plot):
self.c = c self.c = c
self.kw = kw self.kw = kw
self.current_dim = id_dim self.current_dim = id_dim
self._map_ids = dataset_1.get_identifiers(id_dim, sorted=True)
x_index = dataset_1[sel_dim][id_1] x_index = dataset_1[sel_dim][id_1]
if sel_dim_2: if sel_dim_2:
@ -441,25 +442,20 @@ class ScatterPlot(Plot):
def is_mappable_with(self, obj): def is_mappable_with(self, obj):
"""Returns True if dataset/selection is mappable with this plot. """Returns True if dataset/selection is mappable with this plot.
""" """
print "is_mappable_with"
if isinstance(obj, fluents.dataset.Dataset): if isinstance(obj, fluents.dataset.Dataset):
if self.current_dim in obj.get_dim_name(): if self.current_dim in obj.get_dim_name():
print "is_mappable_with: True"
return True return True
elif isinstance(obj, fluents.dataset.Selection): elif isinstance(obj, fluents.dataset.Selection):
if self.current_dim in obj.get_dim_name(): if self.current_dim in obj.get_dim_name():
print "is_mappable_with: True"
return True return True
else: else:
print "is_mappable_with: False"
return False return False
def _update_color_from_dataset(self, data): def _update_color_from_dataset(self, data):
"""Updates the facecolors from a dataset. """Updates the facecolors from a dataset.
""" """
print "_update_color_from_dataset"
array = data.asarray() array = data.asarray()
#only support for 2d-arrays: #only support for 2d-arrays:
try: try:
@ -576,7 +572,6 @@ class HistogramPlot(Plot):
# Set default paramteters # Set default paramteters
if not kw.has_key('bins'): if not kw.has_key('bins'):
kw['bins'] = self._get_binsize() kw['bins'] = self._get_binsize()
print kw['bins']
# Initial draw # Initial draw
self.axes.grid(False) self.axes.grid(False)
@ -970,6 +965,112 @@ class VennPlot(Plot):
return scipy.sqrt( (x2-x1)**2 + (y2-y1)**2 ) return scipy.sqrt( (x2-x1)**2 + (y2-y1)**2 )
class PlotThresholder:
"""Mixin class for plots that needs to filter nodes within a threshold
range.
"""
def __init__(self, text="x"):
"""Constructor.
@param text: Name of the variable the threshold is on.
"""
self._threshold_ds = None
self._add_spin_buttons(text)
self._sb_min.set_sensitive(False)
self._sb_max.set_sensitive(False)
def set_threshold_dataset(self, ds):
"""Sets the dataset to threshold on.
@param ds: A dataset where one dimension corresponds to the select dimension
in the plot, and any other dimensions have length 1
"""
self._threshold_ds = ds
self._sb_min.set_sensitive(True)
self._sb_max.set_sensitive(True)
def _add_spin_buttons(self, text):
"""Adds spin buttons to the toolbar for selecting minimum and maximum
threshold values on information content."""
sb_min = gtk.SpinButton(digits=2)
sb_min.set_range(0, 100)
sb_min.set_value(0)
sb_min.set_increments(.1, 1.)
sb_min.connect('value-changed', self._on_value_changed)
self._sb_min = sb_min
sb_max = gtk.SpinButton(digits=2)
sb_max.set_range(0, 100)
sb_max.set_value(1)
sb_max.set_increments(.1, 1.)
sb_max.connect('value-changed', self._on_value_changed)
self._sb_max = sb_max
label = gtk.Label(" < %s < " % text)
hbox = gtk.HBox()
hbox.pack_start(sb_min)
hbox.pack_start(label)
hbox.pack_start(sb_max)
ti = gtk.ToolItem()
ti.set_expand(False)
ti.add(hbox)
sb_min.show()
sb_max.show()
label.show()
hbox.show()
ti.show()
self._toolbar.insert(ti, -1)
ti.set_tooltip(self._toolbar.tooltips, "Set threshold")
def set_threshold(self, min, max):
"""Sets min and max to the given values.
Updates the plot accordingly to show only values that have a
value within the boundaries. Other values are
also excluded from being selected from the plot.
@param ic_min Do not show nodes with IC below this value.
@param ic_max Do not show nodes with IC above this value.
"""
ds = self._threshold_ds
if ds == None:
return
icnodes = ds.existing_identifiers('go-terms', self._map_ids)
icindices = ds.get_indices('go-terms', icnodes)
a = scipy.ravel(ds.asarray()[icindices])
good = set(scipy.array(icnodes)[(a>=min) & (a<=max)])
sizes = scipy.zeros(len(self._map_ids))
visible = set()
for i, n in enumerate(self._map_ids):
if n in good:
sizes[i] = 50
visible.add(n)
else:
sizes[i] = 0
self.visible = visible
self._mappable._sizes = sizes
self.canvas.draw()
def get_nodes_within_bounds(self):
"""Get a list of all nodes within the bounds of the selection in the
seleted dataset.
"""
pass
def filter_nodes(self, nodes):
"""Filter a list of nodes and return only those that are within the
threshold boundaries."""
pass
def _on_value_changed(self, sb):
"""Callback on spin button value changes."""
min = self._sb_min.get_value()
max = self._sb_max.get_value()
self.set_threshold(min, max)
# Create zoom-changed signal # Create zoom-changed signal
gobject.signal_new('zoom-changed', Plot, gobject.SIGNAL_RUN_LAST, None, gobject.signal_new('zoom-changed', Plot, gobject.SIGNAL_RUN_LAST, None,
(gobject.TYPE_PYOBJECT,)) (gobject.TYPE_PYOBJECT,))

View File

@ -559,119 +559,16 @@ class VolcanoPlot(plots.ScatterPlot):
sel_dim_2='_p', **kw) sel_dim_2='_p', **kw)
class PlotThresholder:
"""Mixin class for plots that needs to filter nodes within a threshold
range.
"""
def __init__(self, text="x"):
"""Constructor.
@param text: Name of the variable the threshold is on.
"""
self._threshold_ds = None
self._add_spin_buttons(text)
self._sb_min.set_sensitive(False)
self._sb_max.set_sensitive(False)
def set_threshold_dataset(self, ds):
"""Sets the dataset to threshold on.
@param ds: A dataset where one dimension corresponds to the select dimension
in the plot, and any other dimensions have length 1
"""
self._threshold_ds = ds
self._sb_min.set_sensitive(True)
self._sb_max.set_sensitive(True)
def _add_spin_buttons(self, text):
"""Adds spin buttons to the toolbar for selecting minimum and maximum
threshold values on information content."""
sb_min = gtk.SpinButton(digits=2)
sb_min.set_range(0, 100)
sb_min.set_value(0)
sb_min.set_increments(.1, 1.)
sb_min.connect('value-changed', self._on_value_changed)
self._sb_min = sb_min
sb_max = gtk.SpinButton(digits=2)
sb_max.set_range(0, 100)
sb_max.set_value(1)
sb_max.set_increments(.1, 1.)
sb_max.connect('value-changed', self._on_value_changed)
self._sb_max = sb_max
label = gtk.Label(" < %s < " % text)
hbox = gtk.HBox()
hbox.pack_start(sb_min)
hbox.pack_start(label)
hbox.pack_start(sb_max)
ti = gtk.ToolItem()
ti.set_expand(False)
ti.add(hbox)
sb_min.show()
sb_max.show()
label.show()
hbox.show()
ti.show()
self._toolbar.insert(ti, -1)
ti.set_tooltip(self._toolbar.tooltips, "Set threshold")
def set_threshold(self, min, max):
"""Sets min and max to the given values.
Updates the plot accordingly to show only values that have a
value within the boundaries. Other values are
also excluded from being selected from the plot.
@param ic_min Do not show nodes with IC below this value.
@param ic_max Do not show nodes with IC above this value.
"""
ds = self._threshold_ds
if ds == None:
return
icnodes = ds.existing_identifiers('go-terms', self.nodes)
icindices = ds.get_indices('go-terms', icnodes)
a = ravel(ds.asarray()[icindices])
good = set(array(icnodes)[(a>=min) & (a<=max)])
sizes = zeros(len(self.nodes))
visible = set()
for i, n in enumerate(self.nodes):
if n in good:
sizes[i] = 50
visible.add(n)
else:
sizes[i] = 0
self.visible = visible
self.node_collection._sizes = sizes
self.canvas.draw()
def get_nodes_within_bounds(self):
"""Get a list of all nodes within the bounds of the selection in the
seleted dataset.
"""
pass
def filter_nodes(self, nodes):
"""Filter a list of nodes and return only those that are within the
threshold boundaries."""
pass
def _on_value_changed(self, sb):
"""Callback on spin button value changes."""
min = self._sb_min.get_value()
max = self._sb_max.get_value()
self.set_threshold(min, max)
class DagPlot(plots.Plot): class DagPlot(plots.Plot):
def __init__(self, graph, dim='go-terms', pos=None, nodecolor='b', nodesize=40, def __init__(self, graph, dim='go-terms', pos=None, nodecolor='b', nodesize=40,
with_labels=False, name='DAG Plot'): with_labels=False, name='DAG Plot'):
plots.Plot.__init__(self, name) plots.Plot.__init__(self, name)
self.nodes = graph.nodes() self.nodes = graph.nodes()
self._map_ids = self.nodes
self.graph = graph self.graph = graph
self._pos = pos self._pos = pos
self._cmap = matplotlib.cm.summer
self._nodesize = nodesize self._nodesize = nodesize
self._nodecolor = nodecolor self._nodecolor = nodecolor
self._with_labels = with_labels self._with_labels = with_labels
@ -700,6 +597,7 @@ class DagPlot(plots.Plot):
linewidth=lw, linewidth=lw,
zorder=3) zorder=3)
self._mappable = self.node_collection self._mappable = self.node_collection
self._mappable.set_cmap(self._cmap)
# selected nodes is a transparent graph that adjust node-edge visibility # selected nodes is a transparent graph that adjust node-edge visibility
# according to the current selection needed to get get the selected # according to the current selection needed to get get the selected
@ -850,13 +748,13 @@ class DagPlot(plots.Plot):
self.canvas.draw() self.canvas.draw()
class ThresholdDagPlot(DagPlot, PlotThresholder): class ThresholdDagPlot(DagPlot, plots.PlotThresholder):
def __init__(self, graph, dim='go-terms', pos=None, nodecolor='b', nodesize=40, def __init__(self, graph, dim='go-terms', pos=None, nodecolor='b', nodesize=40,
with_labels=False, name='DAG Plot'): with_labels=False, name='DAG Plot'):
DagPlot.__init__(self, graph, dim='go-terms', pos=None, DagPlot.__init__(self, graph, dim='go-terms', pos=None,
nodecolor='b', nodesize=40, nodecolor='b', nodesize=40,
with_labels=False, name='DAG Plot') with_labels=False, name='DAG Plot')
PlotThresholder.__init__(self, "IC") plots.PlotThresholder.__init__(self, "IC")
def rectangle_select_callback(self, x1, y1, x2, y2, key): def rectangle_select_callback(self, x1, y1, x2, y2, key):
ids = self.points_in_rect(x1, y1, x2, y2, key) ids = self.points_in_rect(x1, y1, x2, y2, key)