-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added gene utils to formats, a convenience module for obtaining infor…
…mation about genes
- Loading branch information
Showing
5 changed files
with
64 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
""" Formats submodule contains classes and functions | ||
to parse various formats into pandas dataframes as | ||
well as lookup utilities to various formats | ||
""" | ||
|
||
from .gene_utils import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
""" | ||
""" | ||
|
||
import json | ||
import requests | ||
import gzip | ||
|
||
|
||
def get_symbol_ensembl(ensembl): | ||
"""Get symbol from ensembl ID from | ||
ensembl REST API | ||
""" | ||
|
||
server = "http://rest.ensembl.org" | ||
ext = "/lookup/id/{0}?expand=1" | ||
r = requests.get(server + ext.format(str(ensembl)), | ||
headers={ "Content-Type" : "application/json"}) | ||
if not r.ok: | ||
return('NA') | ||
else: | ||
decoded = r.json() | ||
try: | ||
return(decoded['display_name']) | ||
except KeyError: | ||
return('NA') | ||
|
||
|
||
def grab_gene_location(id, ann_file = None, cis_buffer=0): | ||
""" Grab the gene boundries as a tuple buffered by | ||
cis_buffer | ||
returns (chr, pos0, pos1) | ||
""" | ||
|
||
if ann_file: | ||
with gzip.open(ann_file) as annot: | ||
for line in annot: | ||
if id in line: | ||
line = line.split("\t") | ||
return(line[0], int(line[1]) - cis_buffer, | ||
int(line[2]) + cis_buffer, str(line[4])) | ||
else: | ||
raise NotImplementedError | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters