This commit is contained in:
2007-07-20 12:32:54 +00:00
parent 7ee7aa968a
commit 98f53d3448
4 changed files with 33 additions and 14 deletions

View File

@@ -45,7 +45,7 @@ def goterms_from_gene(genelist, ontology=['BP'], garbage = ['IEA', 'ISS', 'ND'])
_ONTOLOGIES = ['BP', 'CC', 'MF']
assert(scipy.all([(code in _CODES) for code in garbage]))
assert(scipy.all([(ont in _ONTOLOGIES) for ont in ontology]))
have_these = rpy.r('as.list(GOTERM)').keys()
goterms = {}
for gene in genelist:
goterms[gene] = []
@@ -53,8 +53,12 @@ def goterms_from_gene(genelist, ontology=['BP'], garbage = ['IEA', 'ISS', 'ND'])
#print info
if info:
for term, desc in info.items():
if term not in have_these:
print "GO miss:"
print term
if desc['Ontology'] in ontology and desc['Evidence'] not in garbage:
goterms[gene].append(term)
return goterms
def genego_matrix(goterms, tmat, gene_ids, term_ids, func=min):
@@ -97,7 +101,12 @@ def goterm2desc(gotermlist):
return term2desc
def parents_dag(go_terms, ontology=['BP']):
""" Returns a list of lists representation of a GO DAG parents of goterms."""
""" Returns a list of lists representation of a GO DAG parents of goterms.
make the networkx graph by:
G = networkx.Digraph()
G = networkx.from_dict_of_lists(edge_dict, G)
"""
try:
rpy.r.library("GOstats")
except:
@@ -105,6 +114,11 @@ def parents_dag(go_terms, ontology=['BP']):
assert(go_terms[0][:3]=='GO:')
# go valid namespace
go_env = {'BP':rpy.r.BPPARENTS, 'MF':rpy.r.MFPARENTS, 'CC': rpy.r.CCPARENTS}
go_env = {'BP':rpy.r.GOBPPARENTS, 'MF':rpy.r.GOMFPARENTS, 'CC': rpy.r.GOCCPARENTS}
graph = rpy.r.GOGraph(go_terms, go_env[ontology[0]])
edges = rpy.r.edges(graph)
edges.pop('all')
edge_dict = {}
for head, nei in edges.items():
edge_dict[head] = nei.values()
return edge_dict