This is a general purpose function to send data request which can be used when there has not been an R equivalent package function to an API endpoint. Underneath this is a wrapper around httr functions with better handling of returned status.

query_epigraphdb(
  route,
  params = NULL,
  mode = c("raw", "table"),
  method = c("GET", "POST"),
  retry_times = 5,
  retry_pause_min = 4
)

Arguments

route

An EpiGraphDB API endpoint route, e.g. "/mr" or "/confounder". Consult the EpiGraphDB API documentation.

params

A list of parameters associated with the query endpoint.

mode

c("raw", "table"), if "table" then the query handler will try to convert the returned data to a tibble dataframe. NOTE: The default mode is "raw" which will NOT convert the returned response to a dataframe. This is different to functions that query topic endpoints which default to return a dataframe. Explicitly specify mode = "table" when needed.

method

Type of HTTP (GET, POST, PUT, etc.) method.

NOTE: When sending a POST request where a specific parameter is specified as a list on the API, and if the equivalent in R is a vector of length 1, you should wrap this parameter in I(), e.g. I(c("APOE")) to avoid auto unboxing. For details, please refer to httr::POST

retry_times

Number of times the function will retry the request to the API.

retry_pause_min

Minimum number of seconds to wait for the next retry.

Value

Data from an EpiGraphDB API endpoint.

Examples

