From fac9346aadc8a93d9db77d5900b5601570c56c93 Mon Sep 17 00:00:00 2001 From: einarr Date: Fri, 15 Dec 2006 12:53:27 +0000 Subject: [PATCH] Added very hackish annotation count reader. --- workflows/go_workflow.py | 59 ++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/workflows/go_workflow.py b/workflows/go_workflow.py index 7515ab6..dcd833f 100644 --- a/workflows/go_workflow.py +++ b/workflows/go_workflow.py @@ -2,7 +2,7 @@ import gtk from fluents import dataset, logger, plots, workflow, fluents import geneontology #import gostat -from scipy import array, randn, log, ones +from scipy import array, randn, log, ones, zeros import networkx EVIDENCE_CODES=[('IMP', 'Inferred from mutant phenotype'), @@ -22,6 +22,10 @@ DISTANCE_METRICS = [('resnik', 'Resnik'), ('jiang', 'Jiang & Conrath'), ('fussimeg', 'FuSSiMeG')] +GO_DATA_DIR = '/home/einarr/data' + +evidence = None + class GoTermView (gtk.Frame): def __init__(self): @@ -133,35 +137,29 @@ 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] + global evidence + f = open(GO_DATA_DIR + '/goa-condensed') + ev_codes = f.readline().split() + go_terms = [] + + lines = f.readlines() + m = zeros((len(lines), len(ev_codes))) + for i, l in enumerate(lines): + values = l.split() + go_terms.append(values[0]) + for j, v in enumerate(values[1:]): + m[i,j] = float(v.strip()) + + d = dataset.Dataset(m, + [['go-terms', go_terms], ['evidence', ev_codes]], + name='GO evidence') + + evidence = d + return [d] + class EvidenceCodeFrame(gtk.Frame): def __init__(self): @@ -249,8 +247,11 @@ class GoDistanceFunction(workflow.Function): workflow.Function.__init__(self, 'go-dist', 'GO term distance matrix') self.options = GoDistanceOptions() - def run(self, data): + def run(self, selection): self.options = self.show_gui(self.options) + if not selection.has_key('go-terms') or len(selection['go-terms']) == 0: + logger.log('warning', 'No GO terms selected. Cannot make distance matrix.') + def show_gui(self, options, edit=True): dialog = GoDistanceDialog()