Skip to content

Commit 16187af

Browse files
Merge pull request #144 from MRCIEU/devel
Various updates
2 parents 4224670 + 78dbcc0 commit 16187af

31 files changed

+194
-86
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: ieugwasr
22
Title: Interface to the 'OpenGWAS' Database API
3-
Version: 1.0.4
3+
Version: 1.1.0
44
Authors@R: c(
55
person("Gibran", "Hemani", , "g.hemani@bristol.ac.uk", role = c("aut", "cre", "cph"),
66
comment = c(ORCID = "0000-0003-0920-1055")),

R/afl2.r

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
#' @param variantlist Choose pre-defined list. `"reduced"` = ~20k SNPs that are
99
#' common in all super populations (default). `"hapmap3"` = ~1.3 million hm3 SNPs
1010
#' @param opengwas_jwt Used to authenticate protected endpoints. Login to <https://api.opengwas.io> to obtain a jwt. Provide the jwt string here, or store in .Renviron under the keyname OPENGWAS_JWT.
11+
#' @param ... Additional arguments passed to `api_query()`.
1112
#'
1213
#' @export
1314
#' @return Data frame containing ancestry specific LD scores and allele frequencies for each variant
14-
afl2_list <- function(variantlist="reduced", opengwas_jwt=get_opengwas_jwt())
15+
afl2_list <- function(variantlist="reduced", opengwas_jwt=get_opengwas_jwt(), ...)
1516
{
1617
if(variantlist == "reduced")
1718
{
18-
api_query("variants/afl2/snplist", opengwas_jwt=opengwas_jwt) %>%
19+
api_query("variants/afl2/snplist", opengwas_jwt=opengwas_jwt, ...) %>%
1920
get_query_content() %>%
2021
dplyr::as_tibble() %>%
2122
return()
@@ -35,12 +36,13 @@ afl2_list <- function(variantlist="reduced", opengwas_jwt=get_opengwas_jwt())
3536
#' @param rsid Vector of rsids
3637
#' @param reference Default=`"1000g"`
3738
#' @param opengwas_jwt Used to authenticate protected endpoints. Login to <https://api.opengwas.io> to obtain a jwt. Provide the jwt string here, or store in .Renviron under the keyname OPENGWAS_JWT.
39+
#' @param ... Additional arguments passed to `api_query()`.
3840
#'
3941
#' @export
4042
#' @return Data frame containing ancestry specific LD scores and allele frequencies for each variant
41-
afl2_rsid <- function(rsid, reference="1000g", opengwas_jwt=get_opengwas_jwt())
43+
afl2_rsid <- function(rsid, reference="1000g", opengwas_jwt=get_opengwas_jwt(), ...)
4244
{
43-
out <- api_query("variants/afl2", list(rsid=rsid), opengwas_jwt=opengwas_jwt) %>% get_query_content()
45+
out <- api_query("variants/afl2", list(rsid=rsid), opengwas_jwt=opengwas_jwt, ...) %>% get_query_content()
4446
if(inherits(out, "response"))
4547
{
4648
return(out)
@@ -57,12 +59,13 @@ afl2_rsid <- function(rsid, reference="1000g", opengwas_jwt=get_opengwas_jwt())
5759
#' Also allows ranges e.g `"7:105561135-105563135"`
5860
#' @param reference Default=`"1000g"`
5961
#' @param opengwas_jwt Used to authenticate protected endpoints. Login to <https://api.opengwas.io> to obtain a jwt. Provide the jwt string here, or store in .Renviron under the keyname OPENGWAS_JWT.
62+
#' @param ... Additional arguments passed to `api_query()`.
6063
#'
6164
#' @export
6265
#' @return Data frame containing ancestry specific LD scores and allele frequencies for each variant
63-
afl2_chrpos <- function(chrpos, reference="1000g", opengwas_jwt=get_opengwas_jwt())
66+
afl2_chrpos <- function(chrpos, reference="1000g", opengwas_jwt=get_opengwas_jwt(), ...)
6467
{
65-
out <- api_query("variants/afl2", list(chrpos=chrpos), opengwas_jwt=opengwas_jwt) %>% get_query_content()
68+
out <- api_query("variants/afl2", list(chrpos=chrpos), opengwas_jwt=opengwas_jwt, ...) %>% get_query_content()
6669
if(inherits(out, "response"))
6770
{
6871
return(out)
@@ -83,14 +86,15 @@ afl2_chrpos <- function(chrpos, reference="1000g", opengwas_jwt=get_opengwas_jwt
8386
#' @param snpinfo Output from [`afl2_list`], [`afl2_rsid`] or [`afl2_chrpos`].
8487
#' If `NULL` then [`afl2_list()`] is used by default
8588
#' @param opengwas_jwt Used to authenticate protected endpoints. Login to <https://api.opengwas.io> to obtain a jwt. Provide the jwt string here, or store in .Renviron under the keyname OPENGWAS_JWT.
89+
#' @param ... Additional arguments passed to `afl2_list()`
8690
#'
8791
#' @export
8892
#' @return data frame ordered by most likely ancestry, each row represents a super population and cor column represents the correlation between the GWAS dataset and the 1000 genomes super population allele frequencies
89-
infer_ancestry <- function(d, snpinfo=NULL, opengwas_jwt=get_opengwas_jwt())
93+
infer_ancestry <- function(d, snpinfo=NULL, opengwas_jwt=get_opengwas_jwt(), ...)
9094
{
9195
if(is.null(snpinfo))
9296
{
93-
snpinfo <- afl2_list(opengwas_jwt=opengwas_jwt)
97+
snpinfo <- afl2_list(opengwas_jwt=opengwas_jwt, ...)
9498
}
9599
snpinfo <- snpinfo %>%
96100
dplyr::inner_join(., d, by="rsid")

R/ld_clump.R

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@
3131
#' @param bfile If this is provided then will use the API. Default = `NULL`
3232
#' @param plink_bin If `NULL` and `bfile` is not `NULL` then will detect
3333
#' packaged plink binary for specific OS. Otherwise specify path to plink binary.
34-
#' Default = `NULL`
34+
#' Default = `NULL`,
35+
#' @param ... Additional arguments passed to `ld_clump_local()`.
3536
#'
3637
#' @export
3738
#' @return Data frame
3839
ld_clump <- function(dat=NULL, clump_kb=10000, clump_r2=0.001, clump_p=0.99,
39-
pop = "EUR", opengwas_jwt=get_opengwas_jwt(), bfile=NULL, plink_bin=NULL)
40+
pop = "EUR", opengwas_jwt=get_opengwas_jwt(), bfile=NULL, plink_bin=NULL, ...)
4041
{
4142

4243
stopifnot("rsid" %in% names(dat))
@@ -84,7 +85,7 @@ ld_clump <- function(dat=NULL, clump_kb=10000, clump_r2=0.001, clump_p=0.99,
8485
if(is.null(bfile))
8586
{
8687
message("Clumping ", ids[i], ", ", nrow(x), " variants, using ", pop, " population reference")
87-
res[[i]] <- ld_clump_api(x, clump_kb=clump_kb, clump_r2=clump_r2, clump_p=clump_p, pop=pop, opengwas_jwt=opengwas_jwt)
88+
res[[i]] <- ld_clump_api(x, clump_kb=clump_kb, clump_r2=clump_r2, clump_p=clump_p, pop=pop, opengwas_jwt=opengwas_jwt, ...)
8889
} else {
8990
message("Clumping ", ids[i], ", ", nrow(x), " variants, using: ", bfile)
9091
res[[i]] <- ld_clump_local(x, clump_kb=clump_kb, clump_r2=clump_r2, clump_p=clump_p, bfile=bfile, plink_bin=plink_bin)
@@ -106,8 +107,9 @@ ld_clump <- function(dat=NULL, clump_kb=10000, clump_r2=0.001, clump_p=0.99,
106107
#' @param pop Super-population to use as reference panel. Default = `"EUR"`.
107108
#' Options are `"EUR"`, `"SAS"`, `"EAS"`, `"AFR"`, `"AMR"`
108109
#' @param opengwas_jwt Used to authenticate protected endpoints. Login to <https://api.opengwas.io> to obtain a jwt. Provide the jwt string here, or store in .Renviron under the keyname OPENGWAS_JWT.
110+
#' @param ... Additional arguments passed to `api_query()`.
109111
#' @return Data frame of only independent variants
110-
ld_clump_api <- function(dat, clump_kb=10000, clump_r2=0.1, clump_p, pop="EUR", opengwas_jwt=get_opengwas_jwt())
112+
ld_clump_api <- function(dat, clump_kb=10000, clump_r2=0.1, clump_p, pop="EUR", opengwas_jwt=get_opengwas_jwt(), ...)
111113
{
112114
res <- api_query('ld/clump',
113115
query = list(
@@ -118,7 +120,7 @@ ld_clump_api <- function(dat, clump_kb=10000, clump_r2=0.1, clump_p, pop="EUR",
118120
kb = clump_kb,
119121
pop = pop
120122
),
121-
opengwas_jwt=opengwas_jwt
123+
opengwas_jwt=opengwas_jwt, ...
122124
) %>% get_query_content()
123125
y <- subset(dat, !dat[["rsid"]] %in% res)
124126
if(nrow(y) > 0)
@@ -195,17 +197,18 @@ random_string <- function(n=1, len=6)
195197
#' @param pop Super-population to use as reference panel. Default = `"EUR"`.
196198
#' Options are `"EUR"`, `"SAS"`, `"EAS"`, `"AFR"`, `"AMR"`
197199
#' @param opengwas_jwt Used to authenticate protected endpoints. Login to <https://api.opengwas.io> to obtain a jwt. Provide the jwt string here, or store in .Renviron under the keyname OPENGWAS_JWT.
200+
#' @param ... Additional arguments passed to `api_query()`.
198201
#'
199202
#' @export
200203
#' @return Array of rsids that are present in the LD reference panel
201-
ld_reflookup <- function(rsid, pop='EUR', opengwas_jwt=get_opengwas_jwt())
204+
ld_reflookup <- function(rsid, pop='EUR', opengwas_jwt=get_opengwas_jwt(), ...)
202205
{
203206
res <- api_query('ld/reflookup',
204207
query = list(
205208
rsid = rsid,
206209
pop = pop
207210
),
208-
opengwas_jwt=opengwas_jwt
211+
opengwas_jwt=opengwas_jwt, ...
209212
) %>% get_query_content()
210213
if(length(res) == 0)
211214
{

R/ld_matrix.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@
3030
#' @param bfile If this is provided then will use the API. Default = `NULL`
3131
#' @param plink_bin If `NULL` and bfile is not `NULL` then will detect packaged
3232
#' plink binary for specific OS. Otherwise specify path to plink binary. Default = `NULL`
33+
#' @param ... Additional arguments passed to `ld_matrix_api()`.
3334
#'
3435
#' @export
3536
#' @return Matrix of LD r values
36-
ld_matrix <- function(variants, with_alleles=TRUE, pop="EUR", opengwas_jwt=get_opengwas_jwt(), bfile=NULL, plink_bin=NULL) {
37+
ld_matrix <- function(variants, with_alleles=TRUE, pop="EUR", opengwas_jwt=get_opengwas_jwt(), bfile=NULL, plink_bin=NULL, ...) {
3738
if(length(variants) > 500 & is.null(bfile))
3839
{
3940
stop("SNP list must be smaller than 500. Try running locally by providing local ld reference with bfile argument. See vignettes for a guide on how to do this.")
@@ -56,7 +57,7 @@ ld_matrix <- function(variants, with_alleles=TRUE, pop="EUR", opengwas_jwt=get_o
5657
return(ld_matrix_local(variants, bfile=bfile, plink_bin=plink_bin, with_alleles=with_alleles))
5758
}
5859

59-
res <- api_query('ld/matrix', query = list(rsid=variants, pop=pop), opengwas_jwt=opengwas_jwt) %>% get_query_content()
60+
res <- api_query('ld/matrix', query = list(rsid=variants, pop=pop), opengwas_jwt=opengwas_jwt, ...) %>% get_query_content()
6061

6162
if(all(is.na(res))) stop("None of the requested variants were found")
6263
variants2 <- res$snplist

0 commit comments

Comments
 (0)