R/map_identifiers.R

mapIdentifiers <- function(source_ids,
                source_bioelement = c("gene", "protein", "transcript", "genesymbol"),
			          source_datasource = c("ncbigene", "ensembl","uniprot", "refseq", "-"),
                target_bioelement = c("gene", "protein", "transcript", "genesymbol"),
                target_datasource = c("ncbigene", "ensembl", "uniprot", "refseq", "-")) {

  source_datasource <- match.arg(source_datasource)
  source_bioelement <- match.arg(source_bioelement)
  target_bioelement <- match.arg(target_bioelement)
  target_datasource <- match.arg(target_datasource)

  url <- "https://petesis.com"
  path <- "/api/v0.1/{source_datasource}/{source_bioelement}/-/relations"
  parameters <- list(targetBioelement = target_bioelement, targetDatasource = target_datasource, withPath = TRUE)

  raw_result <- POST(url = url, path = glue(path), query = parameters, body = toJSON(list(ids = source_ids)),
                     content_type_json(), accept("application/x.biomapr+json"))
  stop_for_status(raw_result, "get response")

  data <- fromJSON(content(raw_result, encoding = "UTF-8", as = "text", type = "application/json"))

  #handle empty dataframe
  if(class(data) == "data.frame" && (nrow(data) == 1 && sum(is.na(data)) == ncol(data))){
     data <- data[-1,]
  }
  data
}
icb-knowing/biomapr documentation built on May 25, 2019, 6:22 p.m.