run_TwoSampleMR: Basic TwoSampleMR analysis

View source: R/run_TwoSampleMR.R

run_TwoSampleMRR Documentation

Basic TwoSampleMR analysis

Description

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.

Details

As TwoSampleMR faces seemingly perplexing options, this function intends to simplify various steps in a two-sample MR as in \insertCitedt18;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.

Value

No value is returned but several files.

References

\insertAllCited

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")
harmonise <- TwoSampleMR::harmonise_data(clump,outcome)
prefix <- paste(prot,type,sep="-")
pQTLtools::run_TwoSampleMR(harmonise, mr_plot="pQTLtools", prefix=prefix)
caption <- "Table. MMP.10 variants and FEV1"
knitr::kable(read.delim(paste0(prefix,"-result.txt"),header=TRUE),
             caption=paste(caption, "(result)"))
knitr::kable(read.delim(paste0(prefix,"-heterogeneity.txt"),header=TRUE),
             caption=paste(caption,"(heterogeneity)"))
knitr::kable(read.delim(paste0(prefix,"-pleiotropy.txt"),header=TRUE),
             caption=paste(caption,"(pleiotropy)"))
knitr::kable(read.delim(paste0(prefix,"-single.txt"),header=TRUE),
             caption=paste(caption,"(single)"))
knitr::kable(read.delim(paste0(prefix,"-loo.txt"),header=TRUE),
             caption=paste(caption,"(loo)"))
for (x in c("result","heterogeneity","pleiotropy","single","loo"))
    unlink(paste0(prefix,"-",x,".txt"))


jinghuazhao/pQTLtools documentation built on Dec. 16, 2024, 3:44 p.m.