Added a tag column in the GO browser to help link it to selections.
This commit is contained in:
parent
442b5fed5f
commit
ae9a207a71
|
@ -192,12 +192,13 @@ def read_default_go():
|
|||
|
||||
def _add_subgraphs(treestore, ontology, parent, nodes):
|
||||
for n in nodes:
|
||||
i = treestore.insert(parent, 0, (n['id'], n['name'], n))
|
||||
i = treestore.insert(parent, 0, (n['id'], n['name'], False, n))
|
||||
_add_subgraphs(treestore, ontology, i, ontology.successors(n))
|
||||
|
||||
def get_go_treestore(ontology):
|
||||
ts = gtk.TreeStore(gobject.TYPE_STRING, ## ID
|
||||
gobject.TYPE_STRING, ## Name
|
||||
gobject.TYPE_BOOLEAN, ## Selected
|
||||
gobject.TYPE_PYOBJECT) ## Node
|
||||
_add_subgraphs(ts, ontology, None, [ontology.get_bp()])
|
||||
return ts
|
||||
|
|
|
@ -77,6 +77,10 @@ class GeneOntologyTree (gtk.HPaned):
|
|||
self._treemodel = treemodel
|
||||
self._tree_view = gtk.TreeView(treemodel)
|
||||
|
||||
self._selected_terms = set()
|
||||
|
||||
self._tree_view.set_fixed_height_mode(True)
|
||||
|
||||
# Set up context menu
|
||||
self._context_menu = GoTermContextMenu(treemodel, self._tree_view)
|
||||
self._tree_view.connect('popup_menu', self._popup_menu)
|
||||
|
@ -84,11 +88,28 @@ class GeneOntologyTree (gtk.HPaned):
|
|||
|
||||
renderer = gtk.CellRendererText()
|
||||
go_column = gtk.TreeViewColumn('GO ID', renderer, text=0)
|
||||
go_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
|
||||
go_column.set_fixed_width(200)
|
||||
go_column.set_resizable(True)
|
||||
self._tree_view.insert_column(go_column, 0)
|
||||
|
||||
renderer = gtk.CellRendererToggle()
|
||||
renderer.set_property('activatable', True)
|
||||
renderer.connect('toggled', self._toggle_selected)
|
||||
renderer.set_active(True)
|
||||
renderer.set_property('mode', gtk.CELL_RENDERER_MODE_ACTIVATABLE)
|
||||
go_column = gtk.TreeViewColumn('T', renderer, active=2)
|
||||
go_column.set_fixed_width(20)
|
||||
go_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
|
||||
go_column.set_resizable(True)
|
||||
self._tree_view.insert_column(go_column, 1)
|
||||
|
||||
renderer = gtk.CellRendererText()
|
||||
go_column = gtk.TreeViewColumn('Name', renderer, text=1)
|
||||
self._tree_view.insert_column(go_column, 1)
|
||||
go_column.set_fixed_width(200)
|
||||
go_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
|
||||
go_column.set_resizable(True)
|
||||
self._tree_view.insert_column(go_column, 2)
|
||||
|
||||
self._desc_view = GoTermView()
|
||||
|
||||
|
@ -103,7 +124,7 @@ class GeneOntologyTree (gtk.HPaned):
|
|||
def _on_cursor_changed(self, tree):
|
||||
path, col = self._tree_view.get_cursor()
|
||||
current = self._treemodel.get_iter(path)
|
||||
term = self._treemodel.get_value(current, 2)
|
||||
term = self._treemodel.get_value(current, 3)
|
||||
self._desc_view.set_go_term(term)
|
||||
|
||||
|
||||
|
@ -119,7 +140,7 @@ class GeneOntologyTree (gtk.HPaned):
|
|||
|
||||
if path:
|
||||
iter = self._treemodel.get_iter(path[0])
|
||||
obj = self._treemodel.get_value(iter, 2)
|
||||
obj = self._treemodel.get_value(iter, 3)
|
||||
else:
|
||||
obj = None
|
||||
|
||||
|
@ -128,6 +149,19 @@ class GeneOntologyTree (gtk.HPaned):
|
|||
if event.button == 3:
|
||||
self._context_menu.popup(None, None, None, event.button, event.time)
|
||||
|
||||
def _toggle_selected(self, renderer, path):
|
||||
iter = self._treemodel.get_iter(path)
|
||||
|
||||
selected = self._treemodel.get_value(iter, 2)
|
||||
id = self._treemodel.get_value(iter, 0)
|
||||
|
||||
self._treemodel.set_value(iter, 2, not selected)
|
||||
|
||||
if selected:
|
||||
self._selected_terms.remove(id)
|
||||
else:
|
||||
self._selected_terms.add(id)
|
||||
|
||||
|
||||
class GoTermContextMenu (gtk.Menu):
|
||||
"""Context menu for GO terms in the gene ontology browser"""
|
||||
|
|
Reference in New Issue