annotate ensembl_rest.py @ 0:038ecf54cbec draft default tip

planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
author galaxyp
date Mon, 22 Jan 2018 13:59:27 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
1 #!/usr/bin/env python
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
2 """
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
3 #
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
4 #------------------------------------------------------------------------------
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
5 # University of Minnesota
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
6 # Copyright 2017, Regents of the University of Minnesota
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
7 #------------------------------------------------------------------------------
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
8 # Author:
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
9 #
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
10 # James E Johnson
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
11 #
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
12 #------------------------------------------------------------------------------
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
13 """
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
14
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
15 from __future__ import print_function
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
16 from __future__ import unicode_literals
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
17
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
18 import sys
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
19
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
20 from time import sleep
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
21
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
22 import requests
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
23
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
24
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
25 server = "https://rest.ensembl.org"
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
26 ext = "/info/assembly/homo_sapiens?"
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
27 max_region = 4000000
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
28 debug = False
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
29
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
30
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
31 def ensembl_rest(ext, headers):
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
32 if debug:
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
33 print("%s" % ext, file=sys.stderr)
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
34 r = requests.get(server+ext, headers=headers)
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
35 if r.status_code == 429:
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
36 print("response headers: %s\n" % r.headers, file=sys.stderr)
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
37 if 'Retry-After' in r.headers:
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
38 sleep(r.headers['Retry-After'])
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
39 r = requests.get(server+ext, headers=headers)
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
40 if not r.ok:
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
41 r.raise_for_status()
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
42 return r
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
43
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
44
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
45 def get_species():
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
46 results = dict()
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
47 ext = "/info/species"
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
48 req_header = {"Content-Type": "application/json"}
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
49 r = ensembl_rest(ext, req_header)
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
50 for species in r.json()['species']:
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
51 results[species['name']] = species
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
52 print("%s\t%s\t%s\t%s\t%s" %
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
53 (species['name'], species['common_name'],
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
54 species['display_name'],
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
55 species['strain'],
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
56 species['taxon_id']), file=sys.stdout)
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
57 return results
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
58
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
59
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
60 def get_biotypes(species):
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
61 biotypes = []
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
62 ext = "/info/biotypes/%s?" % species
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
63 req_header = {"Content-Type": "application/json"}
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
64 r = ensembl_rest(ext, req_header)
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
65 for entry in r.json():
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
66 if 'biotype' in entry:
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
67 biotypes.append(entry['biotype'])
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
68 return biotypes
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
69
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
70
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
71 def get_toplevel(species):
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
72 coord_systems = dict()
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
73 ext = "/info/assembly/%s?" % species
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
74 req_header = {"Content-Type": "application/json"}
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
75 r = ensembl_rest(ext, req_header)
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
76 toplevel = r.json()
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
77 for seq in toplevel['top_level_region']:
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
78 if seq['coord_system'] not in coord_systems:
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
79 coord_systems[seq['coord_system']] = dict()
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
80 coord_system = coord_systems[seq['coord_system']]
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
81 coord_system[seq['name']] = int(seq['length'])
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
82 return coord_systems
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
83
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
84
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
85 def get_transcripts_bed(species, refseq, start, length, strand='',
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
86 params=None):
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
87 bed = []
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
88 param = params if params else ''
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
89 req_header = {"Content-Type": "text/x-bed"}
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
90 regions = list(range(start, length, max_region))
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
91 if not regions or regions[-1] < length:
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
92 regions.append(length)
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
93 for end in regions[1:]:
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
94 ext = "/overlap/region/%s/%s:%d-%d%s?feature=transcript;%s"\
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
95 % (species, refseq, start, end, strand, param)
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
96 start = end + 1
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
97 r = ensembl_rest(ext, req_header)
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
98 if r.text:
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
99 bed += r.text.splitlines()
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
100 return bed
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
101
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
102
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
103 def get_seq(id, seqtype, params=None):
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
104 param = params if params else ''
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
105 ext = "/sequence/id/%s?type=%s;%s" % (id, seqtype, param)
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
106 req_header = {"Content-Type": "text/plain"}
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
107 r = ensembl_rest(ext, req_header)
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
108 return r.text
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
109
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
110
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
111 def get_cdna(id, params=None):
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
112 return get_seq(id, 'cdna', params=params)
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
113
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
114
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
115 def get_cds(id, params=None):
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
116 return get_seq(id, 'cds', params=params)
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
117
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
118
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
119 def get_genomic(id, params=None):
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
120 return get_seq(id, 'genomic', params=params)
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
121
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
122
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
123 def get_transcript_haplotypes(species, transcript):
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
124 ext = "/transcript_haplotypes/%s/%s?aligned_sequences=1"\
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
125 % (species, transcript)
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
126 req_header = {"Content-Type": "application/json"}
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
127 r = ensembl_rest(ext, req_header)
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
128 decoded = r.json()
038ecf54cbec planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/translate_bed commit 383bb485120a193bcc14f88364e51356d6ede219
galaxyp
parents:
diff changeset
129 return decoded