-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathfind_genes_with_GO_Parents.py
More file actions
44 lines (35 loc) · 1.28 KB
/
find_genes_with_GO_Parents.py
File metadata and controls
44 lines (35 loc) · 1.28 KB
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
#!/usr/bin/env python3
import sys
import pronto
GO_GENES = sys.argv[1]
MY_GO_ID = sys.argv[2]
# create an object of class Ontology with the GO ontology
ont = pronto.Ontology('/Users/smr/Desktop/PFB2017/pfb2017/files/go.owl')
# get the term name of the provided GO ID
term_obj = ont[MY_GO_ID]
term_name = term_obj.name
print("These genes have all been annotated with" , MY_GO_ID + ', "' + term_name + '" or any of its child terms' )
# add the parent GO ID to dictionary of IDs to search for
all_children={}
all_children[MY_GO_ID] = term_name
# add all children of the parent term to dictionary
for child in ont[MY_GO_ID].rchildren():
all_children[child.id] = child.name
# open genes file and add gene names and their annotatoted GO terms to a dictionary
genes = {}
file = open(GO_GENES , "r")
for line in file:
line = line.rstrip()
columns = line.split("\t")
# if a gene does not have a GO term annotation, skip it
if len(columns) == 3:
(gene_id , go_id, go_name) = columns
if go_id in all_children:
genes[gene_id] = go_id
# print out all the genes that are of the GO ID you provided as well as any of its children
for gene in genes:
go_id = genes[gene]
go_id_obj = ont[go_id]
go_name = go_id_obj.name
output = "\t".join( [gene,go_id,go_name] )
print(output)