Resnik distances between GO terms work now.
This commit is contained in:
@@ -118,6 +118,7 @@ class GoWorkflow (workflow.Workflow):
|
||||
self.add_stage(load)
|
||||
|
||||
go = workflow.Stage('go', 'Gene Ontology')
|
||||
go.add_function(SelectGoTermsFunction(self))
|
||||
go.add_function(GoDistanceFunction())
|
||||
self.add_stage(go)
|
||||
|
||||
@@ -269,11 +270,36 @@ class NumericDict(dict):
|
||||
retval = 0.0
|
||||
return retval
|
||||
|
||||
|
||||
class SelectGoTermsFunction(workflow.Function):
|
||||
def __init__(self, wf):
|
||||
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']))
|
||||
|
||||
|
||||
class GoDistanceFunction(workflow.Function):
|
||||
def __init__(self):
|
||||
workflow.Function.__init__(self, 'go-dist', 'GO term distance matrix')
|
||||
self.options = GoDistanceOptions()
|
||||
|
||||
def resnik_distance_matrix(self, selection, ic):
|
||||
size = len(selection['go-terms'])
|
||||
m = zeros((size, size))
|
||||
# Create resnik distance matrix
|
||||
ids = list(selection['go-terms'])
|
||||
for i, t1 in enumerate(ids):
|
||||
for j, t2 in enumerate(ids):
|
||||
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[subsumer['id']] - ic[t1] + ic[subsumer['id']] - ic[t2]
|
||||
ds = dataset.Dataset(m, (('go-terms', ids), ('_go-terms', ids)), 'Resnik')
|
||||
return ds
|
||||
|
||||
def run(self, x, selection):
|
||||
global evidence, go
|
||||
self.options = self.show_gui(self.options)
|
||||
@@ -288,22 +314,21 @@ class GoDistanceFunction(workflow.Function):
|
||||
annotations = NumericDict()
|
||||
ic = NumericDict()
|
||||
|
||||
# Insert annotations into dict
|
||||
for i, v in enumerate(evidence.get_identifiers('go-terms')):
|
||||
annotations[v] = ann_count_matrix[i]
|
||||
|
||||
# Accumulate annotations
|
||||
for term in reversed(networkx.topological_sort(go)):
|
||||
for parent in go.in_neighbors(term):
|
||||
annotations[parent['id']] += annotations[term['id']]
|
||||
print "%s -> %s (%s)" % (term['id'], parent['id'], annotations[parent['id']])
|
||||
# print "%s -> %s (%s)" % (term['id'], parent['id'], annotations[parent['id']])
|
||||
|
||||
# Create information content dictionary
|
||||
for i, v in enumerate(evidence.get_identifiers('go-terms')):
|
||||
annotations[v] = ann_count_matrix[i]
|
||||
ic[v] = -log(ann_count_matrix[i] / total_ann)
|
||||
|
||||
# # Create resnik distance matrix
|
||||
# for t1 in selection['go-terms']:
|
||||
# for t2 in selection['go-terms']:
|
||||
|
||||
|
||||
return [self.resnik_distance_matrix(selection, ic)]
|
||||
|
||||
def show_gui(self, options, edit=True):
|
||||
dialog = GoDistanceDialog()
|
||||
|
Reference in New Issue
Block a user