This package, magpie, aims to perform statistical power analysis for differential RNA methylation calling, using MeRIP-Seq data. It takes real MeRIP-Seq data as input for parameter estimation, allows for options of setting various sample sizes, sequencing depths, and testing methods, and calculates FDR, FDC, power, and precision as evaluation metrics. It also offers functions to save results into .xlsx files and produce basic line plots.
magpie 1.6.0
MeRIP-Seq (methylated RNA immunoprecipitation followed by sequencing) is a method used to study the epigenetic regulation of gene expression by identifying methylated RNA molecules in a sample. It involves immunoprecipitation of methylated RNA using an antibody specific for methylated nucleotides, followed by high-throughput sequencing of the immunoprecipitated RNA. The resulting data provide a snapshot of the methylation status of RNA molecules, allowing researchers to investigate the role of methylation in the regulation of gene expression and other biological processes. After being collected from two or more biological conditions, MeRIP-Seq data is typically analyzed using computational tools to identify differentially methylated regions (DMRs). DMR detection can uncover the functional significance of m6A methylation and identify potential therapeutic targets for disease such as cancer.
To establish the statistical rigor of MeRIP-Seq experiments, it is important to carefully consider sample size during the study design process in order to ensure that the experiment is adequately powered to detect differentially methylated RNA (DMR) regions. However, there is no such tool available, so we developed the R package magpie, a simulation-based tool for performing power calculations on MeRIP-Seq data. magpie has two main functions:
Power calculation: Given a MeRIP-Seq dataset, various experimental scenarios, and a selected test method, magpie can calculate the statistical power of the experiment and output the results.
Results preservation and visualization: magpie can save the results of the power calculation as an Excel file, and it can also produce basic line plots that allow the user to visualize the results.
From GitHub:
install.packages("devtools") # if you have not installed "devtools" package
library(devtools)
install_github("https://github.com/dxd429/magpie",
build_vignettes = TRUE
)
From Bioconductor:
if (!requireNamespace("BiocManager", quietly = TRUE)) {
install.packages("BiocManager")
}
BiocManager::install("magpie")
To view the package vignette in HTML format, run the following lines in R:
library(magpie)
vignette("magpie")
To get started with magpie, users are expected to provide MeRIP-Seq data for parameter estimation. This includes paired input and IP .BAM files for each experimental condition, along with the matching annotation file in the *.sqlite
format. Since .BAM files are generally large, it is also encouraged to use data of only one or a few chromosomes.
magpie offers the function quickPower()
for users who need quick power calculation results without their own simulations. This function takes few seconds to run and uses pre-calculated results from three publicly available MeRIP-seq datasets. The details of these datasets can be found in 4.2). To use this function and save and plot the results:
library(magpie)
power.test <- quickPower(dataset = "GSE46705") # Options are 'GSE46705', 'GSE55575', and 'GSE94613'.
Save results into .xlsx files:
### write out .xlsx
writeToxlsx(power.test, file = "test_TRESS.xlsx")
### write out stratified results
writeToxlsx_strata(power.test, file = "test_strata_TRESS.xlsx")
Produce basic line plots for visulization:
### plot FDR under sequencing depth 1x
plotRes(power.test, depth_factor = 1, value_option = "FDR")
### plot all in a panel under sequencing depth 1x
plotAll(power.test, depth_factor = 1)
### plot a FDR strata result
plotStrata(power.test, value_option = "FDR")
### plot all strata results in a panel
plotAll_Strata(power.test)
In order to best mimic the characteristics of real data, magpie expects users to provide real MeRIP-Seq datasets, if not directly extracting our pre-calculated results.
magpie requires paired input and IP .BAM files for each replicate of both conditions. Example file names are as follows: “Ctrl1.input.bam” & Ctrl1.ip.bam“,”Ctrl2.input.bam" & Ctrl2.ip.bam“,”Case1.input.bam" & Case1.ip.bam“,”Case2.input.bam" & Case2.ip.bam", for a 2 controls vs 2 cases DMR calling study. Note that names of provided .BAM files should be ordered carefully so that samples from different conditions will not be mistreated.
For illustration purpose, we include a sample dataset (GSE46705) from a study investigating how METTL3-METTL14 complex mediates mammalian nuclear RNA N6-adenosine methylation in our experimental data package magpieData
on GitHub, which can be installed with:
install.packages("devtools") # if you have not installed "devtools" package
library(devtools)
install_github("https://github.com/dxd429/magpieData",
build_vignettes = TRUE
)
The data package contains four .BAM files of two wild type (WT) replicates, four .BAM files of two knockdown of complex METTL3 replicates only on chromosome 15, and one genome annotation file.
In terms of the annotation file, it should match the reference genome version when obtaining the .BAM files, and be saved in the format of *.sqlite
, which can be created with R function makeTxDbFromUCSC()
from Bioconductor package GenomicFeatures
:
## Use "makeTxDbFromUCSC" function to create an annotation file of hg18
library(GenomicFeatures)
hg18 <- makeTxDbFromUCSC(genome = "hg18", tablename = "knownGene")
saveDb(hg18, file = "hg18.sqlite")
magpie offers two functions for power evaluation: powerEval()
and quickPower()
. If users prefer to quickly examine the power evaluation results using the built-in datasets, they can use the quickPower()
function. Otherwise, users can use the powerEval()
function to perform power evaluation on their own data and customize the simulation settings. The output of these two functions is a list of power measurements under various experimental settings, such as FDR
, Precision
, and Statistical power
.
With .BAM files and an annotation file, powerEval()
enables users to specify number of simulations (nsim
), sample sizes (N.reps
), sequencing depths (depth_factor
), FDR thresholds (thres
), and testing methods (Test_method
).
Users should always indicate the percentage of the whole genome covered by their dataset, whether it’s complete or partial (bam_factor
). Here, bam_factor
allows for simulating whole-genome data using a smaller subset of it, under the assumption that DMR signals are relatively evenly distributed across chromosomes.
We demonstrate the usage of powerEval()
with the example dataset from R package magpieData
:
library(magpieData)
library(magpie)
### Get the example data
BAM_path <- getBAMpath()
### Call powerEval()
power.test <- powerEval(
Input.file = c("Ctrl1.chr15.input.bam", "Ctrl2.chr15.input.bam", "Case1.chr15.input.bam", "Case2.chr15.input.bam"),
IP.file = c("Ctrl1.chr15.ip.bam", "Ctrl2.chr15.ip.bam", "Case1.chr15.ip.bam", "Case2.chr15.ip.bam"),
BamDir = BAM_path,
annoDir = paste0(BAM_path, "/hg18_chr15.sqlite"),
variable = rep(c("Ctrl", "Trt"), each = 2),
bam_factor = 0.03,
nsim = 10,
N.reps = c(2, 3, 5, 7),
depth_factor = c(1, 2),
thres = c(0.01, 0.05, 0.1),
Test_method = "TRESS" ## TRESS or exomePeak2
)
To use your own data, replace Input.file
and IP.file
with the names of your .BAM files, and set BamDir
and annoDir
to the file paths for your data. Make sure that the order of the variable
corresponds to the order of your data files.
Another power calculation function is quickPower()
. Unlike powerEval()
which often takes a while to run, quickPower()
produces results in seconds, by directly extracting results from three pre-evaluated datasets on GEO:
GSE46705
: Human HeLa cell line: Two replicates of wild type (WT) and two replicates of knockdown (KD) of complex METTL3.
GSE55575
: Mouse embryonic fibroblasts: Two replicates of wild type (WT) and four replicates of knockdown (KD) of WTAP.
GSE94613
: Human leukemia cell line: Four replicates of wild type (WT) and eight replicates of knockdown (KD) of complex METTL3.
Here, we use quickPower()
to get power evaluation results of GSE46705
, tested by TRESS
:
library(magpie)
power.test <- quickPower(dataset = "GSE46705")
Magpie computes power evaluation metrics for each experimental scenario defined in the function arguments, the results it generates include:
FDR: The ratio of number of false positives to the number of positive discoveries.
FDC: The ratio of number of false positives to the number of true positives.
Power: Statistical power.
Precision: The ratio of number of true positives to the number of positive discoveries.
Once users have obtained a list of power measurements using either powerEval()
or quickPower()
, they can use functions in magpie to save the results as a formatted .xlsx file and generate basic line plots.
magpie provides two functions: writeToxlsx()
and writeToxlsx_strata()
, for saving results to a formatted .xlsx file. writeToxlsx()
allows you to save power measurements for different sample sizes, FDR thresholds, and sequencing depths, while writeToxlsx_strata()
writes out the results stratified by input expression level and for different sample sizes. Note that we only evaluate power under the original sequencing depth (depth_factor = 1
) and FDR threshold of 0.05 (thres = 1
).
Here we save the output from quickPower()
to corresponding .xlsx
files:
### write out .xlsx
writeToxlsx(power.test, file = "test_TRESS.xlsx")
### write out stratified results
writeToxlsx_strata(power.test, file = "test_strata_TRESS.xlsx")
The generated .xlsx
files are formatted as follows:
FDR | N.rep | 0.01 | 0.05 | 0.1 |
---|---|---|---|---|
2 | 0.36 | 0.48 | 0.57 | |
3 | 0.14 | 0.27 | 0.38 | |
5 | 0.06 | 0.13 | 0.21 | |
7 | 0.04 | 0.11 | 0.17 |
FDR | N.rep | (0, 27.68] | (27.68, 54.3] | (54.3, 92.64] | (92.64, Inf] |
---|---|---|---|---|---|
2 | 0.41 | 0.46 | 0.47 | 0.58 | |
3 | 0.23 | 0.30 | 0.27 | 0.28 | |
5 | 0.15 | 0.16 | 0.11 | 0.12 | |
7 | 0.12 | 0.14 | 0.08 | 0.11 |
As mentioned before, magpie also provides four plotting functions: plotRes()
, plotAll()
, plotStrata()
, and plotAll_Strata()
, for figure generating. In general, plotRes()
and plotStrata()
produce individual plots, while plotAll()
and `plotAll_Strata()
produce four plots in a 2 x 2 panel.
Again, we demonstrate these four functions with the previous output from `quickPower()``:
### plot FDR under sequencing depth 1x
plotRes(power.test, depth_factor = 1, value_option = "FDR")
### plot all in a panel under sequencing depth 1x
plotAll(power.test, depth_factor = 1)
### plot a FDR strata result
plotStrata(power.test, value_option = "FDR")
### plot all strata results in a panel
plotAll_Strata(power.test)
## R version 4.4.1 (2024-06-14)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 24.04.1 LTS
##
## Matrix products: default
## BLAS: /home/biocbuild/bbs-3.20-bioc/R/lib/libRblas.so
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.12.0
##
## locale:
## [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
## [3] LC_TIME=en_GB LC_COLLATE=C
## [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
## [7] LC_PAPER=en_US.UTF-8 LC_NAME=C
## [9] LC_ADDRESS=C LC_TELEPHONE=C
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
##
## time zone: America/New_York
## tzcode source: system (glibc)
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] magpie_1.6.0 BiocStyle_2.34.0
##
## loaded via a namespace (and not attached):
## [1] DBI_1.2.3 bitops_1.0-9
## [3] rlang_1.1.4 magrittr_2.0.3
## [5] matrixStats_1.4.1 compiler_4.4.1
## [7] RSQLite_2.3.7 GenomicFeatures_1.58.0
## [9] systemfonts_1.1.0 png_0.1-8
## [11] vctrs_0.6.5 reshape2_1.4.4
## [13] stringr_1.5.1 pkgconfig_2.0.3
## [15] crayon_1.5.3 fastmap_1.2.0
## [17] magick_2.8.5 XVector_0.46.0
## [19] utf8_1.2.4 Rsamtools_2.22.0
## [21] rmarkdown_2.28 UCSC.utils_1.2.0
## [23] tinytex_0.53 bit_4.5.0
## [25] xfun_0.48 zlibbioc_1.52.0
## [27] cachem_1.1.0 GenomeInfoDb_1.42.0
## [29] jsonlite_1.8.9 blob_1.2.4
## [31] highr_0.11 DelayedArray_0.32.0
## [33] BiocParallel_1.40.0 parallel_4.4.1
## [35] R6_2.5.1 bslib_0.8.0
## [37] stringi_1.8.4 RColorBrewer_1.1-3
## [39] rtracklayer_1.66.0 GenomicRanges_1.58.0
## [41] jquerylib_0.1.4 Rcpp_1.0.13
## [43] bookdown_0.41 SummarizedExperiment_1.36.0
## [45] knitr_1.48 IRanges_2.40.0
## [47] Matrix_1.7-1 tidyselect_1.2.1
## [49] rstudioapi_0.17.1 abind_1.4-8
## [51] yaml_2.3.10 codetools_0.2-20
## [53] curl_5.2.3 lattice_0.22-6
## [55] tibble_3.2.1 plyr_1.8.9
## [57] Biobase_2.66.0 KEGGREST_1.46.0
## [59] evaluate_1.0.1 xml2_1.3.6
## [61] zip_2.3.1 Biostrings_2.74.0
## [63] pillar_1.9.0 BiocManager_1.30.25
## [65] TRESS_1.12.0 MatrixGenerics_1.18.0
## [67] stats4_4.4.1 generics_0.1.3
## [69] RCurl_1.98-1.16 S4Vectors_0.44.0
## [71] ggplot2_3.5.1 munsell_0.5.1
## [73] scales_1.3.0 aod_1.3.3
## [75] glue_1.8.0 tools_4.4.1
## [77] BiocIO_1.16.0 openxlsx_4.2.7.1
## [79] locfit_1.5-9.10 GenomicAlignments_1.42.0
## [81] XML_3.99-0.17 grid_4.4.1
## [83] AnnotationDbi_1.68.0 colorspace_2.1-1
## [85] GenomeInfoDbData_1.2.13 restfulr_0.0.15
## [87] cli_3.6.3 kableExtra_1.4.0
## [89] fansi_1.0.6 viridisLite_0.4.2
## [91] S4Arrays_1.6.0 svglite_2.1.3
## [93] dplyr_1.1.4 gtable_0.3.6
## [95] DESeq2_1.46.0 sass_0.4.9
## [97] digest_0.6.37 BiocGenerics_0.52.0
## [99] SparseArray_1.6.0 rjson_0.2.23
## [101] memoise_2.0.1 htmltools_0.5.8.1
## [103] lifecycle_1.0.4 httr_1.4.7
## [105] mime_0.12 bit64_4.5.2