-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·62 lines (50 loc) · 2.04 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
'''
Created on 2010-07-19
@author: Shobhit Jain
@contact: [email protected]
'''
from ontology import GOGraph
def load_semantic_similarity(ontology_file, gene_file, ontology, code):
'''
Calls functions for loading and processing data.
'''
objs = {}
ontology = ontology.split(",")
g = GOGraph()
print("loading data.............")
g._obo_parser(ontology_file)
g._go_annotations(gene_file, code)
print("processing data..........(takes time)")
run = {'C':g._cellular_component, 'P':g._biological_process, 'F':g._molecular_function}
ont = {'C':"Cellular Component", 'P':"Biological Process", 'F':"Molecular Function"}
for i in ontology:
i = i.split(":")
print("working with %s ontology....."%ont[i[0]])
objs[i[0]] = run[i[0]]()
objs[i[0]]._species()
objs[i[0]]._clustering(float(i[1]))
return objs
def return_detail(result, geneA, geneB, detail):
'''
Formats the output for printing on screen or on file.
'''
domain_def = {'C':'Cellular Component', 'P':'Biological Process', 'F':'Molecular Function'}
r = "\nSemantic similarity between " + geneA + " and " + geneB + " is:\n\n"
for domain in result:
r += " " + domain_def[domain] + ": " + str(result[domain][0]) + "\n"
if detail:
for data in result[domain][1]:
r += " GO id assigned to " + geneA + " is: " + data[0] + \
"\n GO id assigned to " + geneB + " is: " + data[1] + \
"\n LCA of assigned GO ids is: " + "|".join(result[domain][1][data]['lca']) + "\n\n"
return r + "\n\n\n"
def calculate_semantic_similarity(objs, geneA, geneB, detail):
'''
Calls the function for calculating semantic similarity between
genesA and genesB.
'''
result = {}
for domain in objs:
result[domain] = objs[domain]._semantic_similarity(geneA, geneB)
return return_detail(result, geneA, geneB, detail)
#cc._semantic_similarity('S000004065', 'S000001451')