diff --git a/workflows/gobrowser.py b/workflows/gobrowser.py index 3214f8b..e716b9d 100644 --- a/workflows/gobrowser.py +++ b/workflows/gobrowser.py @@ -1,6 +1,6 @@ import gtk -from fluents import dataset, logger, plots, workflow, fluents, project, view +from fluents import dataset, logger, plots, workflow, fluents, project, view, main import geneontology from matplotlib.nxutils import points_inside_poly import matplotlib @@ -471,6 +471,17 @@ class TTestFunction(workflow.Function): return options +class SetICFunction(workflow.Function): + def __init__(self): + workflow.Function.__init__(self, 'set-ic', 'Set IC') + + def run(self, ds): + if 'go-terms' in ds.get_dim_name(): + main.workflow.current_ic = ds + else: + logger.log('warning', 'Cannot use this dataset as IC on the go-terms dimension') + return + class PlotDagFunction(workflow.Function): def __init__(self): workflow.Function.__init__(self, 'go-dag', 'Build DAG') @@ -553,13 +564,14 @@ class DagPlot(plots.Plot): with_labels=False, name='DAG Plot'): plots.Plot.__init__(self, name) - self._add_ic_spin_button() + self._add_ic_spin_buttons() self.nodes = graph.nodes() self.graph = graph self._pos = pos self._nodesize = nodesize self._nodecolor = nodecolor self._with_labels = with_labels + self.visible = set() self.current_dim = dim @@ -618,19 +630,33 @@ class DagPlot(plots.Plot): self.axes.set_frame_on(False) self.fig.subplots_adjust(left=0, right=1, bottom=0, top=1) - def _add_ic_spin_button(self): - sb = gtk.SpinButton() - sb.set_range(0, 100) - sb.set_value(1) - sb.set_increments(1, 3) - label = gtk.Label("IC > ") + def _add_ic_spin_buttons(self): + """Adds spin buttons to the toolbar for selecting minimum and maximum + threshold values on information content.""" + sb_min = gtk.SpinButton() + sb_min.set_range(0, 100) + sb_min.set_value(1) + sb_min.set_increments(1, 3) + sb_min.connect('value-changed', self._on_ic_value_changed) + self._ic_sb_min = sb_min + + sb_max = gtk.SpinButton() + sb_max.set_range(0, 100) + sb_max.set_value(1) + sb_max.set_increments(1, 3) + sb_max.connect('value-changed', self._on_ic_value_changed) + self._ic_sb_max = sb_max + + label = gtk.Label(" < IC < ") hbox = gtk.HBox() + hbox.pack_start(sb_min) hbox.pack_start(label) - hbox.pack_start(sb) + hbox.pack_start(sb_max) ti = gtk.ToolItem() ti.set_expand(False) ti.add(hbox) - sb.show() + sb_min.show() + sb_max.show() label.show() hbox.show() ti.show() @@ -638,7 +664,7 @@ class DagPlot(plots.Plot): ti.set_tooltip(self._toolbar.tooltips, "Set information content threshold") def _calc_pos(self, graph): - """Calculates position for graph nodes.""" + """Calculates position for graph nodes using 'dot' layout.""" gv_graph = networkx.DiGraph() for start, end in graph.edges(): gv_graph.add_edge(start.replace('GO:', ''), end.replace('GO:', '')) @@ -652,6 +678,43 @@ class DagPlot(plots.Plot): pos[k] = v return pos + def set_ic_threshold(self, ic_min, ic_max): + """Sets Information Content min and max to the given values. + Updates the plot accordingly to show only values that have an + information content 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. + """ + ic = getattr(main.workflow, 'current_ic', None) + if ic == None: + print "no ic set" + return + + icnodes = ic.existing_identifiers('go-terms', self.nodes) + icindices = ic.get_indices('go-terms', icnodes) + a = ravel(ic.asarray()[icindices]) + ic_good = set(array(icnodes)[(a>ic_min) & (ax1) & (xdatay1) & (ydata