# GET /mr # equivalent to `mr(exposure_trait = "Body mass index", outcome_trait = "Coronary heart disease")` query_epigraphdb( route = "/mr", params = list( exposure_trait = "Body mass index", outcome_trait = "Coronary heart disease" ), mode = "table" )
#> # A tibble: 6 x 10 #> exposure.id exposure.trait outcome.id outcome.trait mr.b mr.se mr.pval #> <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl> #> 1 ieu-a-974 Body mass ind… ieu-a-7 Coronary hea… 0.389 0.0493 3.42e-15 #> 2 ieu-a-2 Body mass ind… ieu-a-7 Coronary hea… 0.397 0.0727 4.79e- 8 #> 3 ieu-a-95 Body mass ind… ieu-a-7 Coronary hea… 0.455 0.0931 1.02e- 6 #> 4 ieu-a-2 Body mass ind… ieu-a-8 Coronary hea… 0.331 0.0684 1.31e- 6 #> 5 ieu-a-835 Body mass ind… ieu-a-7 Coronary hea… 0.360 0.0756 1.94e- 6 #> 6 ieu-a-974 Body mass ind… ieu-a-8 Coronary hea… 0.328 0.0731 6.97e- 6 #> # … with 3 more variables: mr.method <chr>, mr.selection <chr>, #> # mr.moescore <dbl>
# GET /meta/nodes/Gwas/list query_epigraphdb( route = "/meta/nodes/Gwas/list", params = list( limit = 5, offset = 0 ) ) %>% str(1)
#> List of 2 #> $ metadata:List of 3 #> $ results :List of 5
# POST /protein/ppi query_epigraphdb( route = "/protein/ppi", params = list( uniprot_id_list = c("P30793", "Q9NZM1", "O95236") ), method = "POST" )
#> $metadata #> $metadata$query #> [1] "MATCH p=(protein:Protein)-[r:STRING_INTERACT_WITH]-(assoc_protein:Protein) WHERE protein.uniprot_id IN ['P30793', 'Q9NZM1', 'O95236'] RETURN protein {.uniprot_id}, assoc_protein {.uniprot_id}" #> #> $metadata$total_seconds #> [1] 0.010093 #> #> $metadata$empty_results #> [1] FALSE #> #> #> $results #> $results[[1]] #> $results[[1]]$protein #> $results[[1]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[1]]$assoc_protein #> $results[[1]]$assoc_protein$uniprot_id #> [1] "P00439" #> #> #> #> $results[[2]] #> $results[[2]]$protein #> $results[[2]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[2]]$assoc_protein #> $results[[2]]$assoc_protein$uniprot_id #> [1] "Q5TCS8" #> #> #> #> $results[[3]] #> $results[[3]]$protein #> $results[[3]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[3]]$assoc_protein #> $results[[3]]$assoc_protein$uniprot_id #> [1] "O14638" #> #> #> #> $results[[4]] #> $results[[4]]$protein #> $results[[4]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[4]]$assoc_protein #> $results[[4]]$assoc_protein$uniprot_id #> [1] "P20711" #> #> #> #> $results[[5]] #> $results[[5]]$protein #> $results[[5]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[5]]$assoc_protein #> $results[[5]]$assoc_protein$uniprot_id #> [1] "O43556" #> #> #> #> $results[[6]] #> $results[[6]]$protein #> $results[[6]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[6]]$assoc_protein #> $results[[6]]$assoc_protein$uniprot_id #> [1] "P00374" #> #> #> #> $results[[7]] #> $results[[7]]$protein #> $results[[7]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[7]]$assoc_protein #> $results[[7]]$assoc_protein$uniprot_id #> [1] "P22392" #> #> #> #> $results[[8]] #> $results[[8]]$protein #> $results[[8]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[8]]$assoc_protein #> $results[[8]]$assoc_protein$uniprot_id #> [1] "P05187" #> #> #> #> $results[[9]] #> $results[[9]]$protein #> $results[[9]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[9]]$assoc_protein #> $results[[9]]$assoc_protein$uniprot_id #> [1] "P22102" #> #> #> #> $results[[10]] #> $results[[10]]$protein #> $results[[10]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[10]]$assoc_protein #> $results[[10]]$assoc_protein$uniprot_id #> [1] "P07101" #> #> #> #> $results[[11]] #> $results[[11]]$protein #> $results[[11]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[11]]$assoc_protein #> $results[[11]]$assoc_protein$uniprot_id #> [1] "Q9BY32" #> #> #> #> $results[[12]] #> $results[[12]]$protein #> $results[[12]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[12]]$assoc_protein #> $results[[12]]$assoc_protein$uniprot_id #> [1] "O95197" #> #> #> #> $results[[13]] #> $results[[13]]$protein #> $results[[13]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[13]]$assoc_protein #> $results[[13]]$assoc_protein$uniprot_id #> [1] "P50583" #> #> #> #> $results[[14]] #> $results[[14]]$protein #> $results[[14]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[14]]$assoc_protein #> $results[[14]]$assoc_protein$uniprot_id #> [1] "P05186" #> #> #> #> $results[[15]] #> $results[[15]]$protein #> $results[[15]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[15]]$assoc_protein #> $results[[15]]$assoc_protein$uniprot_id #> [1] "Q05932" #> #> #> #> $results[[16]] #> $results[[16]]$protein #> $results[[16]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[16]]$assoc_protein #> $results[[16]]$assoc_protein$uniprot_id #> [1] "Q5MY95" #> #> #> #> $results[[17]] #> $results[[17]]$protein #> $results[[17]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[17]]$assoc_protein #> $results[[17]]$assoc_protein$uniprot_id #> [1] "Q9BX66" #> #> #> #> $results[[18]] #> $results[[18]]$protein #> $results[[18]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[18]]$assoc_protein #> $results[[18]]$assoc_protein$uniprot_id #> [1] "P49961" #> #> #> #> $results[[19]] #> $results[[19]]$protein #> $results[[19]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[19]]$assoc_protein #> $results[[19]]$assoc_protein$uniprot_id #> [1] "P16066" #> #> #> #> $results[[20]] #> $results[[20]]$protein #> $results[[20]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[20]]$assoc_protein #> $results[[20]]$assoc_protein$uniprot_id #> [1] "Q9NP79" #> #> #> #> $results[[21]] #> $results[[21]]$protein #> $results[[21]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[21]]$assoc_protein #> $results[[21]]$assoc_protein$uniprot_id #> [1] "Q9Y5B8" #> #> #> #> $results[[22]] #> $results[[22]]$protein #> $results[[22]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[22]]$assoc_protein #> $results[[22]]$assoc_protein$uniprot_id #> [1] "P22413" #> #> #> #> $results[[23]] #> $results[[23]]$protein #> $results[[23]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[23]]$assoc_protein #> $results[[23]]$assoc_protein$uniprot_id #> [1] "P51841" #> #> #> #> $results[[24]] #> $results[[24]]$protein #> $results[[24]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[24]]$assoc_protein #> $results[[24]]$assoc_protein$uniprot_id #> [1] "O00746" #> #> #> #> $results[[25]] #> $results[[25]]$protein #> $results[[25]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[25]]$assoc_protein #> $results[[25]]$assoc_protein$uniprot_id #> [1] "Q13232" #> #> #> #> $results[[26]] #> $results[[26]]$protein #> $results[[26]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[26]]$assoc_protein #> $results[[26]]$assoc_protein$uniprot_id #> [1] "P35270" #> #> #> #> $results[[27]] #> $results[[27]]$protein #> $results[[27]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[27]]$assoc_protein #> $results[[27]]$assoc_protein$uniprot_id #> [1] "Q96PE7" #> #> #> #> $results[[28]] #> $results[[28]]$protein #> $results[[28]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[28]]$assoc_protein #> $results[[28]]$assoc_protein$uniprot_id #> [1] "O75298" #> #> #> #> $results[[29]] #> $results[[29]]$protein #> $results[[29]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[29]]$assoc_protein #> $results[[29]]$assoc_protein$uniprot_id #> [1] "P17752" #> #> #> #> $results[[30]] #> $results[[30]]$protein #> $results[[30]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[30]]$assoc_protein #> $results[[30]]$assoc_protein$uniprot_id #> [1] "Q9NVV9" #> #> #> #> $results[[31]] #> $results[[31]]$protein #> $results[[31]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[31]]$assoc_protein #> $results[[31]]$assoc_protein$uniprot_id #> [1] "Q02846" #> #> #> #> $results[[32]] #> $results[[32]]$protein #> $results[[32]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[32]]$assoc_protein #> $results[[32]]$assoc_protein$uniprot_id #> [1] "P25092" #> #> #> #> $results[[33]] #> $results[[33]]$protein #> $results[[33]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[33]]$assoc_protein #> $results[[33]]$assoc_protein$uniprot_id #> [1] "P30047" #> #> #> #> $results[[34]] #> $results[[34]]$protein #> $results[[34]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[34]]$assoc_protein #> $results[[34]]$assoc_protein$uniprot_id #> [1] "Q02153" #> #> #> #> $results[[35]] #> $results[[35]]$protein #> $results[[35]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[35]]$assoc_protein #> $results[[35]]$assoc_protein$uniprot_id #> [1] "Q16799" #> #> #> #> $results[[36]] #> $results[[36]]$protein #> $results[[36]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[36]]$assoc_protein #> $results[[36]]$assoc_protein$uniprot_id #> [1] "P09417" #> #> #> #> $results[[37]] #> $results[[37]]$protein #> $results[[37]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[37]]$assoc_protein #> $results[[37]]$assoc_protein$uniprot_id #> [1] "P33402" #> #> #> #> $results[[38]] #> $results[[38]]$protein #> $results[[38]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[38]]$assoc_protein #> $results[[38]]$assoc_protein$uniprot_id #> [1] "Q03393" #> #> #> #> $results[[39]] #> $results[[39]]$protein #> $results[[39]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[39]]$assoc_protein #> $results[[39]]$assoc_protein$uniprot_id #> [1] "P16152" #> #> #> #> $results[[40]] #> $results[[40]]$protein #> $results[[40]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[40]]$assoc_protein #> $results[[40]]$assoc_protein$uniprot_id #> [1] "P09923" #> #> #> #> $results[[41]] #> $results[[41]]$protein #> $results[[41]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[41]]$assoc_protein #> $results[[41]]$assoc_protein$uniprot_id #> [1] "P10696" #> #> #> #> $results[[42]] #> $results[[42]]$protein #> $results[[42]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[42]]$assoc_protein #> $results[[42]]$assoc_protein$uniprot_id #> [1] "Q02108" #> #> #> #> $results[[43]] #> $results[[43]]$protein #> $results[[43]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[43]]$assoc_protein #> $results[[43]]$assoc_protein$uniprot_id #> [1] "O75355" #> #> #> #> $results[[44]] #> $results[[44]]$protein #> $results[[44]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[44]]$assoc_protein #> $results[[44]]$assoc_protein$uniprot_id #> [1] "P14618" #> #> #> #> $results[[45]] #> $results[[45]]$protein #> $results[[45]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[45]]$assoc_protein #> $results[[45]]$assoc_protein$uniprot_id #> [1] "Q9NQC3" #> #> #> #> $results[[46]] #> $results[[46]]$protein #> $results[[46]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[46]]$assoc_protein #> $results[[46]]$assoc_protein$uniprot_id #> [1] "P30613" #> #> #> #> $results[[47]] #> $results[[47]]$protein #> $results[[47]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[47]]$assoc_protein #> $results[[47]]$assoc_protein$uniprot_id #> [1] "P15531" #> #> #> #> $results[[48]] #> $results[[48]]$protein #> $results[[48]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[48]]$assoc_protein #> $results[[48]]$assoc_protein$uniprot_id #> [1] "P20594" #> #> #> #> $results[[49]] #> $results[[49]]$protein #> $results[[49]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[49]]$assoc_protein #> $results[[49]]$assoc_protein$uniprot_id #> [1] "O14656" #> #> #> #> $results[[50]] #> $results[[50]]$protein #> $results[[50]]$protein$uniprot_id #> [1] "P30793" #> #> #> $results[[50]]$assoc_protein #> $results[[50]]$assoc_protein$uniprot_id #> [1] "O94875" #> #> #> #> $results[[51]] #> $results[[51]]$protein #> $results[[51]]$protein$uniprot_id #> [1] "Q9NZM1" #> #> #> $results[[51]]$assoc_protein #> $results[[51]]$assoc_protein$uniprot_id #> [1] "P15692" #> #> #> #> $results[[52]] #> $results[[52]]$protein #> $results[[52]]$protein$uniprot_id #> [1] "Q9NZM1" #> #> #> $results[[52]]$assoc_protein #> $results[[52]]$assoc_protein$uniprot_id #> [1] "P50570" #> #> #> #> $results[[53]] #> $results[[53]]$protein #> $results[[53]]$protein$uniprot_id #> [1] "Q9NZM1" #> #> #> $results[[53]]$assoc_protein #> $results[[53]]$assoc_protein$uniprot_id #> [1] "Q9NZN3" #> #> #> #> $results[[54]] #> $results[[54]]$protein #> $results[[54]]$protein$uniprot_id #> [1] "Q9NZM1" #> #> #> $results[[54]]$assoc_protein #> $results[[54]]$assoc_protein$uniprot_id #> [1] "P22681" #> #> #> #> $results[[55]] #> $results[[55]]$protein #> $results[[55]]$protein$uniprot_id #> [1] "Q9NZM1" #> #> #> $results[[55]]$assoc_protein #> $results[[55]]$assoc_protein$uniprot_id #> [1] "P35968" #> #> #> #> $results[[56]] #> $results[[56]]$protein #> $results[[56]]$protein$uniprot_id #> [1] "Q9NZM1" #> #> #> $results[[56]]$assoc_protein #> $results[[56]]$assoc_protein$uniprot_id #> [1] "Q9NZN4" #> #> #> #>
# error handling tryCatch( query_epigraphdb( route = "/mr", params = list( exposure_trait = NULL, outcome_trait = NULL ), retry_times = 0 ), error = function(e) { message(e) } )
#> Error in stop_for_status(response, call = sys.call(-1)): Unprocessable Entity (WebDAV; RFC 4918) (HTTP 422). #> Detail: #> $detail #> [1] "At least one of the following parameters should be non-missing: [exposure_trait, outcome_trait]" #> do.call(method, args = list(route = route, params = params, retry_times = retry_times, retry_pause_min = retry_pause_min, call = call))