86 lines
2.6 KiB
Python
86 lines
2.6 KiB
Python
import gtk
|
|
from fluents import dataset, logger, plots, workflow, fluents
|
|
#import geneontology
|
|
#import gostat
|
|
from scipy import array, randn, log, ones
|
|
import networkx
|
|
|
|
class GoTermView (gtk.Frame):
|
|
|
|
def __init__(self):
|
|
gtk.Frame.__init__(self)
|
|
self.set_label('GO Term')
|
|
|
|
|
|
class GeneOntologyTree (gtk.HPaned):
|
|
|
|
def __init__(self):
|
|
gtk.HPaned.__init__(self)
|
|
self._tree_view = gtk.TreeView()
|
|
self._desc_view = GoTermView()
|
|
|
|
self.add1(self._tree_view)
|
|
self.add2(self._desc_view)
|
|
self.show_all()
|
|
|
|
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):
|
|
browser = GeneOntologyTree()
|
|
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]
|
|
|