Skip to contents

Given harmonised data, this function conducts a two-sample MR analysis.

Usage

run_TwoSampleMR(TwoSampleMRinput, mr_plot = "None", prefix = "")

Arguments

TwoSampleMRinput

Harmonised data.

mr_plot

one of "None", "TwoSampleMR", "pQTLtools" for no, the original and the revised plots, respectively.

prefix

a prefix for output files.

Value

No value is returned but several files.

Details

As TwoSampleMR faces seemingly perplexing options, this function intends to simplify various steps in a two-sample MR as in dt18;textualpQTLtools. It is particularly useful when a large numbher of MRs are necessary, e.g., multiple proteins and their cis/trans regions need to be examined, in which case prefix could direct the output to various directories.

Check your authentication token if the example below fails to run.

References

Examples

suppressMessages(require(dplyr))
prot <- "MMP.10"
type <- "cis"
f <- paste0(prot,"-",type,".mrx")
d <- read.table(file.path(find.package("pQTLtools",lib.loc=.libPaths()),"tests",f),
                header=TRUE)
exposure <- TwoSampleMR::format_data(within(d,{P=10^logP}), phenotype_col="prot", snp_col="rsid",
                                     chr_col="Chromosome", pos_col="Posistion",
                                     effect_allele_col="Allele1", other_allele_col="Allele2",
                                     eaf_col="Freq1", beta_col="Effect", se_col="StdErr",
                                     pval_col="P", log_pval=FALSE,
                                     samplesize_col="N")
clump <- exposure[sample(1:nrow(exposure),nrow(exposure)/80),] # TwoSampleMR::clump_data(exposure)
outcome <- TwoSampleMR::extract_outcome_data(snps=exposure$SNP,outcomes="ebi-a-GCST007432")
#> Extracting data for 1106 SNP(s) from 1 GWAS(s)
#> Finding proxies for 1106 SNPs in outcome ebi-a-GCST007432
#> Extracting data for 1106 SNP(s) from 1 GWAS(s)
#> 1 of 1 outcomes
#>  [>] 1 of 3 chunks
#>  [>] 2 of 3 chunks
#>  [>] 3 of 3 chunks
harmonise <- TwoSampleMR::harmonise_data(clump,outcome)
#> Error in check_required_columns(outcome_dat, "outcome"): The following required columns are missing from outcome: SNP, id.outcome, outcome, beta.outcome, se.outcome, effect_allele.outcome, other_allele.outcome
prefix <- paste(prot,type,sep="-")
pQTLtools::run_TwoSampleMR(harmonise, mr_plot="pQTLtools", prefix=prefix)
#> Error: object 'harmonise' not found
caption <- "Table. MMP.10 variants and FEV1"
knitr::kable(read.delim(paste0(prefix,"-result.txt"),header=TRUE),
             caption=paste(caption, "(result)"))
#> Warning: cannot open file 'MMP.10-cis-result.txt': No such file or directory
#> Error in file(file, "rt"): cannot open the connection
knitr::kable(read.delim(paste0(prefix,"-heterogeneity.txt"),header=TRUE),
             caption=paste(caption,"(heterogeneity)"))
#> Warning: cannot open file 'MMP.10-cis-heterogeneity.txt': No such file or directory
#> Error in file(file, "rt"): cannot open the connection
knitr::kable(read.delim(paste0(prefix,"-pleiotropy.txt"),header=TRUE),
             caption=paste(caption,"(pleiotropy)"))
#> Warning: cannot open file 'MMP.10-cis-pleiotropy.txt': No such file or directory
#> Error in file(file, "rt"): cannot open the connection
knitr::kable(read.delim(paste0(prefix,"-single.txt"),header=TRUE),
             caption=paste(caption,"(single)"))
#> Warning: cannot open file 'MMP.10-cis-single.txt': No such file or directory
#> Error in file(file, "rt"): cannot open the connection
knitr::kable(read.delim(paste0(prefix,"-loo.txt"),header=TRUE),
             caption=paste(caption,"(loo)"))
#> Warning: cannot open file 'MMP.10-cis-loo.txt': No such file or directory
#> Error in file(file, "rt"): cannot open the connection
for (x in c("result","heterogeneity","pleiotropy","single","loo"))
    unlink(paste0(prefix,"-",x,".txt"))