Skip to content

Commit

Permalink
Merge pull request #489 from remlapmot/march-2024-suggestions
Browse files Browse the repository at this point in the history
TwoSampleMR 0.5.11
  • Loading branch information
remlapmot authored Mar 21, 2024
2 parents e7cd0fc + 06c6372 commit ebfeb95
Show file tree
Hide file tree
Showing 31 changed files with 161 additions and 77 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: TwoSampleMR
Title: Two Sample MR Functions and Interface to MR Base Database
Version: 0.5.10
Version: 0.5.11
Authors@R: c(
person("Gibran", "Hemani", , "g.hemani@bristol.ac.uk", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-0920-1055")),
Expand Down Expand Up @@ -32,7 +32,7 @@ Imports:
cowplot,
data.table,
dplyr,
ggplot2,
ggplot2 (>= 3.4.0),
glmnet,
gridExtra,
gtable,
Expand Down
21 changes: 15 additions & 6 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# TwoSampleMR v0.5.11

(Release date: 2024-03-21)

* In `mr_leaveoneout_plot()` and `mr_forest_plot()` amended `size` argument to `linewidth` as per ggplot2 version 3.4.0.
* Add some datasets such that tests, continuous integration services, and creation of the vignettes don't rely on the availability of the OpenGWAS server.
* Various improvements to helpfiles.

# TwoSampleMR v0.5.10

(Release date: 2024-02-20)

* Added `bfile` and `plink_bin` arguments to `clump_data()`
* Improvements to file reading and dataset formatting capabilities of `mv_extract_exposures_local()` to create the multiple exposure dataset

# TwoSampleMR v0.5.9

(Release date: 2024-02-01)
Expand Down Expand Up @@ -217,12 +232,6 @@ TwoSampleMR v0.4.17
(Release date: 2018-12-03)

* Added facility to harmonise indels

TwoSampleMR v0.4.17
==============

(Release date: 2018-12-03)

* Documentation and options added to multivariable MR

TwoSampleMR v0.3.4
Expand Down
8 changes: 4 additions & 4 deletions R/ld.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
#' This function does put load on the OpenGWAS servers, which makes life more difficult for other users.
#' We have implemented a method and made available the LD reference panels to perform clumping locally, see [ieugwasr::ld_clump()] and related vignettes for details.
#'
#' @param dat Output from [format_data()]. Must have a SNP name column (SNP), SNP chromosome column (chr_name), SNP position column (chrom_start). If id.exposure or pval.exposure not present they will be generated.
#' @param dat Output from [format_data()]. Must have a SNP name column (`SNP`), SNP chromosome column (`chr_name`), SNP position column (`chrom_start`). If `id.exposure` or `pval.exposure` not present they will be generated.
#' @param clump_kb Clumping window, default is `10000`.
#' @param clump_r2 Clumping r2 cutoff. Note that this default value has recently changed from `0.01` to `0.001`.
#' @param clump_p1 Clumping sig level for index SNPs, default is `1`.
#' @param clump_p2 Clumping sig level for secondary SNPs, default is `1`.
#' @param pop Super-population to use as reference panel. Default = "EUR". Options are EUR, SAS, EAS, AFR, AMR. 'legacy' also available - which is a previously used version of the EUR panel with a slightly different set of markers
#' @param bfile If this is provided then will use the API. Default = NULL
#' @param plink_bin If NULL and bfile is not NULL then will detect packaged plink binary for specific OS. Otherwise specify path to plink binary. Default = NULL
#' @param pop Super-population to use as reference panel. Default = `"EUR"`. Options are `"EUR"`, `"SAS"`, `"EAS"`, `"AFR"`, `"AMR"`. `'legacy'` also available - which is a previously used version of the EUR panel with a slightly different set of markers
#' @param bfile If this is provided then will use the API. Default = `NULL`
#' @param plink_bin If `NULL` and `bfile` is not `NULL` then will detect packaged plink binary for specific OS. Otherwise specify path to plink binary. Default = `NULL`
#'
#' @export
#' @return Data frame
Expand Down
2 changes: 1 addition & 1 deletion R/leaveoneout.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ mr_leaveoneout_plot <- function(leaveoneout_results)
ggplot2::geom_point(ggplot2::aes(colour=as.factor(tot))) +
ggplot2::geom_hline(ggplot2::aes(yintercept = which(levels(SNP) %in% "")), colour="grey") +
ggplot2::scale_colour_manual(values=c("black", "red")) +
ggplot2::scale_size_manual(values=c(0.3, 1)) +
ggplot2::scale_linewidth_manual(values=c(0.3, 1)) +
# xlim(c(min(c(0, d$b), na.rm=T), max(c(0, d$b), na.rm=T))) +
ggplot2::theme(
legend.position="none",
Expand Down
20 changes: 10 additions & 10 deletions R/multivariable_mr.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
#' @param access_token Google OAuth2 access token. Used to authenticate level of access to data.
#' @param find_proxies Look for proxies? This slows everything down but is more accurate. The default is `TRUE`.
#' @param force_server Whether to search through pre-clumped dataset or to re-extract and clump directly from the server. The default is `FALSE`.
#' @param pval_threshold Instrument detection p-value threshold. Default = 5e-8
#' @param pval_threshold Instrument detection p-value threshold. Default = `5e-8`
#' @param pop Which 1000 genomes super population to use for clumping when using the server
#' @param plink_bin If NULL and bfile is not NULL then will detect packaged plink binary for specific OS. Otherwise specify path to plink binary. Default = NULL
#' @param bfile If this is provided then will use the API. Default = NULL
#' @param plink_bin If `NULL` and `bfile` is not `NULL` then will detect packaged plink binary for specific OS. Otherwise specify path to plink binary. Default = `NULL`
#' @param bfile If this is provided then will use the API. Default = `NULL`
#'
#' @export
#' @return data frame in `exposure_dat` format
Expand Down Expand Up @@ -80,13 +80,13 @@ mv_extract_exposures <- function(id_exposure, clump_r2=0.001, clump_kb=10000, ha
#' @param id_col Optional column name to give the dataset an ID. Will be generated automatically if not provided for every trait / unit combination. The default is `"id"`.
#' @param min_pval Minimum allowed p-value. The default is `1e-200`.
#' @param log_pval The pval is -log10(P). The default is `FALSE`.
#' @param pval_threshold Default=5e-8 for clumping
#' @param plink_bin If NULL and bfile is not NULL then will detect packaged plink binary for specific OS. Otherwise specify path to plink binary. Default = NULL
#' @param bfile If this is provided then will use the API. Default = NULL
#' @param clump_r2 Default=0.001 for clumping
#' @param clump_kb Default=10000 for clumping
#' @param pval_threshold Default=`5e-8` for clumping
#' @param plink_bin If `NULL` and `bfile` is not `NULL` then will detect packaged plink binary for specific OS. Otherwise specify path to plink binary. Default = `NULL`
#' @param bfile If this is provided then will use the API. Default = `NULL`
#' @param clump_r2 Default=`0.001` for clumping
#' @param clump_kb Default=`10000` for clumping
#' @param pop Which 1000 genomes super population to use for clumping when using the server
#' @param harmonise_strictness See action argument in harmonise_data. Default=2
#' @param harmonise_strictness See action argument in [harmonise_data()]. Default=`2`
#'
#' @export
#' @return List
Expand Down Expand Up @@ -252,7 +252,7 @@ mv_extract_exposures_local <- function(
#' \item{exposure_se}{is the same as `exposure_beta`, but for standard errors.}
#' \item{exposure_pval}{the same as `exposure_beta`, but for p-values.}
#' \item{expname}{A data frame with two variables, `id.exposure` and `exposure` which are character strings.}
#' \item{outcome_beta}{an array of effects for the outcome, corresponding to the SNPs in exposure_beta.}
#' \item{outcome_beta}{an array of effects for the outcome, corresponding to the SNPs in `exposure_beta`.}
#' \item{outcome_se}{an array of standard errors for the outcome.}
#' \item{outcome_pval}{an array of p-values for the outcome.}
#' \item{outname}{A data frame with two variables, `id.outcome` and `outcome` which are character strings.}
Expand Down
2 changes: 1 addition & 1 deletion R/singlesnp.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ mr_forest_plot <- function(singlesnp_results, exponentiate=FALSE)
ggplot2::geom_point(ggplot2::aes(colour=as.factor(tot))) +
ggplot2::geom_hline(ggplot2::aes(yintercept = which(levels(SNP) %in% "")), colour="grey") +
ggplot2::scale_colour_manual(values=c("black", "red")) +
ggplot2::scale_size_manual(values=c(0.3, 1)) +
ggplot2::scale_linewidth_manual(values=c(0.3, 1)) +
# xlim(c(min(c(0, d$b), na.rm=T), max(c(0, d$b), na.rm=T))) +
ggplot2::theme(
legend.position="none",
Expand Down
2 changes: 1 addition & 1 deletion R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
paste("TwoSampleMR version", utils::packageVersion("TwoSampleMR"), "\n"),
"[>] New: Option to use non-European LD reference panels for clumping etc\n",
"[>] Some studies temporarily quarantined to verify effect allele\n",
"[>] See news(package='TwoSampleMR') and https://gwas.mrcieu.ac.uk for further details\n"
"[>] See news(package = 'TwoSampleMR') and https://gwas.mrcieu.ac.uk for further details\n"
)

a <- suppressWarnings(try(readLines("https://raw.githubusercontent.com/MRCIEU/TwoSampleMR/master/DESCRIPTION"), silent=TRUE))
Expand Down
Binary file modified inst/extdata/test_add_metadata.RData
Binary file not shown.
Binary file modified inst/extdata/test_add_mvmr_local.RData
Binary file not shown.
Binary file modified inst/extdata/test_commondata.RData
Binary file not shown.
Binary file modified inst/extdata/vig_exposure.RData
Binary file not shown.
Binary file modified inst/extdata/vig_harmonise.RData
Binary file not shown.
Binary file modified inst/extdata/vig_outcome.RData
Binary file not shown.
Binary file modified inst/extdata/vig_perform_mr.RData
Binary file not shown.
8 changes: 4 additions & 4 deletions man/clump_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/mv_extract_exposures.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions man/mv_extract_exposures_local.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/mv_harmonise_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions tests/testthat/test_add_metadata.r
Original file line number Diff line number Diff line change
Expand Up @@ -13,61 +13,70 @@ context("add metadata")
# d9 <- extract_instruments("bbj-a-1")
# d10 <- extract_instruments("ieu-b-109")

# save(d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, file="inst/extdata/test_add_metadata.RData")
# save(d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, file="inst/extdata/test_add_metadata.RData", compress = "xz")

load(system.file("extdata", "test_add_metadata.RData", package="TwoSampleMR"))

test_that("exposure data 1", {
skip("Skip unless you have good access to the API.")
d1 <- d1 %>% add_metadata()
expect_true("units.exposure" %in% names(d1))
})

test_that("exposure data 2", {
skip("Skip unless you have good access to the API.")
d2 <- d2 %>% add_metadata()
expect_true("units.exposure" %in% names(d2))
})

test_that("outcome data 1", {
skip("Skip unless you have good access to the API.")
d3 <- d3 %>% add_metadata()
expect_true("units.outcome" %in% names(d3))
})

test_that("outcome data 2", {
skip("Skip unless you have good access to the API.")
d4 <- d4 %>% add_metadata()
expect_true("units.outcome" %in% names(d4))
})

test_that("dat 2", {
skip("Skip unless you have good access to the API.")
d5 <- d5 %>% add_metadata()
expect_true("units.outcome" %in% names(d5) & "units.exposure" %in% names(d5))
})

test_that("no id1", {
skip("Skip unless you have good access to the API.")
d6$id.exposure <- "not a real id"
d6 <- add_metadata(d6)
expect_true(!"units.exposure" %in% names(d6))
})

test_that("no id2", {
skip("Skip unless you have good access to the API.")
d7$id.outcome <- "not a real id"
d7 <- add_metadata(d7)
expect_true(!"units.outcome" %in% names(d7))
})

test_that("ukb-d", {
skip("Skip unless you have good access to the API.")
d8 <- add_metadata(d8)
expect_true("units.outcome" %in% names(d8))
})

test_that("bbj-a-1", {
skip("Skip unless you have good access to the API.")
d9 <- d9 %>% add_metadata()
expect_true("samplesize.exposure" %in% names(d9))
expect_true(all(!is.na(d9$samplesize.exposure)))
})

test_that("ieu-b-109", {
skip("Skip unless you have good access to the API.")
d10 <- d10 %>% add_metadata()
expect_true("samplesize.exposure" %in% names(d10))
expect_true(all(!is.na(d10$samplesize.exposure)))
})

6 changes: 4 additions & 2 deletions tests/testthat/test_create_test_data.r
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
skip()
test_that("Create local data", {
skip("Skip local data creation unless you have good access to the API.")

exp_dat <- extract_instruments("ieu-a-2")
out_dat <- extract_outcome_data(exp_dat$SNP, "ieu-a-7")
dat <- make_dat("ieu-a-2", "ieu-a-7") %>% add_metadata()
dat2 <- make_dat()

save(exp_dat, out_dat, dat, dat2, file=file.path("inst", "extdata", "test_commondata.RData"))
save(exp_dat, out_dat, dat, dat2, file=file.path("inst", "extdata", "test_commondata.RData"), compress = "xz")
})
2 changes: 2 additions & 0 deletions tests/testthat/test_instruments.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ context("Instruments")

test_that("server and mrinstruments", {

skip("Skip unless you have good access to the API.")

# no no
exp_dat <- extract_instruments(outcomes=c("ieu-a-1032"))
expect_true(length(unique(exp_dat$id)) == 0)
Expand Down
16 changes: 11 additions & 5 deletions tests/testthat/test_ld.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
context("ld")


a <- extract_instruments(2, clump=FALSE)
out <- clump_data(a)

test_that("extract some data", {
skip("Skip unless you have good access to the API.")
skip_on_ci()
skip_on_cran()
a <- extract_instruments(2, clump=FALSE)
out <- clump_data(a)
})

test_that("clump", {
skip("Skip unless you have good access to the API.")
skip_on_ci()
skip_on_cran()
expect_equal(ncol(a), ncol(out))
Expand All @@ -15,6 +19,7 @@ test_that("clump", {


test_that("matrix", {
skip("Skip unless you have good access to the API.")
skip_on_ci()
skip_on_cran()
b <- ld_matrix(out$SNP)
Expand All @@ -24,6 +29,7 @@ test_that("matrix", {


test_that("clump multiple", {
skip("Skip unless you have good access to the API.")
skip_on_ci()
skip_on_cran()
a <- extract_instruments(c("ieu-a-2", "ieu-a-1001"), clump=FALSE)
Expand All @@ -32,9 +38,9 @@ test_that("clump multiple", {
})

test_that("clump local", {
skip("Skip unless you're GH running this test locally.")
skip_on_ci()
skip_on_cran()
skip_if_not(file.exists("/Users/gh13047/repo/opengwas-api-internal/opengwas-api/app/ld_files/EUR.bim"))
aclump <- clump_data(a, bfile="/Users/gh13047/repo/opengwas-api-internal/opengwas-api/app/ld_files/EUR", plink_bin="plink")
})

3 changes: 3 additions & 0 deletions tests/testthat/test_mvmr.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
context("mvmr")

test_that("control", {
skip("Skip unless you have good access to the API.")
skip_on_ci()
skip_on_cran()
lipids <- mv_extract_exposures(c("ieu-a-299","ieu-a-300","ieu-a-302"))
Expand All @@ -18,6 +19,7 @@ test_that("control", {


test_that("dat", {
skip("Skip unless you have good access to the API.")
skip_on_ci()
skip_on_cran()
a <- mv_extract_exposures(c("ukb-b-5238", "ieu-a-1001"))
Expand All @@ -37,6 +39,7 @@ test_that("dat", {


test_that("ordering", {
skip("Skip unless you have good access to the API.")
skip_on_ci()
skip_on_cran()
lipids1 <- mv_extract_exposures(c("ieu-a-299","ieu-a-300","ieu-a-302"))
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test_mvmr_local.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ context("mvmr local")
# rsid <- unique(c(a$rsid, b$rsid))
# a1 <- ieugwasr::associations(rsid, "ieu-a-2")
# a2 <- ieugwasr::associations(rsid, "ieu-a-1001")
# save(a, b, rsid, a1, a2, file="inst/extdata/test_add_mvmr_local.RData")
# save(a, b, rsid, a1, a2, file="inst/extdata/test_add_mvmr_local.RData", compress = "xz")

load(system.file("extdata", "test_add_mvmr_local.RData", package="TwoSampleMR"))

test_that("mv exposure local", {
skip("Skip unless you have good access to the API.")
skip_on_ci()
skip_on_cran()
f1 <- tempfile()
Expand Down Expand Up @@ -42,4 +43,3 @@ test_that("mv exposure local", {
expect_true(nrow(exposure_dat) > 100)
expect_true(all.equal(exposure_dat, exposure_dat2))
})

Loading

0 comments on commit ebfeb95

Please sign in to comment.