2006-10-22 17:31:36 +02:00
|
|
|
import gtk
|
|
|
|
from fluents import dataset, logger, plots, workflow, fluents
|
2006-10-23 01:19:54 +02:00
|
|
|
import geneontology
|
2006-10-22 17:31:36 +02:00
|
|
|
#import gostat
|
|
|
|
from scipy import array, randn, log, ones
|
|
|
|
import networkx
|
|
|
|
|
|
|
|
class GoTermView (gtk.Frame):
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
gtk.Frame.__init__(self)
|
2006-10-23 01:19:54 +02:00
|
|
|
tab = gtk.Table(2, 2, False)
|
|
|
|
self._table = tab
|
2006-10-22 17:31:36 +02:00
|
|
|
|
2006-10-23 01:19:54 +02:00
|
|
|
self._name = gtk.Label('')
|
|
|
|
tab.attach(gtk.Label('Name:'), 0, 1, 0, 1)
|
|
|
|
tab.attach(self._name, 1, 2, 0, 1)
|
|
|
|
|
|
|
|
self.add(tab)
|
|
|
|
self.set_go_term(None)
|
|
|
|
|
|
|
|
def set_go_term(self, term):
|
|
|
|
if term:
|
|
|
|
self.set_label(term['id'])
|
|
|
|
self._name.set_text(term['name'])
|
|
|
|
else:
|
|
|
|
self.set_label('GO Term')
|
|
|
|
self._name.set_text('')
|
|
|
|
|
2006-10-22 17:31:36 +02:00
|
|
|
|
|
|
|
class GeneOntologyTree (gtk.HPaned):
|
|
|
|
|
2006-10-23 01:19:54 +02:00
|
|
|
def __init__(self, network):
|
2006-10-22 17:31:36 +02:00
|
|
|
gtk.HPaned.__init__(self)
|
2006-10-23 01:19:54 +02:00
|
|
|
|
|
|
|
treemodel = geneontology.get_go_treestore(network)
|
|
|
|
self._treemodel = treemodel
|
|
|
|
self._tree_view = gtk.TreeView(treemodel)
|
|
|
|
|
|
|
|
renderer = gtk.CellRendererText()
|
|
|
|
go_column = gtk.TreeViewColumn('GO ID', renderer, text=0)
|
|
|
|
self._tree_view.insert_column(go_column, 0)
|
|
|
|
|
|
|
|
renderer = gtk.CellRendererText()
|
|
|
|
go_column = gtk.TreeViewColumn('Name', renderer, text=1)
|
|
|
|
self._tree_view.insert_column(go_column, 1)
|
|
|
|
|
2006-10-22 17:31:36 +02:00
|
|
|
self._desc_view = GoTermView()
|
|
|
|
|
2006-10-23 01:19:54 +02:00
|
|
|
self._tree_view.connect('cursor-changed', self._on_cursor_changed)
|
|
|
|
|
|
|
|
scrolled_window = gtk.ScrolledWindow()
|
|
|
|
scrolled_window.add(self._tree_view)
|
|
|
|
self.add1(scrolled_window)
|
2006-10-22 17:31:36 +02:00
|
|
|
self.add2(self._desc_view)
|
|
|
|
self.show_all()
|
|
|
|
|
2006-10-23 01:19:54 +02:00
|
|
|
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)
|
|
|
|
self._desc_view.set_go_term(term)
|
|
|
|
|
|
|
|
|
2006-10-22 17:31:36 +02:00
|
|
|
class GoWorkflow (workflow.Workflow):
|
|
|
|
|
|
|
|
name = 'Gene Ontology'
|
|
|
|
ident = 'go'
|
|
|
|
description = 'Gene Ontology Workflow. For tree distance measures based '\
|
|
|
|
+ 'on the GO tree.'
|
|
|
|
|
|
|
|
def __init__(self, app):
|
|
|
|
workflow.Workflow.__init__(self, app)
|
|
|
|
|
|
|
|
load = workflow.Stage('load', 'Load GO Annotations')
|
|
|
|
load.add_function(LoadGOFunction())
|
|
|
|
load.add_function(LoadAnnotationsFunction())
|
|
|
|
self.add_stage(load)
|
|
|
|
|
|
|
|
|
|
|
|
class LoadGOFunction(workflow.Function):
|
|
|
|
def __init__(self):
|
|
|
|
workflow.Function.__init__(self, 'load-go', 'Load Gene Ontology')
|
|
|
|
|
|
|
|
def run(self):
|
2006-10-23 01:19:54 +02:00
|
|
|
global go
|
|
|
|
go = geneontology.read_default_go()
|
|
|
|
browser = GeneOntologyTree(go)
|
2006-10-22 17:31:36 +02:00
|
|
|
label = gtk.Label('_Gene Ontology')
|
|
|
|
label.set_use_underline(True)
|
|
|
|
fluents.app['bottom_notebook'].append_page(browser, label)
|
|
|
|
|
|
|
|
class LoadAnnotationsFunction(workflow.Function):
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
workflow.Function.__init__(self, 'load-go-ann', 'Load Annotations')
|
|
|
|
self.annotations = None
|
|
|
|
|
|
|
|
def load_file(self, filename):
|
|
|
|
f = open(filename)
|
|
|
|
self.annotations = Annotations('genes', 'go-terms')
|
|
|
|
logger.log('notice', 'Loading annotation file: %s' % filename)
|
|
|
|
|
|
|
|
for line in f.readlines():
|
|
|
|
val = line.split(' \t')
|
|
|
|
|
|
|
|
if len(val) > 1:
|
|
|
|
val = [v.strip() for v in val]
|
|
|
|
retval.add_annotations('genes', val[0],
|
|
|
|
'go-terms', set(val[1:]))
|
|
|
|
|
|
|
|
def on_response(self, dialog, response):
|
|
|
|
if response == gtk.RESPONSE_OK:
|
|
|
|
logger.log('notice', 'Reading file: %s' % dialog.get_filename())
|
|
|
|
self.load_file(dialog.get_filename())
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
btns = ('Open', gtk.RESPONSE_OK, \
|
|
|
|
'Cancel', gtk.RESPONSE_CANCEL)
|
|
|
|
dialog = gtk.FileChooserDialog('Open GO Annotation File',
|
|
|
|
buttons=btns)
|
|
|
|
dialog.connect('response', self.on_response)
|
|
|
|
dialog.run()
|
|
|
|
dialog.destroy()
|
|
|
|
return [self.annotations]
|
|
|
|
|