From 58886726d8ec2a940ff5c12cbe9f606bd45db497 Mon Sep 17 00:00:00 2001 From: einarr Date: Fri, 12 Jan 2007 10:50:55 +0000 Subject: [PATCH] Small updates. --- workflows/geneontology.py | 24 ++++++++++++++++++++++++ workflows/go_workflow.py | 15 +++++++++++---- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/workflows/geneontology.py b/workflows/geneontology.py index 6fc8f54..977cc9f 100644 --- a/workflows/geneontology.py +++ b/workflows/geneontology.py @@ -61,7 +61,29 @@ class GeneOntology(networkx.XDiGraph): """Returns the root node of the molecular_function tree""" return self.by_id['GO:0003674'] + def _subsumer(self, t1, t2, heap): + while heap != []: + t = heap[0] + heap = heap[1:] + + p1 = networkx.shortest_path(self, t, t1) + p2 = networkx.shortest_path(self, t, t2) + if p1 and p2: + return t + + heap += self.in_neighbors(t) + return None + def subsumer(self, t1, t2): + if t1 == t2: + return t1 + if networkx.shortest_path(self, t1, t2): + return t1 + elif networkx.shortest_path(self, t2, t1): + return t2 + return self._subsumer(t1, t2, self.in_neighbors(t1)) + + def old_subsumer(self, t1, t2): if t1 == t2: return t1 @@ -83,6 +105,8 @@ class GeneOntology(networkx.XDiGraph): return t print "GeneOntology.subsumer: should not reach this point" + print "path is now: %s" % path + print "ids are: %s " % [x['id'] for x in path] def _split_obo_line(line): """Splits a line from an obo file in its three constituent parts. diff --git a/workflows/go_workflow.py b/workflows/go_workflow.py index 9875c9e..2b19553 100644 --- a/workflows/go_workflow.py +++ b/workflows/go_workflow.py @@ -277,8 +277,11 @@ class SelectGoTermsFunction(workflow.Function): workflow.Function.__init__(self, 'go-select', 'Select GO Terms') self.wf = wf - def run(self): - self.wf.project.set_selection('go-terms', set(['GO:0007582', 'GO:0008150', 'GO:0051704', 'GO:0044419'])) + def run(self, ds): + terms = [x['id'] for x in networkx.paths.bfs(go, go.get_bp())] + + self.wf.project.set_selection('go-terms', set(terms[:100])) +# self.wf.project.set_selection('go-terms', set(['GO:0007582', 'GO:0008150', 'GO:0051704', 'GO:0044419'])) class GoDistanceFunction(workflow.Function): @@ -296,8 +299,12 @@ class GoDistanceFunction(workflow.Function): term1 = go.by_id[t1] term2 = go.by_id[t2] subsumer = go.subsumer(term1, term2) - print "%s - %s - %s" % (t1, subsumer['id'], t2) - m[i, j] = ic[t1] + ic[t2] - 2.0 * ic[subsumer['id']] + + if subsumer == None: + m[i, j] = 1000 + else: +# print "%s - %s - %s" % (t1, subsumer['id'], t2) + m[i, j] = ic[t1] + ic[t2] - 2.0 * ic[subsumer['id']] ds = dataset.Dataset(m, (('go-terms', ids), ('_go-terms', ids)), 'Resnik') return ds