Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into 8-integrate-tidyverse…
Browse files Browse the repository at this point in the history
…-styling
  • Loading branch information
rbasu101 committed Oct 17, 2024
2 parents 6956b93 + f535657 commit 1028506
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions dgidb.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,10 @@ library(tidyverse)
library(data.table)
library(httr)

api_url <- function(env = "local") {
url <- "http://localhost:3000/api/graphql"
if (env == "local") {
url <- "http://localhosst:3000/api/graphql"
}
if (env == "staging") {
url <- "https://staging.dgidb.org/api/graphql"
}
return(url)
}

base_url <- api_url("staging")
api_endpoint_url <- Sys.getenv(
"DGIDB_API_URL",
unset = "https://dgidb.org/api/graphql"
)

get_interactions <- function(
terms,
Expand Down Expand Up @@ -46,7 +38,7 @@ get_interactions <- function(
stop("Search type must be specified using: search='drugs' or search='genes'") # nolint: line_length_linter.
}

r <- POST(base_url, body = list(query = query), encode = "json")
r <- POST(api_endpoint_url, body = list(query = query), encode = "json")
data <- content(r)$data

if (use_processing == TRUE) {
Expand Down Expand Up @@ -196,7 +188,7 @@ process_drug <- function(data) {

get_gene_list <- function() {
query <- "{\ngenes {\nnodes {\nname\n}\n}\n}"
r <- POST(base_url, body = list(query = query), encode = "json")
r <- POST(api_endpoint_url, body = list(query = query), encode = "json")
gene_list <- list()
raw_nodes <- content(r)$data$genes$nodes
for (i in seq_along(raw_nodes)) {
Expand All @@ -211,7 +203,7 @@ get_drug_applications <- function(terms, use_processing = TRUE) {
terms <- paste0("[\"", paste(toupper(terms), collapse = "\",\""), "\"]")
query <- paste0("{\ndrugs(names: ", terms, ") {\nnodes{\nname \ndrugApplications {\nappNo\n}\n}\n}\n}\n") # nolint: line_length_linter.

r <- POST(base_url, body = list(query = query), encode = "json")
r <- POST(api_endpoint_url, body = list(query = query), encode = "json")
data <- content(r)

if (use_processing == TRUE) {
Expand Down

0 comments on commit 1028506

Please sign in to comment.