diff --git a/.Rbuildignore b/.Rbuildignore index e0f1cc63..ed8b4b66 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -16,3 +16,4 @@ cache$ ^index\.md$ ^README\.Rmd$ ^CITATION\.cff$ +^README\.html$ diff --git a/.github/workflows/check-full.yaml b/.github/workflows/check-full.yaml index a68277b4..028d375d 100644 --- a/.github/workflows/check-full.yaml +++ b/.github/workflows/check-full.yaml @@ -5,7 +5,7 @@ on: branches: [main, master] workflow_dispatch: schedule: - - cron: '37 2 * * TUE' # run at 7:37am UTC on Mondays + - cron: '37 2 * * TUE' # run at 2:37am UTC on Tuesdays name: R-CMD-check @@ -25,13 +25,14 @@ jobs: - {os: ubuntu-latest, r: 'release'} - {os: ubuntu-latest, r: 'oldrel-1'} - {os: ubuntu-latest, r: 'oldrel-2'} + - {os: ubuntu-latest, r: 'oldrel-3'} env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} R_KEEP_PKG_SOURCE: yes steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: r-lib/actions/setup-pandoc@v2 diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml index 80d76bea..3ff58464 100644 --- a/.github/workflows/pkgdown.yaml +++ b/.github/workflows/pkgdown.yaml @@ -19,8 +19,10 @@ jobs: group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }} env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + permissions: + contents: write steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: r-lib/actions/setup-pandoc@v2 diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index 9249b24a..6642deb4 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -13,7 +13,7 @@ jobs: env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: r-lib/actions/setup-r@v2 diff --git a/.gitignore b/.gitignore index d9af4be6..6762c310 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ vignettes/*.R vignettes/*.html docs tests/testthat/*.pdf +README.html diff --git a/CITATION.cff b/CITATION.cff index 996e0c3e..acdc8913 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -21,8 +21,8 @@ authors: orcid: "https://orcid.org/0000-0003-4655-4511" title: "TwoSampleMR R package" type: software -version: 0.5.7 -date-released: 2023-05-29 +version: 0.5.8 +date-released: 2023-11-16 doi: "10.5281/zenodo.4636570" url: "https://mrcieu.github.io/TwoSampleMR/index.html" repository-code: "https://github.com/MRCIEU/TwoSampleMR" diff --git a/DESCRIPTION b/DESCRIPTION index 59f5c661..056c2b0e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: TwoSampleMR Title: Two Sample MR Functions and Interface to MR Base Database -Version: 0.5.7 +Version: 0.5.8 Authors@R: c( person("Gibran", "Hemani", , "g.hemani@bristol.ac.uk", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-0920-1055")), @@ -22,6 +22,9 @@ Description: A package for performing Mendelian randomization using GWAS functionality in this package, but for any serious work we strongly recommend using this R package. License: MIT + file LICENSE +URL: https://github.com/MRCIEU/TwoSampleMR, + https://mrcieu.github.io/TwoSampleMR/ +BugReports: https://github.com/MRCIEU/TwoSampleMR/issues/ Depends: R (>= 4.0.0) Imports: diff --git a/NAMESPACE b/NAMESPACE index df469578..7e7dedac 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -113,4 +113,5 @@ export(subset_on_method) export(trim) export(weighted_median) export(weighted_median_bootstrap) +import(data.table) importFrom(magrittr,"%>%") diff --git a/NEWS.md b/NEWS.md index f801e377..96afebb6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,11 @@ +# TwoSampleMR v0.5.8 + +(Release date: 2023-11-16) + +* Improved speed of harmonisation using data.table functions (thanks @nicksunderland) +* Updated URL to R-CMD-check README badge +* Updates to GitHub Actions workflows + TwoSampleMR v0.5.7 ============== diff --git a/R/TwoSampleMR-package.R b/R/TwoSampleMR-package.R index f8a2f5fd..df79c7fb 100644 --- a/R/TwoSampleMR-package.R +++ b/R/TwoSampleMR-package.R @@ -2,7 +2,7 @@ #' #' A package for performing Mendelian randomization using GWAS summary data. #' It uses the [IEU GWAS database](https://gwas.mrcieu.ac.uk/) to obtain data automatically, -#' and a wide range of methods to run the analysis. You can use the [MR-Base web app](http://www.mrbase.org/) +#' and a wide range of methods to run the analysis. You can use the [MR-Base web app](https://www.mrbase.org/) #' to try out a limited range of the functionality in this package, #' but for any serious work we strongly recommend using this R package. #' diff --git a/R/globals.R b/R/globals.R index b2e0d30d..46fee94c 100644 --- a/R/globals.R +++ b/R/globals.R @@ -16,5 +16,5 @@ utils::globalVariables(c( "steiger_filtered", "theme", "theme_bw", "tibble", "tot", "type", "unit", "up", "up_ci", "use_by_default", "value", "vgu", "vgx", "word_document", "complete.cases", ".", "eaf", "id", "l2", "l2.x", "n1", "n2", "rsid", "z", - "orig_SNP", "df" + "orig_SNP", "df", "SNP_index" )) diff --git a/R/harmonise.R b/R/harmonise.R index 506d68da..155af45f 100644 --- a/R/harmonise.R +++ b/R/harmonise.R @@ -546,12 +546,12 @@ harmonise_11 <- function(SNP, A1, B1, betaA, betaB, fA, fB, tolerance, action) return(d) } - +#' @import data.table harmonise <- function(dat, tolerance, action) { dat$orig_SNP<-dat$SNP - SNP_index<-sapply(1:length(dat$SNP),function(i)sum(dat$SNP[1:i]==dat$SNP[i])) - dat$SNP<-paste0(dat$SNP,"_",SNP_index) + dat <- data.table::data.table(dat)[, SNP_index := 1:.N, by="SNP"] + dat$SNP <- paste0(dat$SNP, "_", dat$SNP_index) SNP <- dat$SNP A1 <- dat$effect_allele.exposure A2 <- dat$other_allele.exposure diff --git a/README.md b/README.md index 00f6c0d9..842ef110 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,7 @@ -[![Build -Status](https://github.com/MRCIEU/TwoSampleMR/workflows/R-CMD-check/badge.svg)](https://github.com/MRCIEU/TwoSampleMR/actions?workflow=R-CMD-check) +[![R-CMD-check](https://github.com/MRCIEU/TwoSampleMR/actions/workflows/check-full.yaml/badge.svg)](https://github.com/MRCIEU/TwoSampleMR/actions/workflows/check-full.yaml) [![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental) [![DOI](https://zenodo.org/badge/49515156.svg)](https://zenodo.org/badge/latestdoi/49515156) @@ -17,7 +16,7 @@ coverage](https://codecov.io/gh/MRCIEU/TwoSampleMR/branch/master/graph/badge.svg A package for performing Mendelian randomization using GWAS summary data. It uses the [IEU GWAS database](https://gwas.mrcieu.ac.uk/) to obtain data automatically, and a wide range of methods to run the -analysis. You can use the [MR-Base web app](http://www.mrbase.org/) to +analysis. You can use the [MR-Base web app](https://www.mrbase.org/) to try out a limited range of the functionality in this package, but for any serious work we strongly recommend using this R package. diff --git a/index.md b/index.md index 6d1f9785..1c798b3e 100644 --- a/index.md +++ b/index.md @@ -1,12 +1,12 @@ # Mendelian randomization with GWAS summary data -[![Build Status](https://github.com/MRCIEU/TwoSampleMR/workflows/R-CMD-check/badge.svg)](https://github.com/MRCIEU/TwoSampleMR/actions?workflow=R-CMD-check) +[![R-CMD-check](https://github.com/MRCIEU/TwoSampleMR/actions/workflows/check-full.yaml/badge.svg)](https://github.com/MRCIEU/TwoSampleMR/actions/workflows/check-full.yaml) [![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental) [![DOI](https://zenodo.org/badge/49515156.svg)](https://zenodo.org/badge/latestdoi/49515156) [![Codecov test coverage](https://codecov.io/gh/MRCIEU/TwoSampleMR/branch/master/graph/badge.svg)](https://codecov.io/gh/MRCIEU/TwoSampleMR?branch=master) -A package for performing Mendelian randomization using GWAS summary data. It uses the [IEU GWAS database](https://gwas.mrcieu.ac.uk/) to obtain data automatically, and a wide range of methods to run the analysis. You can use the [MR-Base web app](http://www.mrbase.org/) to try out a limited range of the functionality in this package, but for any serious work we strongly recommend using this R package. +A package for performing Mendelian randomization using GWAS summary data. It uses the [IEU GWAS database](https://gwas.mrcieu.ac.uk/) to obtain data automatically, and a wide range of methods to run the analysis. You can use the [MR-Base web app](https://www.mrbase.org/) to try out a limited range of the functionality in this package, but for any serious work we strongly recommend using this R package. ## January 2020 major update diff --git a/inst/sandpit/vignette.rmd b/inst/sandpit/vignette.rmd index 973c0669..46f262ce 100644 --- a/inst/sandpit/vignette.rmd +++ b/inst/sandpit/vignette.rmd @@ -39,7 +39,7 @@ The function looks up the rs IDs in biomart to validate them and retrieve chromo ### GWAS catalog -The GWAS catalog ([http://www.ebi.ac.uk/gwas/](http://www.ebi.ac.uk/gwas/)) is a collection of `r data(gwas_catalog); nrow(gwas_catalog)` reported associations against `r length(unique(gwas_catalog$Phenotype))` traits. These have the potential to be used as instruments in 2SMR. We have downloaded the GWAS catalog and made important formatting changes in order to simplify usage of these data for MR. **Please note that the reformatting of this data may be unreliable**. +The GWAS catalog ([https://www.ebi.ac.uk/gwas/](https://www.ebi.ac.uk/gwas/)) is a collection of `r data(gwas_catalog); nrow(gwas_catalog)` reported associations against `r length(unique(gwas_catalog$Phenotype))` traits. These have the potential to be used as instruments in 2SMR. We have downloaded the GWAS catalog and made important formatting changes in order to simplify usage of these data for MR. **Please note that the reformatting of this data may be unreliable**. To use the GWAS catalog: diff --git a/man/TwoSampleMR-package.Rd b/man/TwoSampleMR-package.Rd index 5e4a3352..b36eedb4 100644 --- a/man/TwoSampleMR-package.Rd +++ b/man/TwoSampleMR-package.Rd @@ -9,7 +9,7 @@ \description{ A package for performing Mendelian randomization using GWAS summary data. It uses the \href{https://gwas.mrcieu.ac.uk/}{IEU GWAS database} to obtain data automatically, -and a wide range of methods to run the analysis. You can use the \href{http://www.mrbase.org/}{MR-Base web app} +and a wide range of methods to run the analysis. You can use the \href{https://www.mrbase.org/}{MR-Base web app} to try out a limited range of the functionality in this package, but for any serious work we strongly recommend using this R package. } diff --git a/vignettes/perform_mr.Rmd b/vignettes/perform_mr.Rmd index 38e9ae26..c0a71df7 100644 --- a/vignettes/perform_mr.Rmd +++ b/vignettes/perform_mr.Rmd @@ -499,7 +499,7 @@ This is an implementation of the method described here: [Hemani G, Tilling K, Davey Smith G.
**Orienting the causal relationship between imprecisely measured traits using GWAS summary data.**
-PLoS Genetics. 2017. 13(11): e1007081.](http://journals.plos.org/plosgenetics/article?id=10.1371/journal.pgen.1007081) +PLoS Genetics. 2017. 13(11): e1007081.](https://journals.plos.org/plosgenetics/article?id=10.1371/journal.pgen.1007081) In MR it is assumed that the instruments influence the exposure first and then the outcome through the exposure. But sometimes this is difficult to evaluate, for example is a cis-acting SNP influencing gene expression levels or DNA methylation levels first? The causal direction between the hypothesised exposure and outcomes can be tested using the Steiger test [@hemani-plosgen-2017]. For example: @@ -640,7 +640,7 @@ MendelianRandomization::mr_ivw(dat2[[1]], correl = TRUE) ## MR-MoE: Using a mixture of experts machine learning approach -We recently developed MR-MoE, a method to choose the most appropriate amongst several MR tests using a machine learning algorithm. Note that the method is still under review, but full details are described here: [biorxiv.org/content/early/2017/08/23/173682](http://www.biorxiv.org/content/early/2017/08/23/173682). +We recently developed MR-MoE, a method to choose the most appropriate amongst several MR tests using a machine learning algorithm. Note that the method is still under review, but full details are described here: . MR-MoE operates by taking a set of harmonised data, inferring some characteristics about the dataset, and using those characteristics to predict how well each of the different MR methods will perform on the dataset, in terms of maximising power while minimising false discovery rates. diff --git a/vignettes/refs.bib b/vignettes/refs.bib index 59efce9d..daceda70 100644 --- a/vignettes/refs.bib +++ b/vignettes/refs.bib @@ -18,7 +18,7 @@ @article{DaveySmith2003 number = {1}, pages = {1--22}, title = {{'Mendelian randomization': can genetic epidemiology contribute to understanding environmental determinants of disease?}}, - url = {http://www.ije.oxfordjournals.org/cgi/doi/10.1093/ije/dyg070}, + url = {https://doi.org/10.1093/ije/dyg070}, volume = {32}, year = {2003}, } @@ -27,7 +27,7 @@ @article{DaveySmithHemani2014 author = {{Davey Smith}, George and Hemani, Gibran}, doi = {10.1093/hmg/ddu328}, issn = {0964-6906}, - journal = {Human molecular genetics}, + journal = {Human Molecular Genetics}, month = {jul}, number = {R1}, pages = {R89--R98}, @@ -35,6 +35,7 @@ @article{DaveySmithHemani2014 title = {{Mendelian randomization: genetic anchors for causal inference in epidemiological studies}}, volume = {23}, year = {2014}, + url = {https://doi.org/10.1093/hmg/ddu328} } @article{Pierce2013, @@ -47,8 +48,8 @@ @article{Pierce2013 number = {7}, pages = {1177--1184}, pmid = {23863760}, - title = {{Efficient design for Mendelian randomization studies: subsample and 2-sample instrumental variable estimators.}}, - url = {http://www.pubmedcentral.nih.gov/articlerender.fcgi?artid=3783091{\&}tool=pmcentrez{\&}rendertype=abstract}, + title = {{Efficient design for Mendelian randomization studies: subsample and 2-sample instrumental variable estimators}}, + url = {https://doi.org/10.1093/aje/kwt084}, volume = {178}, year = {2013}, } @@ -64,7 +65,7 @@ @article{Speliotes2010 pages = {937--948}, pmid = {20935630}, title = {{Association analyses of 249,796 individuals reveal 18 new loci associated with body mass index}}, - url = {http://www.pubmedcentral.nih.gov/articlerender.fcgi?artid=3014648{\&}tool=pmcentrez{\&}rendertype=abstract}, + url = {https://doi.org/10.1038/ng.686}, volume = {42}, year = {2010}, }