Created
September 3, 2019 16:49
-
-
Save vjcitn/7295067e6592213823c28b9421eb5fdc to your computer and use it in GitHub Desktop.
function to use ensembl API to convert rsid to hg38 coordinates ... note the seqnames
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
get_rslocs_38 = function(rsids = c("rs6060535", "rs56116432")) { | |
server <- "https://rest.ensembl.org" | |
ext <- "/variant_recoder/homo_sapiens" | |
r <- httr::POST(paste(server, ext, sep = ""), | |
httr::content_type("application/json"), | |
httr::accept("application/json"), | |
body = list(ids=rsids), encode="json") | |
httr::stop_for_status(r) | |
ans = rjson::fromJSON( rjson::toJSON( httr::content(r))) | |
ids = lapply(ans, "[[", "id") | |
spd = sapply(lapply(ans, "[[", "spdi"), "[", 1) | |
sspd = strsplit(spd, ":") | |
chrs = sapply(sspd, "[", 1) | |
locs = as.numeric(sapply(sspd, "[", 2))+1 | |
ans = GenomicRanges::GRanges(chrs, IRanges::IRanges(locs, width=1)) | |
GenomeInfoDb::genome(ans) = "GRCh38" | |
names(ans) = ids | |
ans | |
} |
Author
vjcitn
commented
Sep 3, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment