Added spin buttons for minimum and maximum information content in DAG plot.
This commit is contained in:
parent
dc3893eecc
commit
b233e4abc6
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
import gtk
|
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
|
import geneontology
|
||||||
from matplotlib.nxutils import points_inside_poly
|
from matplotlib.nxutils import points_inside_poly
|
||||||
import matplotlib
|
import matplotlib
|
||||||
|
@ -471,6 +471,17 @@ class TTestFunction(workflow.Function):
|
||||||
return options
|
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):
|
class PlotDagFunction(workflow.Function):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
workflow.Function.__init__(self, 'go-dag', 'Build DAG')
|
workflow.Function.__init__(self, 'go-dag', 'Build DAG')
|
||||||
|
@ -553,13 +564,14 @@ class DagPlot(plots.Plot):
|
||||||
with_labels=False, name='DAG Plot'):
|
with_labels=False, name='DAG Plot'):
|
||||||
|
|
||||||
plots.Plot.__init__(self, name)
|
plots.Plot.__init__(self, name)
|
||||||
self._add_ic_spin_button()
|
self._add_ic_spin_buttons()
|
||||||
self.nodes = graph.nodes()
|
self.nodes = graph.nodes()
|
||||||
self.graph = graph
|
self.graph = graph
|
||||||
self._pos = pos
|
self._pos = pos
|
||||||
self._nodesize = nodesize
|
self._nodesize = nodesize
|
||||||
self._nodecolor = nodecolor
|
self._nodecolor = nodecolor
|
||||||
self._with_labels = with_labels
|
self._with_labels = with_labels
|
||||||
|
self.visible = set()
|
||||||
|
|
||||||
self.current_dim = dim
|
self.current_dim = dim
|
||||||
|
|
||||||
|
@ -618,19 +630,33 @@ class DagPlot(plots.Plot):
|
||||||
self.axes.set_frame_on(False)
|
self.axes.set_frame_on(False)
|
||||||
self.fig.subplots_adjust(left=0, right=1, bottom=0, top=1)
|
self.fig.subplots_adjust(left=0, right=1, bottom=0, top=1)
|
||||||
|
|
||||||
def _add_ic_spin_button(self):
|
def _add_ic_spin_buttons(self):
|
||||||
sb = gtk.SpinButton()
|
"""Adds spin buttons to the toolbar for selecting minimum and maximum
|
||||||
sb.set_range(0, 100)
|
threshold values on information content."""
|
||||||
sb.set_value(1)
|
sb_min = gtk.SpinButton()
|
||||||
sb.set_increments(1, 3)
|
sb_min.set_range(0, 100)
|
||||||
label = gtk.Label("IC > ")
|
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 = gtk.HBox()
|
||||||
|
hbox.pack_start(sb_min)
|
||||||
hbox.pack_start(label)
|
hbox.pack_start(label)
|
||||||
hbox.pack_start(sb)
|
hbox.pack_start(sb_max)
|
||||||
ti = gtk.ToolItem()
|
ti = gtk.ToolItem()
|
||||||
ti.set_expand(False)
|
ti.set_expand(False)
|
||||||
ti.add(hbox)
|
ti.add(hbox)
|
||||||
sb.show()
|
sb_min.show()
|
||||||
|
sb_max.show()
|
||||||
label.show()
|
label.show()
|
||||||
hbox.show()
|
hbox.show()
|
||||||
ti.show()
|
ti.show()
|
||||||
|
@ -638,7 +664,7 @@ class DagPlot(plots.Plot):
|
||||||
ti.set_tooltip(self._toolbar.tooltips, "Set information content threshold")
|
ti.set_tooltip(self._toolbar.tooltips, "Set information content threshold")
|
||||||
|
|
||||||
def _calc_pos(self, graph):
|
def _calc_pos(self, graph):
|
||||||
"""Calculates position for graph nodes."""
|
"""Calculates position for graph nodes using 'dot' layout."""
|
||||||
gv_graph = networkx.DiGraph()
|
gv_graph = networkx.DiGraph()
|
||||||
for start, end in graph.edges():
|
for start, end in graph.edges():
|
||||||
gv_graph.add_edge(start.replace('GO:', ''), end.replace('GO:', ''))
|
gv_graph.add_edge(start.replace('GO:', ''), end.replace('GO:', ''))
|
||||||
|
@ -652,6 +678,43 @@ class DagPlot(plots.Plot):
|
||||||
pos[k] = v
|
pos[k] = v
|
||||||
return pos
|
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) & (a<ic_max)])
|
||||||
|
|
||||||
|
sizes = zeros(len(self.nodes))
|
||||||
|
visible = set()
|
||||||
|
for i, n in enumerate(self.nodes):
|
||||||
|
if n in ic_good:
|
||||||
|
sizes[i] = 50
|
||||||
|
visible.add(n)
|
||||||
|
else:
|
||||||
|
sizes[i] = 0
|
||||||
|
self.visible = visible
|
||||||
|
|
||||||
|
self.node_collection._sizes = sizes
|
||||||
|
self.canvas.draw()
|
||||||
|
|
||||||
|
def _on_ic_value_changed(self, sb):
|
||||||
|
"""Callback on spin button value changes."""
|
||||||
|
ic_min = self._ic_sb_min.get_value()
|
||||||
|
ic_max = self._ic_sb_max.get_value()
|
||||||
|
self.set_ic_threshold(ic_min, ic_max)
|
||||||
|
|
||||||
def rectangle_select_callback(self, x1, y1, x2, y2, key):
|
def rectangle_select_callback(self, x1, y1, x2, y2, key):
|
||||||
ydata = self.yaxis_data
|
ydata = self.yaxis_data
|
||||||
xdata = self.xaxis_data
|
xdata = self.xaxis_data
|
||||||
|
@ -665,7 +728,7 @@ class DagPlot(plots.Plot):
|
||||||
assert y1<=y2
|
assert y1<=y2
|
||||||
|
|
||||||
index = nonzero((xdata>x1) & (xdata<x2) & (ydata>y1) & (ydata<y2))[0]
|
index = nonzero((xdata>x1) & (xdata<x2) & (ydata>y1) & (ydata<y2))[0]
|
||||||
ids = [self.nodes[i] for i in index]
|
ids = self.visible.intersection([self.nodes[i] for i in index])
|
||||||
ids = self.update_selection(ids, key)
|
ids = self.update_selection(ids, key)
|
||||||
self.selection_listener(self.current_dim, ids)
|
self.selection_listener(self.current_dim, ids)
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,7 @@ class SmallTestWorkflow(workflow.Workflow):
|
||||||
# Gene Ontology
|
# Gene Ontology
|
||||||
go = workflow.Stage('go', 'Gene Ontology')
|
go = workflow.Stage('go', 'Gene Ontology')
|
||||||
go.add_function(gobrowser.LoadGOFunction())
|
go.add_function(gobrowser.LoadGOFunction())
|
||||||
|
go.add_function(gobrowser.SetICFunction())
|
||||||
# go.add_function(gobrowser.GOWeightFunction())
|
# go.add_function(gobrowser.GOWeightFunction())
|
||||||
# go.add_function(gobrowser.DistanceToSelectionFunction())
|
# go.add_function(gobrowser.DistanceToSelectionFunction())
|
||||||
# go.add_function(gobrowser.TTestFunction())
|
# go.add_function(gobrowser.TTestFunction())
|
||||||
|
|
Reference in New Issue