Skip to content

Commit 588e859

Browse files
Updating to align with changes in ieugwasr
- Changed error handling - now if the API gives an error code it is propagated as an error with message in TwoSampleMR - Headers sent to API are updated
1 parent d386f0b commit 588e859

File tree

5 files changed

+24
-14
lines changed

5 files changed

+24
-14
lines changed

DESCRIPTION

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: TwoSampleMR
22
Title: Two Sample MR Functions and Interface to MRC Integrative
33
Epidemiology Unit OpenGWAS Database
4-
Version: 0.6.19
4+
Version: 0.6.20
55
Authors@R: c(
66
person("Gibran", "Hemani", , "[email protected]", role = c("aut", "cre"),
77
comment = c(ORCID = "0000-0003-0920-1055")),
@@ -34,7 +34,7 @@ Imports:
3434
glmnet,
3535
gridExtra,
3636
gtable,
37-
ieugwasr (>= 1.0.1),
37+
ieugwasr (>= 1.1.0),
3838
jsonlite,
3939
knitr,
4040
lattice,
@@ -64,6 +64,7 @@ VignetteBuilder:
6464
Remotes:
6565
gqi/MRMix,
6666
mrcieu/MRInstruments,
67+
mrcieu/ieugwasr,
6768
MRPRESSO=rondolab/MR-PRESSO,
6869
qingyuanzhao/mr.raps,
6970
WSpiller/RadialMR

R/instruments.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extract_instruments <- function(outcomes, p1 = 5e-8, clump = TRUE, p2 = 5e-8, r2
1919
# .Deprecated("ieugwasr::tophits()")
2020
outcomes <- ieugwasr::legacy_ids(unique(outcomes))
2121

22-
d <- ieugwasr::tophits(outcomes, pval=p1, clump=clump, r2=r2, kb=kb, force_server=FALSE, opengwas_jwt=opengwas_jwt)
22+
d <- ieugwasr::tophits(outcomes, pval=p1, clump=clump, r2=r2, kb=kb, force_server=FALSE, opengwas_jwt=opengwas_jwt, x_api_source=x_api_source_header())
2323

2424
# d$phenotype.deprecated <- paste0(d$trait, " || ", d$consortium, " || ", d$year, " || ", d$unit)
2525
if(nrow(d) == 0) return(NULL)

R/ld.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,5 @@ clump_data <- function(dat, clump_kb=10000, clump_r2=0.001, clump_p1=1, clump_p2
8989
ld_matrix <- function(snps, with_alleles=TRUE, pop="EUR")
9090
{
9191
# .Deprecated("ieugwasr::ld_matrix()")
92-
ieugwasr::ld_matrix(variants=snps, with_alleles=with_alleles, pop=pop)
92+
ieugwasr::ld_matrix(variants=snps, with_alleles=with_alleles, pop=pop, x_api_source=x_api_source_header())
9393
}

R/ldsc.r

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,14 @@ ldsc_rg_internal <- function(Zs, r2, h1, h2, N1, N2, Nc=0, W=NULL)
118118
ldsc_h2 <- function(id, ancestry="infer", snpinfo = NULL, splitsize=20000)
119119
{
120120
if (is.null(snpinfo)) {
121-
snpinfo <- ieugwasr::afl2_list("hapmap3")
121+
snpinfo <- ieugwasr::afl2_list("hapmap3", x_api_source=x_api_source_header())
122122
}
123123

124124
snpinfo <- snpinfo %>%
125125
dplyr::filter(complete.cases(.))
126126

127127
d <- extract_split(snpinfo$rsid, id, splitsize) %>%
128-
ieugwasr::fill_n() %>%
128+
ieugwasr::fill_n(x_api_source=x_api_source_header()) %>%
129129
dplyr::mutate(z = beta / se) %>%
130130
dplyr::select(rsid, z = z, n = n, eaf) %>%
131131
dplyr::filter(complete.cases(.))
@@ -159,20 +159,20 @@ ldsc_h2 <- function(id, ancestry="infer", snpinfo = NULL, splitsize=20000)
159159
ldsc_rg <- function(id1, id2, ancestry="infer", snpinfo = NULL, splitsize=20000)
160160
{
161161
if (is.null(snpinfo)) {
162-
snpinfo <- ieugwasr::afl2_list("hapmap3")
162+
snpinfo <- ieugwasr::afl2_list("hapmap3", x_api_source=x_api_source_header())
163163
}
164164

165165
x <- extract_split(snpinfo$rsid, c(id1, id2), splitsize)
166166
d1 <- subset(x, id == id1) %>%
167-
ieugwasr::fill_n() %>%
167+
ieugwasr::fill_n(x_api_source=x_api_source_header()) %>%
168168
dplyr::mutate(z = beta / se) %>%
169169
dplyr::select(rsid, z1 = z, n1 = n, eaf) %>%
170170
dplyr::filter(complete.cases(.))
171171

172172
stopifnot(nrow(d1) > 0)
173173

174174
d2 <- subset(x, id == id2) %>%
175-
ieugwasr::fill_n() %>%
175+
ieugwasr::fill_n(x_api_source=x_api_source_header()) %>%
176176
dplyr::mutate(z = beta / se) %>%
177177
dplyr::select(rsid, z2 = z, n2 = n, eaf) %>%
178178
dplyr::filter(complete.cases(.))
@@ -234,7 +234,7 @@ extract_split <- function(snplist, id, splitsize=20000)
234234
split(snplist, 1:nsplit) %>%
235235
pbapply::pblapply(., function(x)
236236
{
237-
ieugwasr::associations(x, id, proxies=FALSE)
237+
ieugwasr::associations(x, id, proxies=FALSE, x_api_source=x_api_source_header())
238238
}) %>%
239239
dplyr::bind_rows()
240240
}

R/query.R

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
x_api_source_header <- function()
2+
{
3+
paste0("ieugwasr/", utils::packageVersion("ieugwasr"), ";TwoSampleMR/", utils::packageVersion("TwoSampleMR"))
4+
}
5+
6+
17
#' Get list of studies with available GWAS summary statistics through API
28
#'
39
#' @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.
@@ -7,7 +13,7 @@
713
available_outcomes <- function(opengwas_jwt = ieugwasr::get_opengwas_jwt())
814
{
915
# .Deprecated("ieugwasr::gwasinfo()")
10-
a <- ieugwasr::gwasinfo(opengwas_jwt=opengwas_jwt)
16+
a <- ieugwasr::gwasinfo(opengwas_jwt=opengwas_jwt, x_api_source=x_api_source_header())
1117
return(a)
1218
}
1319

@@ -92,7 +98,8 @@ extract_outcome_data_internal <- function(snps, outcomes, proxies = TRUE, rsq =
9298
align_alleles = align_alleles,
9399
palindromes = palindromes,
94100
maf_threshold = maf_threshold,
95-
opengwas_jwt=opengwas_jwt
101+
opengwas_jwt=opengwas_jwt,
102+
x_api_source=x_api_source_header()
96103
)
97104
if(!is.data.frame(d)) d <- data.frame()
98105

@@ -118,7 +125,8 @@ extract_outcome_data_internal <- function(snps, outcomes, proxies = TRUE, rsq =
118125
align_alleles = align_alleles,
119126
palindromes = palindromes,
120127
maf_threshold = maf_threshold,
121-
opengwas_jwt=opengwas_jwt
128+
opengwas_jwt=opengwas_jwt,
129+
x_api_source=x_api_source_header()
122130
)
123131
if(!is.data.frame(out)) out <- data.frame()
124132
return(out)
@@ -149,7 +157,8 @@ extract_outcome_data_internal <- function(snps, outcomes, proxies = TRUE, rsq =
149157
align_alleles = align_alleles,
150158
palindromes = palindromes,
151159
maf_threshold = maf_threshold,
152-
opengwas_jwt=opengwas_jwt
160+
opengwas_jwt=opengwas_jwt,
161+
x_api_source=x_api_source_header()
153162
)
154163

155164
if(!is.data.frame(out)) out <- data.frame()

0 commit comments

Comments
 (0)