Updated go-workflow.
This commit is contained in:
@@ -26,6 +26,7 @@ DISTANCE_METRICS = [('resnik', 'Resnik'),
|
||||
GO_DATA_DIR = '/home/einarr/data'
|
||||
|
||||
evidence = None
|
||||
go = None
|
||||
|
||||
class GoTermView (gtk.Frame):
|
||||
|
||||
@@ -137,11 +138,14 @@ class LoadGOFunction(workflow.Function):
|
||||
class LoadTextDatasetFunction(workflow.Function):
|
||||
|
||||
def __init__(self):
|
||||
workflow.Function.__init__(self, 'load-text-ds', 'Load text dataset')
|
||||
workflow.Function.__init__(self, 'load-text-ds', 'Load GO Evidence')
|
||||
|
||||
def run(self):
|
||||
f = open('/home/einarr/data/goa-condensed.ftsv')
|
||||
return [dataset.read_ftsv(f)]
|
||||
|
||||
global evidence
|
||||
evidence = dataset.read_ftsv(f)
|
||||
return [evidence]
|
||||
|
||||
|
||||
class LoadAnnotationsFunction(workflow.Function):
|
||||
|
||||
@@ -253,17 +257,54 @@ class GoDistanceDialog(gtk.Dialog):
|
||||
self._metric_frame.set_sensitive(editable)
|
||||
|
||||
|
||||
class NumericDict(dict):
|
||||
def __init__(self):
|
||||
dict.__init__(self)
|
||||
|
||||
def __getitem__(self, key):
|
||||
retval = 0
|
||||
try:
|
||||
retval = dict.__getitem__(self, key)
|
||||
except:
|
||||
retval = 0.0
|
||||
return retval
|
||||
|
||||
class GoDistanceFunction(workflow.Function):
|
||||
def __init__(self):
|
||||
workflow.Function.__init__(self, 'go-dist', 'GO term distance matrix')
|
||||
self.options = GoDistanceOptions()
|
||||
|
||||
def run(self, selection):
|
||||
def run(self, x, selection):
|
||||
global evidence, go
|
||||
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.')
|
||||
|
||||
codes = [c for c, d in EVIDENCE_CODES if self.options[c]]
|
||||
ev_indices = evidence.get_indices('evidence', codes)
|
||||
ann_count_matrix = evidence._array[:, ev_indices].sum(1)
|
||||
total_ann = ann_count_matrix.sum(0)
|
||||
|
||||
annotations = NumericDict()
|
||||
ic = NumericDict()
|
||||
|
||||
# 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']])
|
||||
|
||||
# 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']:
|
||||
|
||||
|
||||
|
||||
def show_gui(self, options, edit=True):
|
||||
dialog = GoDistanceDialog()
|
||||
dialog.set_options(self.options)
|
||||
|
Reference in New Issue
Block a user