/
directEnsembl.py
94 lines (70 loc) · 2.71 KB
/
directEnsembl.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import json
import requests
import sys
from pprint import pprint
from requests.exceptions import HTTPError
## ----------------------------------------------------------------------------
def fetch_endpoint(server, request, content_type):
try:
print ( " *********************** " )
print ( " endpoint request: ", server+request )
r = requests.get(server+request, headers={"Content-Type":content_type})
print ( r )
print ( " *********************** " )
r.raise_for_status()
except HTTPError as http_err:
print ( 'HTTP error occurred: {http_err}' )
except Exception as err:
print ( 'Other error occurred: {err}' )
else:
print ( 'successful request!')
if content_type == 'application/json':
return r.json()
else:
return r.text
## ----------------------------------------------------------------------------
## this is one of their published examples, which I don't really understand
if ( 0 ):
server = "http://rest.ensembl.org/"
ext = "lookup/id/TraesCS3D02G007500?"
con = "application/json"
r = fetch_endpoint(server, ext, con)
pprint ( r )
## how about BRAF?
if ( 0 ):
server = "http://rest.ensembl.org/"
ext = "lookup/symbol/homo_sapiens/BRAF?"
con = "application/json"
r = fetch_endpoint(server, ext, con)
pprint ( r )
## here is a variant call in torrent_results:
## _locus chr7:140494203
## chrom chr7 'chr'+r['seq_region_name']
## position 140494203
## snpeff_annotated_dna_change c.1045G>T
## snpeff_annotated_gene BRAF r['display_name']
## snpeff_annotated_protein_change p.Ala349Ser
## snpeff_annotated_transcript NM_004333.4 r['id']=ENSG00000157764 r['version']=8
## ref C
## unique_mut_identifier chr7:140494203:A
## r['strand']=-1
## how about BRAF on GRCh37?
if ( 0 ):
server = "http://grch37.rest.ensembl.org/"
ext = "lookup/symbol/homo_sapiens/BRAF?"
con = "application/json"
r = fetch_endpoint(server, ext, con)
pprint ( r )
if ( 1 ):
server = "http://grch37.rest.ensembl.org/"
ext = "vep/homo_sapiens/hgvs/BRAF:c.1045G>T?"
con = "application/json"
r = fetch_endpoint(server, ext, con)
pprint ( r )
if ( 0 ):
## this works for the GRCh38 endpoint ...
server = "http://rest.ensembl.org/"
ext = "variant_recoder/human/BRAF:c.1045G>T?"
con = "application/json"
r = fetch_endpoint(server, ext, con)
pprint ( r )