Results from the univariate regressions performed using can be combined in a post-processing step to perform multivariate hypothesis testing. In this example, we fit on transcript-level counts and then perform multivariate hypothesis testing by combining transcripts at the gene-level. This is done with the function.
Read in transcript counts from the package.
library(readr)
library(tximport)
library(tximportData)
# specify directory
path <- system.file("extdata", package = "tximportData")
# read sample meta-data
samples <- read.table(file.path(path, "samples.txt"), header = TRUE)
samples.ext <- read.table(file.path(path, "samples_extended.txt"), header = TRUE, sep = "\t")
# read assignment of transcripts to genes
# remove genes on the PAR, since these are present twice
tx2gene <- read_csv(file.path(path, "tx2gene.gencode.v27.csv"))
tx2gene <- tx2gene[grep("PAR_Y", tx2gene$GENEID, invert = TRUE), ]
# read transcript-level quatifictions
files <- file.path(path, "salmon", samples$run, "quant.sf.gz")
txi <- tximport(files, type = "salmon", txOut = TRUE)
# Create metadata simulating two conditions
sampleTable <- data.frame(condition = factor(rep(c("A", "B"), each = 3)))
rownames(sampleTable) <- paste0("Sample", 1:6)
Perform standard analysis at the transcript-level
library(variancePartition)
library(edgeR)
# Prepare transcript-level reads
dge <- DGEList(txi$counts)
design <- model.matrix(~condition, data = sampleTable)
isexpr <- filterByExpr(dge, design)
dge <- dge[isexpr, ]
dge <- calcNormFactors(dge)
# Estimate precision weights
vobj <- voomWithDreamWeights(dge, ~condition, sampleTable)
# Fit regression model one transcript at a time
fit <- dream(vobj, ~condition, sampleTable)
fit <- eBayes(fit)
Combine the transcript-level results at the gene-level. The mapping between transcript and gene is stored in as a list.
# Prepare transcript to gene mapping
# keep only transcripts present in vobj
# then convert to list with key GENEID and values TXNAMEs
keep <- tx2gene$TXNAME %in% rownames(vobj)
tx2gene.lst <- unstack(tx2gene[keep, ])
# Run multivariate test on entries in each feature set
# Default method is "FE.empirical", but use "FE" here to reduce runtime
res <- mvTest(fit, vobj, tx2gene.lst, coef = "conditionB", method = "FE")
# truncate gene names since they have version numbers
# ENST00000498289.5 -> ENST00000498289
res$ID.short <- gsub("\\..+", "", res$ID)
Perform gene set analysis using on the gene-level test statistics.
# must have zenith > v1.0.2
library(zenith)
library(GSEABase)
gs <- get_MSigDB("C1", to = "ENSEMBL")
df_gsa <- zenithPR_gsa(res$stat, res$ID.short, gs, inter.gene.cor = .05)
head(df_gsa)
## NGenes Correlation delta se p.less p.greater PValue Direction
## M7078_chr2p16 30 0.05 1.6648559 0.5654000 0.99838058 0.001619416 0.003238831 Up
## M14982_chr7p13 26 0.05 1.1308186 0.5822422 0.97393338 0.026066620 0.052133239 Up
## M7314_chr4p14 25 0.05 -1.1343531 0.5871399 0.02668882 0.973311179 0.053377641 Down
## M5824_chr11p13 30 0.05 -1.0127799 0.5656396 0.03669606 0.963303938 0.073392125 Down
## M10517_chr4q24 21 0.05 -1.0093202 0.6108457 0.04924334 0.950756658 0.098486684 Down
## M3783_chr2q37 73 0.05 0.8177321 0.4968469 0.95009202 0.049907978 0.099815957 Up
## FDR
## M7078_chr2p16 0.8032301
## M14982_chr7p13 0.9998700
## M7314_chr4p14 0.9998700
## M5824_chr11p13 0.9998700
## M10517_chr4q24 0.9998700
## M3783_chr2q37 0.9998700
## R Under development (unstable) (2023-11-11 r85510)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 22.04.3 LTS
##
## Matrix products: default
## BLAS: /home/biocbuild/bbs-3.19-bioc/R/lib/libRblas.so
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0
##
## locale:
## [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_GB
## [4] LC_COLLATE=C LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
## [7] LC_PAPER=en_US.UTF-8 LC_NAME=C LC_ADDRESS=C
## [10] LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
##
## time zone: America/New_York
## tzcode source: system (glibc)
##
## attached base packages:
## [1] stats4 stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] org.Hs.eg.db_3.18.0 msigdbr_7.5.1 GSEABase_1.65.0
## [4] graph_1.81.0 annotate_1.81.0 XML_3.99-0.15
## [7] AnnotationDbi_1.65.2 IRanges_2.37.0 S4Vectors_0.41.1
## [10] Biobase_2.63.0 BiocGenerics_0.49.1 zenith_1.5.1
## [13] tximportData_1.31.0 tximport_1.31.0 readr_2.1.4
## [16] edgeR_4.1.1 pander_0.6.5 variancePartition_1.33.2
## [19] BiocParallel_1.37.0 limma_3.59.1 ggplot2_3.4.4
## [22] knitr_1.45
##
## loaded via a namespace (and not attached):
## [1] jsonlite_1.8.7 magrittr_2.0.3 farver_2.1.1
## [4] nloptr_2.0.3 rmarkdown_2.25 zlibbioc_1.49.0
## [7] vctrs_0.6.4 memoise_2.0.1 minqa_1.2.6
## [10] RCurl_1.98-1.13 progress_1.2.2 S4Arrays_1.3.0
## [13] htmltools_0.5.7 curl_5.1.0 broom_1.0.5
## [16] SparseArray_1.3.1 sass_0.4.7 KernSmooth_2.23-22
## [19] bslib_0.5.1 pbkrtest_0.5.2 plyr_1.8.9
## [22] cachem_1.0.8 lifecycle_1.0.4 iterators_1.0.14
## [25] pkgconfig_2.0.3 Matrix_1.6-3 R6_2.5.1
## [28] fastmap_1.1.1 MatrixGenerics_1.15.0 GenomeInfoDbData_1.2.11
## [31] rbibutils_2.2.16 digest_0.6.33 numDeriv_2016.8-1.1
## [34] colorspace_2.1-0 GenomicRanges_1.55.1 RSQLite_2.3.3
## [37] filelock_1.0.2 labeling_0.4.3 RcppZiggurat_0.1.6
## [40] fansi_1.0.5 abind_1.4-5 httr_1.4.7
## [43] compiler_4.4.0 bit64_4.0.5 aod_1.3.2
## [46] withr_2.5.2 backports_1.4.1 DBI_1.1.3
## [49] highr_0.10 gplots_3.1.3 MASS_7.3-60.1
## [52] DelayedArray_0.29.0 corpcor_1.6.10 gtools_3.9.4
## [55] caTools_1.18.2 tools_4.4.0 remaCor_0.0.16
## [58] glue_1.6.2 nlme_3.1-163 grid_4.4.0
## [61] reshape2_1.4.4 generics_0.1.3 snow_0.4-4
## [64] gtable_0.3.4 tzdb_0.4.0 tidyr_1.3.0
## [67] hms_1.1.3 utf8_1.2.4 XVector_0.43.0
## [70] pillar_1.9.0 stringr_1.5.0 babelgene_22.9
## [73] vroom_1.6.4 splines_4.4.0 dplyr_1.1.3
## [76] BiocFileCache_2.11.1 lattice_0.22-5 bit_4.0.5
## [79] tidyselect_1.2.0 locfit_1.5-9.8 Biostrings_2.71.1
## [82] SummarizedExperiment_1.33.0 RhpcBLASctl_0.23-42 xfun_0.41
## [85] statmod_1.5.0 matrixStats_1.1.0 KEGGgraph_1.63.0
## [88] stringi_1.8.1 yaml_2.3.7 boot_1.3-28.1
## [91] evaluate_0.23 codetools_0.2-19 archive_1.1.6
## [94] tibble_3.2.1 Rgraphviz_2.47.0 cli_3.6.1
## [97] RcppParallel_5.1.7 xtable_1.8-4 Rdpack_2.6
## [100] munsell_0.5.0 jquerylib_0.1.4 Rcpp_1.0.11
## [103] GenomeInfoDb_1.39.1 EnvStats_2.8.1 dbplyr_2.4.0
## [106] png_0.1-8 Rfast_2.1.0 parallel_4.4.0
## [109] blob_1.2.4 prettyunits_1.2.0 bitops_1.0-7
## [112] lme4_1.1-35.1 mvtnorm_1.2-3 lmerTest_3.1-3
## [115] scales_1.2.1 purrr_1.0.2 crayon_1.5.2
## [118] fANCOVA_0.6-1 rlang_1.1.2 EnrichmentBrowser_2.33.1
## [121] KEGGREST_1.43.0
<>