forked from emreg00/toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_amigo.py
48 lines (39 loc) · 1.82 KB
/
parse_amigo.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
import parse_ncbi, parse_uniprot
def main():
mapping_file = "/home/emre/data/uniprot/idmapping.tab"
uniprot_to_geneid = parse_uniprot.get_uniprot_to_geneid(mapping_file, uniprot_ids=None)
file_name = "/home/emre/data/tissue/amigo_extracellular.tsv"
#file_name = "/home/emre/data/tissue/amigo_membrane.tsv"
geneid_to_localization = get_geneid_to_localization(file_name, mapping_file)
print geneid_to_localization["5594"] # MAPK1
return
def get_geneid_to_localization(file_name, mapping_file):
name_to_geneid = parse_uniprot.get_uniprot_to_geneid(mapping_file, uniprot_ids=None)
geneid_to_localization = {}
uniprots_unmatched = set()
for line in open(file_name):
words = line.strip("\n").split("\t")
uniprot, go, evidence = words[0], words[3], words[7]
idx = uniprot.find(":")
uniprot = uniprot[idx+1:]
#if evidence not in ("EXP", "IDA", "IPA", "IMP", "IGI", "IEP", "HDA"):
# continue
if uniprot in name_to_geneid:
geneid = name_to_geneid[uniprot]
else:
#print "Unmatched id", uniprot
if not uniprot.startswith("URS"):
uniprots_unmatched.add(uniprot)
continue
# Store evidence type as well
geneid_to_localization.setdefault(geneid, set()).add((go, evidence))
print "Unmatched:", len(uniprots_unmatched) #, ", ".join(sorted(uniprots_unmatched))
return geneid_to_localization
def get_geneid_to_extracellular_localization(file_name_membrane, file_name_secreted, mapping_file):
geneid_to_localization = get_geneid_to_localization(file_name_membrane, mapping_file)
geneid_to_localization2 = get_geneid_to_localization(file_name_extracellular, mapping_file)
for geneid, localization in geneid_to_localization2.iteritems():
geneid_to_localization.setdefault(geneid, set()).add(localization)
return geneid_to_localization
if __name__ == "__main__":
main()