RNAG3
RNAseq PCA Graphs
This page can be used as a template of how to use the available hermes
functions for principal components analysis and plots of RNAseq data sets.
The principal components analysis function uses HermesData
as input. See RNAG1 for details.
Once we have filtered out low quality genes and samples, and normalized the counts, we can perform principal components analysis of the gene counts across all samples using the calc_pca()
function. The calc_pca()
function uses by default the raw counts, unless otherwise specified in the assay_name
argument of the function.
We can then also plot these principal component results using the corresponding autoplot()
method.
There are many different options for plotting. See ?autoplot.pca_common
for the full details. Here some examples.
We can specify which principal components should be plotted against each other.
We can also include sample labels on the plot.
Or we can exclude the variance percentages from the axis labels.
As a last example, we can also color the points by a sample variable.
We can also calculate the correlation (in R2 values) between sample variables in HermesData
and the principal components of these samples using correlate()
:
We can then also plot these R2 values between sample variables and principal components again using the autoplot()
method. Sample variables that have high correlation with major principal components can point to potential batch effects.
We can also avoid reordering the principal components column.
We can also update the color definitions of R2 values in the heatmap.
Code
See ?pca_cor_samplevar
for the detailed options.
We start by importing a MultiAssayExperiment
; here we use the example multi_assay_experiment
available in hermes
. It is wrapped as a teal::dataset
. We can then use the provided teal module tm_g_pca
to include a PCA module in our teal app.
Code
[INFO] 2024-09-14 17:36:01.7888 pid:7282 token:[] teal.modules.hermes Initializing tm_g_pca
[INFO] 2024-09-14 17:36:03.2594 pid:7282 token:[029aa418] teal Initializing reporter_previewer_module
Warning: 'experiments' dropped; see 'drops()'
R version 4.4.1 (2024-06-14)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 22.04.4 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so; LAPACK version 3.10.0
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[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: Etc/UTC
tzcode source: system (glibc)
attached base packages:
[1] stats4 stats graphics grDevices utils datasets methods
[8] base
other attached packages:
[1] teal.modules.hermes_0.1.6 teal_0.15.2
[3] teal.slice_0.5.1 teal.data_0.6.0
[5] teal.code_0.5.0 shiny_1.9.1
[7] hermes_1.8.1 SummarizedExperiment_1.34.0
[9] Biobase_2.64.0 GenomicRanges_1.56.1
[11] GenomeInfoDb_1.40.1 IRanges_2.38.1
[13] S4Vectors_0.42.1 BiocGenerics_0.50.0
[15] MatrixGenerics_1.16.0 matrixStats_1.4.1
[17] ggfortify_0.4.17 ggplot2_3.5.1
loaded via a namespace (and not attached):
[1] RColorBrewer_1.1-3 jsonlite_1.8.8
[3] shape_1.4.6.1 MultiAssayExperiment_1.30.3
[5] magrittr_2.0.3 magick_2.8.4
[7] farver_2.1.2 rmarkdown_2.28
[9] ragg_1.3.3 GlobalOptions_0.1.2
[11] zlibbioc_1.50.0 vctrs_0.6.5
[13] memoise_2.0.1 webshot_0.5.5
[15] BiocBaseUtils_1.7.3 htmltools_0.5.8.1
[17] S4Arrays_1.4.1 forcats_1.0.0
[19] progress_1.2.3 curl_5.2.2
[21] SparseArray_1.4.8 sass_0.4.9
[23] bslib_0.8.0 fontawesome_0.5.2
[25] htmlwidgets_1.6.4 testthat_3.2.1.1
[27] httr2_1.0.4 cachem_1.1.0
[29] teal.widgets_0.4.2 mime_0.12
[31] lifecycle_1.0.4 iterators_1.0.14
[33] pkgconfig_2.0.3 webshot2_0.1.1
[35] Matrix_1.7-0 R6_2.5.1
[37] fastmap_1.2.0 GenomeInfoDbData_1.2.12
[39] rbibutils_2.2.16 clue_0.3-65
[41] digest_0.6.37 colorspace_2.1-1
[43] shinycssloaders_1.1.0 ps_1.8.0
[45] AnnotationDbi_1.66.0 DESeq2_1.44.0
[47] textshaping_0.4.0 crosstalk_1.2.1
[49] RSQLite_2.3.7 filelock_1.0.3
[51] labeling_0.4.3 fansi_1.0.6
[53] httr_1.4.7 abind_1.4-8
[55] compiler_4.4.1 bit64_4.0.5
[57] withr_3.0.1 doParallel_1.0.17
[59] backports_1.5.0 BiocParallel_1.38.0
[61] DBI_1.2.3 logger_0.3.0
[63] biomaRt_2.60.1 rappdirs_0.3.3
[65] DelayedArray_0.30.1 rjson_0.2.22
[67] chromote_0.3.1 tools_4.4.1
[69] httpuv_1.6.15 glue_1.7.0
[71] callr_3.7.6 promises_1.3.0
[73] grid_4.4.1 checkmate_2.3.2
[75] cluster_2.1.6 generics_0.1.3
[77] gtable_0.3.5 websocket_1.4.2
[79] tidyr_1.3.1 hms_1.1.3
[81] xml2_1.3.6 utf8_1.2.4
[83] XVector_0.44.0 ggrepel_0.9.6
[85] foreach_1.5.2 pillar_1.9.0
[87] stringr_1.5.1 limma_3.60.4
[89] later_1.3.2 circlize_0.4.16
[91] dplyr_1.1.4 BiocFileCache_2.12.0
[93] lattice_0.22-6 bit_4.0.5
[95] tidyselect_1.2.1 ComplexHeatmap_2.20.0
[97] locfit_1.5-9.10 Biostrings_2.72.1
[99] knitr_1.48 gridExtra_2.3
[101] teal.logger_0.2.0 edgeR_4.2.1
[103] xfun_0.47 statmod_1.5.0
[105] brio_1.1.5 DT_0.33
[107] stringi_1.8.4 UCSC.utils_1.0.0
[109] yaml_2.3.10 shinyWidgets_0.8.6
[111] evaluate_0.24.0 codetools_0.2-20
[113] tibble_3.2.1 cli_3.6.3
[115] systemfonts_1.1.0 xtable_1.8-4
[117] Rdpack_2.6.1 processx_3.8.4
[119] jquerylib_0.1.4 munsell_0.5.1
[121] teal.reporter_0.3.1 Rcpp_1.0.13
[123] dbplyr_2.5.0 png_0.1-8
[125] parallel_4.4.1 assertthat_0.2.1
[127] blob_1.2.4 prettyunits_1.2.0
[129] scales_1.3.0 purrr_1.0.2
[131] crayon_1.5.3 GetoptLong_1.0.5
[133] rlang_1.1.4 formatR_1.14
[135] KEGGREST_1.44.1 shinyjs_2.1.0