Skip to content

Instantly share code, notes, and snippets.

@egonw
Created June 21, 2018 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save egonw/3b10da2b783c86f9aff8dd3677bf430a to your computer and use it in GitHub Desktop.
Save egonw/3b10da2b783c86f9aff8dd3677bf430a to your computer and use it in GitHub Desktop.
library(jsonlite)
library("curl")
mapUriService = "http://localhost:8081/QueryExpander/mapUri"
# gene to variants
gene = "http://rdf.ebi.ac.uk/resource/ensembl/ENSG00000198947"
targetUriPattern = "http://identifiers.org/dbsnp"
h <- new_handle()
handle_setopt(h, customrequest = "POST")
handle_setform(h, Uri=gene, format = "application/json", targetUriPattern = targetUriPattern)
r <- curl_fetch_memory(mapUriService, h)
jsonReply = rawToChar(r$content)
data = fromJSON(jsonReply)
variantCount = length(data$Mapping$targetUri)
head(data$Mapping$targetUri)
# variants to gene
gene = "http://identifiers.org/dbsnp/rs769658853"
targetUriPattern = "http://identifiers.org/ensembl"
h <- new_handle()
handle_setopt(h, customrequest = "POST")
handle_setform(h, Uri=gene, format = "application/json", targetUriPattern = targetUriPattern)
r <- curl_fetch_memory(mapUriService, h)
jsonReply = rawToChar(r$content)
data = fromJSON(jsonReply)
gene = data$Mapping$targetUri
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment