R/biolink_search_similar.R

Defines functions biolink_search_similar

Documented in biolink_search_similar

#' Calculate phenotypic similarity between set of terms
#' @param id ref_id
#' @param limit_rows limit_rows
#' @param taxon taxon
#' @param metric metric
#' @importFrom tibble as_tibble
#' @importFrom dplyr rename bind_cols
#' @importFrom httr user_agent modify_url GET


#' @rdname biolink_search_similar
#' @export 
biolink_search_similar <- function(id, limit_rows, taxon, metric) {
  
  # Check internet connection
  check_internet()
  
  if (!(metric %in% c('phenodigm', 'jaccard', 'simGIC', 'resnik', 'symmetric_resnik'))) {
    stop("Metric not found")
  }
  
  # Set user agent header

  names(id) <- rep('id', length(id))
  id <- as.list(id)

  metric <- list(metric = metric)

  args <- append(id, metric)
  
  url <- modify_url(base_url, path = paste0('api/', 'sim/search'))
  
  resp <- GET(url, user_agent = ua, query = args)
  
  check_response(resp)
  
  
  parsed <- jsonlite::fromJSON(content(resp, as = "text", encoding = 'UTF-8'), simplifyVector = TRUE)

  result_tbl <- parsed$matches %>% as_tibble()
  
  result_tbl

}
frequena/rbiolink documentation built on May 16, 2020, 10:20 p.m.