-
Notifications
You must be signed in to change notification settings - Fork 0
/
ens_homolog_pan.py
38 lines (31 loc) · 1.23 KB
/
ens_homolog_pan.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
import requests, sys
def get_homolog(gene_id):
"""get all homolog from Ensembl REST API"""
server = "https://rest.ensembl.org"
ext = "/homology/id/" + gene_id + "?compara=pan_homology"
r = requests.get(server + ext, headers = {'Content-Type': 'application/json'})
if not r.ok:
r.raise_for_status()
sys.exit()
decoded = r.json()
for homolog in decoded['data'][0]['homologies']:
out = [homolog['type'],
homolog['taxonomy_level'],
homolog['target']['species'],
homolog['target']['taxon_id'],
homolog['target']['id'],
homolog['target']['protein_id'],
homolog['target']['perc_pos'],
homolog['target']['perc_id'],
homolog['target']['cigar_line'],
homolog['target']['align_seq'],
homolog['source']['id'],
homolog['source']['protein_id'],
homolog['source']['perc_pos'],
homolog['source']['perc_id'],
homolog['source']['cigar_line'],
homolog['source']['align_seq']]
print('\t'.join(str(i) for i in out))
return
if __name__ == '__main__':
get_homolog(sys.argv[1])