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

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

View File

@@ -559,119 +559,16 @@ class VolcanoPlot(plots.ScatterPlot):
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):
def __init__(self, graph, dim='go-terms', pos=None, nodecolor='b', nodesize=40,
with_labels=False, name='DAG Plot'):
plots.Plot.__init__(self, name)
self.nodes = graph.nodes()
self._map_ids = self.nodes
self.graph = graph
self._pos = pos
self._cmap = matplotlib.cm.summer
self._nodesize = nodesize
self._nodecolor = nodecolor
self._with_labels = with_labels
@@ -700,6 +597,7 @@ class DagPlot(plots.Plot):
linewidth=lw,
zorder=3)
self._mappable = self.node_collection
self._mappable.set_cmap(self._cmap)
# selected nodes is a transparent graph that adjust node-edge visibility
# according to the current selection needed to get get the selected
@@ -850,13 +748,13 @@ class DagPlot(plots.Plot):
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,
with_labels=False, name='DAG Plot'):
DagPlot.__init__(self, graph, dim='go-terms', pos=None,
nodecolor='b', nodesize=40,
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):
ids = self.points_in_rect(x1, y1, x2, y2, key)