@@ -4,7 +4,7 @@ timeout_seconds <- 360
44# ' @description Select the API to use
55# ' @param api A character string specifying the API to use. Default is "production".
66# ' @return NULL
7- # ' @export
7+ # ' @noRd
88select_api <- function (api = " dev" ) {
99 if (api == " dev" ) {
1010 api_option <- options(" gpmap_url" = " http://localhost:8000" )
@@ -32,7 +32,7 @@ health_api <- function() {
3232# ' @title Get API Version
3333# ' @description Get the version of the API
3434# ' @return A list containing the version
35- # ' @export
35+ # ' @noRd
3636version_api <- function () {
3737 url <- paste0(getOption(" gpmap_url" ), " /v1/info/version" )
3838 version <- httr :: GET(url )
@@ -44,6 +44,7 @@ version_api <- function() {
4444# ' @title Search Options API
4545# ' @description Search options from the API
4646# ' @return A list containing the search options
47+ # ' @noRd
4748search_options_api <- function () {
4849 url <- paste0(getOption(" gpmap_url" ), " /v1/search/options" )
4950 search_options <- httr :: GET(url , httr :: timeout(timeout_seconds ))
@@ -57,6 +58,7 @@ search_options_api <- function() {
5758# ' @param query A character string specifying the query
5859# ' @param rsquared_threshold A numeric value specifying the rsquared threshold for the proxy variants
5960# ' @return A list containing the variants
61+ # ' @noRd
6062search_variants_api <- function (query , rsquared_threshold = 0.8 ) {
6163 url <- paste0(getOption(" gpmap_url" ), " /v1/search/variant/" , query , " ?rsquared_threshold=" , rsquared_threshold )
6264 search_variants <- httr :: GET(url , httr :: timeout(timeout_seconds ))
@@ -68,6 +70,7 @@ search_variants_api <- function(query, rsquared_threshold = 0.8) {
6870# ' @title Get All Traits API
6971# ' @description Get all traits from the API
7072# ' @return A list containing all traits
73+ # ' @noRd
7174traits_api <- function () {
7275 url <- paste0(getOption(" gpmap_url" ), " /v1/traits" )
7376 traits <- httr :: GET(url , httr :: timeout(timeout_seconds ))
@@ -83,6 +86,7 @@ traits_api <- function() {
8386# ' @param include_coloc_pairs A logical value specifying whether to include coloc pairs
8487# ' @param h4_threshold A numeric value specifying the h4 threshold for coloc pairs
8588# ' @return A list containing the traits
89+ # ' @noRd
8690specific_traits_api <- function (
8791 trait_ids ,
8892 include_associations = FALSE ,
@@ -106,6 +110,7 @@ specific_traits_api <- function(
106110# ' @param trait_id A character string specifying the trait ID
107111# ' @param include_associations A logical value specifying whether to include associations
108112# ' @return A list containing the trait
113+ # ' @noRd
109114trait_api <- function (trait_id , include_associations = FALSE ) {
110115 url <- paste0(
111116 getOption(" gpmap_url" ),
@@ -118,6 +123,12 @@ trait_api <- function(trait_id, include_associations = FALSE) {
118123 return (trait )
119124}
120125
126+ # ' @title Get Trait Coloc Pairs API
127+ # ' @description Get trait coloc pairs from the API
128+ # ' @param trait_id A character string specifying the trait ID
129+ # ' @param h4_threshold A numeric value specifying the h4 threshold for coloc pairs
130+ # ' @return A list containing the trait coloc pairs
131+ # ' @noRd
121132trait_coloc_pairs_api <- function (trait_id , h4_threshold = 0.8 ) {
122133 url <- paste0(
123134 getOption(" gpmap_url" ),
@@ -135,6 +146,7 @@ trait_coloc_pairs_api <- function(trait_id, h4_threshold = 0.8) {
135146# ' @title Get Gene Information
136147# ' @description Get gene information from the API
137148# ' @return A list containing the genes
149+ # ' @noRd
138150genes_api <- function () {
139151 url <- paste0(getOption(" gpmap_url" ), " /v1/genes" )
140152 genes <- httr :: GET(url , httr :: timeout(timeout_seconds ))
@@ -151,6 +163,7 @@ genes_api <- function() {
151163# ' @param include_trans A logical value specifying whether to include trans genetic effects
152164# ' @param h4_threshold A numeric value specifying the h4 threshold for coloc pairs
153165# ' @return A list containing the genes
166+ # ' @noRd
154167specific_genes_api <- function (
155168 gene_ids ,
156169 include_associations = FALSE ,
@@ -180,6 +193,7 @@ specific_genes_api <- function(
180193# ' @param include_trans A logical value specifying whether to include trans genetic effects
181194# ' @param h4_threshold A numeric value specifying the h4 threshold for coloc pairs
182195# ' @return A list containing the gene information
196+ # ' @noRd
183197gene_api <- function (gene_id ,
184198 include_associations = FALSE ,
185199 include_coloc_pairs = FALSE ,
@@ -207,6 +221,7 @@ gene_api <- function(gene_id,
207221# ' @param include_coloc_pairs A logical value specifying whether to include coloc pairs
208222# ' @param h4_threshold A numeric value specifying the h4 threshold for coloc pairs
209223# ' @return A list containing the region information
224+ # ' @noRd
210225region_api <- function (region_id , include_associations = FALSE , include_coloc_pairs = FALSE , h4_threshold = 0.8 ) {
211226 url <- paste0(
212227 getOption(" gpmap_url" ),
@@ -230,6 +245,7 @@ region_api <- function(region_id, include_associations = FALSE, include_coloc_pa
230245# ' @param include_coloc_pairs Logical. Whether to include coloc pairs for SNPs (only when expand=TRUE)
231246# ' @param h4_threshold Numeric. H4 threshold for coloc pairs, defaults to 0.8
232247# ' @return A list containing the variants
248+ # ' @noRd
233249variants_api <- function (variants , expand = FALSE , include_associations = FALSE , include_coloc_pairs = FALSE , h4_threshold = 0.8 ) {
234250 variants <- paste(variants , collapse = " &variants=" )
235251 url <- paste0(getOption(" gpmap_url" ), " /v1/variants?variants=" , variants )
@@ -245,11 +261,21 @@ variants_api <- function(variants, expand = FALSE, include_associations = FALSE,
245261# ' @param include_coloc_pairs Logical. Whether to include coloc pairs
246262# ' @param h4_threshold Numeric. H4 threshold for coloc pairs, defaults to 0.8
247263# ' @return A list containing the variants
264+ # ' @noRd
248265variants_grange_api <- function (chr , start , stop , include_associations = FALSE , include_coloc_pairs = FALSE , h4_threshold = 0.8 ) {
249266 url <- paste0(getOption(" gpmap_url" ), " /v1/variants?grange=" , chr , " :" , start , " -" , stop )
250267 return (get_variants_with_options_api(url , expand = FALSE , include_associations , include_coloc_pairs , h4_threshold ))
251268}
252269
270+ # ' @title Get Variants with Options API
271+ # ' @description Get variants from the API with options
272+ # ' @param url A character string specifying the URL
273+ # ' @param expand A logical value specifying whether to expand the variants
274+ # ' @param include_associations A logical value specifying whether to include associations
275+ # ' @param include_coloc_pairs A logical value specifying whether to include coloc pairs
276+ # ' @param h4_threshold A numeric value specifying the h4 threshold for coloc pairs
277+ # ' @return A list containing the variants
278+ # ' @noRd
253279get_variants_with_options_api <- function (
254280 url ,
255281 expand = FALSE ,
@@ -275,6 +301,7 @@ get_variants_with_options_api <- function(
275301# ' @param include_coloc_pairs A logical value specifying whether to include coloc pairs
276302# ' @param h4_threshold A numeric value specifying the h4 threshold for coloc pairs
277303# ' @return A list containing the variant
304+ # ' @noRd
278305variant_api <- function (snp_id , include_coloc_pairs = FALSE , h4_threshold = 0.8 ) {
279306 url <- paste0(
280307 getOption(" gpmap_url" ),
@@ -293,6 +320,7 @@ variant_api <- function(snp_id, include_coloc_pairs = FALSE, h4_threshold = 0.8)
293320# ' @description Get variant summary statistics from the API
294321# ' @param snp_id A character string specifying the SNP ID
295322# ' @return A list containing dataframes from the TSV files
323+ # ' @noRd
296324variant_summary_stats_api <- function (snp_id ) {
297325 temp_zip <- file.path(tempdir(), paste0(" summary_stats_" , snp_id , " .zip" ))
298326
@@ -317,6 +345,7 @@ variant_summary_stats_api <- function(snp_id) {
317345# ' @description Get LD proxies from the API by Variant ID
318346# ' @param variants A character string specifying the Variant ID
319347# ' @return A list containing the LD proxies
348+ # ' @noRd
320349ld_proxies_by_variant_api <- function (variants ) {
321350 variants <- paste(variants , collapse = " &variants=" )
322351 url <- paste0(getOption(" gpmap_url" ), " /v1/ld/proxies?variants=" , variants )
@@ -330,6 +359,7 @@ ld_proxies_by_variant_api <- function(variants) {
330359# ' @description Get LD proxies from the API by SNP ID
331360# ' @param snp_ids A character string specifying the SNP ID
332361# ' @return A list containing the LD proxies
362+ # ' @noRd
333363ld_proxies_by_snp_id_api <- function (snp_ids ) {
334364 snp_ids <- paste(snp_ids , collapse = " &snp_ids=" )
335365 url <- paste0(getOption(" gpmap_url" ), " /v1/ld/proxies?snp_ids=" , snp_ids )
@@ -343,6 +373,7 @@ ld_proxies_by_snp_id_api <- function(snp_ids) {
343373# ' @description Get LD matrix from the API by Variant ID
344374# ' @param variants A character string specifying the Variant ID
345375# ' @return A list containing the LD matrix
376+ # ' @noRd
346377ld_matrix_by_variant_api <- function (variants ) {
347378 variants <- paste(variants , collapse = " &variants=" )
348379 url <- paste0(getOption(" gpmap_url" ), " /v1/ld/matrix?variants=" , variants )
@@ -356,6 +387,7 @@ ld_matrix_by_variant_api <- function(variants) {
356387# ' @description Get LD matrix from the API by SNP ID
357388# ' @param snp_ids A character string specifying the SNP ID
358389# ' @return A list containing the LD matrix
390+ # ' @noRd
359391ld_matrix_by_snp_id_api <- function (snp_ids ) {
360392 snp_ids <- paste(snp_ids , collapse = " &snp_ids=" )
361393 url <- paste0(getOption(" gpmap_url" ), " /v1/ld/matrix?snp_ids=" , snp_ids )
@@ -370,6 +402,7 @@ ld_matrix_by_snp_id_api <- function(snp_ids) {
370402# ' @param snp_ids A vector of numeric values specifying the SNP IDs
371403# ' @param study_ids A vector of numeric values specifying the Study IDs
372404# ' @return A list containing the associations
405+ # ' @noRd
373406associations_api <- function (snp_ids , study_ids ) {
374407 snp_ids <- paste(snp_ids , collapse = " &snp_ids=" )
375408 study_ids <- paste(study_ids , collapse = " &study_ids=" )
@@ -384,6 +417,7 @@ associations_api <- function(snp_ids, study_ids) {
384417# ' @title Get All Gene Pleiotropies API
385418# ' @description Get all gene pleiotropies from the API
386419# ' @return A list containing the gene pleiotropies
420+ # ' @noRd
387421gene_pleiotropies_api <- function () {
388422 url <- paste0(getOption(" gpmap_url" ), " /v1/pleiotropy/genes" )
389423 gene_pleiotropies <- httr :: GET(url , httr :: timeout(timeout_seconds ))
@@ -395,6 +429,7 @@ gene_pleiotropies_api <- function() {
395429# ' @title Get All SNP Pleiotropies API
396430# ' @description Get all SNP pleiotropies from the API
397431# ' @return A list containing the SNP pleiotropies
432+ # ' @noRd
398433snp_pleiotropies_api <- function () {
399434 url <- paste0(getOption(" gpmap_url" ), " /v1/pleiotropy/snps" )
400435 snp_pleiotropies <- httr :: GET(url , httr :: timeout(timeout_seconds ))
@@ -407,10 +442,14 @@ snp_pleiotropies_api <- function() {
407442# ' @description Get a GWAS from the API
408443# ' @param gwas_id The ID of the GWAS
409444# ' @param include_summary_stats Whether to include summary statistics
445+ # ' @param include_associations Whether to include associations
410446# ' @return A list containing the GWAS information
411- # ' @export
412- get_gwas_api <- function (gwas_id , include_summary_stats = FALSE ) {
447+ # ' @noRd
448+ get_gwas_api <- function (gwas_id , include_summary_stats = FALSE , include_associations = FALSE ) {
413449 url <- paste0(getOption(" gpmap_url" ), " /v1/gwas/" , gwas_id )
450+ if (include_associations ) {
451+ url <- paste0(url , " ?include_associations=true" )
452+ }
414453 gwas <- httr :: GET(url , httr :: timeout(timeout_seconds ))
415454 gwas <- httr :: content(gwas , " text" , encoding = " UTF-8" )
416455 gwas <- jsonlite :: fromJSON(gwas )
@@ -421,6 +460,11 @@ get_gwas_api <- function(gwas_id, include_summary_stats = FALSE) {
421460 return (gwas )
422461}
423462
463+ # ' @title Get a GWAS Summary Stats API
464+ # ' @description Get a GWAS summary stats from the API
465+ # ' @param gwas_id The ID of the GWAS
466+ # ' @return A list containing the GWAS summary stats
467+ # ' @noRd
424468get_gwas_summary_stats_api <- function (gwas_id ) {
425469 url <- paste0(getOption(" gpmap_url" ), " /v1/gwas/" , gwas_id , " /summary-stats" )
426470 summary_stats <- httr :: GET(url , httr :: timeout(timeout_seconds ))
@@ -451,7 +495,9 @@ get_gwas_summary_stats_api <- function(gwas_id) {
451495# ' @param ancestry The ancestry of the GWAS. Currently only "EUR" is accepted.
452496# ' @param sample_size The sample size of the GWAS
453497# ' @param reference_build The reference build of the GWAS. Only "GRCh37" and "GRCh38" are accepted.
498+ # ' @param compare_with_upload_guids A vector of GUIDs of uploads to compare with
454499# ' @return A list containing the GWAS information
500+ # ' @noRd
455501upload_gwas_api <- function (file ,
456502 name ,
457503 p_value_threshold ,
@@ -463,7 +509,8 @@ upload_gwas_api <- function(file,
463509 should_be_added = FALSE ,
464510 ancestry = " EUR" ,
465511 sample_size ,
466- reference_build = " GRCh38" ) {
512+ reference_build = " GRCh38" ,
513+ compare_with_upload_guids = NA ) {
467514 url <- paste0(getOption(" gpmap_url" ), " /v1/gwas" )
468515
469516 gwas_request <- list (
@@ -477,7 +524,8 @@ upload_gwas_api <- function(file,
477524 ancestry = ancestry ,
478525 sample_size = sample_size ,
479526 p_value_threshold = p_value_threshold ,
480- column_names = column_names
527+ column_names = column_names ,
528+ compare_with_upload_guids = compare_with_upload_guids
481529 )
482530 request_json <- jsonlite :: toJSON(gwas_request , auto_unbox = TRUE )
483531
0 commit comments