The R package HiLDA is developed under the Bayesian framework to select the number of mutational signatures based on perplexity and cross-validation. The mutation signature is defined based on the independent model proposed by Shiraishi’s et al.Â
Shiraishi et al. A simple model-based approach to inferring and visualizing cancer mutation signatures, bioRxiv, doi: http://dx.doi.org/10.1101/019901.
Zhi Yang, Paul Marjoram, Kimberly D. Siegmund. Selecting the number of mutational signatures using a perplexity-based measure and cross-validation.
selectKSigs requires several CRAN and Bioconductor R packages to be installed. Dependencies are usually handled automatically, when installing the package using the following commands:
install.packages("BiocManager")
BiocManager::install("selectKSigs")
[NOTE: Ignore the first line if you already have installed the BiocManager.]
You can also download the newest version from the GitHub using devtools:
devtools::install_github("USCbiostats/selectKSigs")
selectKSigs
is a package built on some basic functions from pmsignature
including how to read the input data. Here is an example from pmsignature
on
the input data, mutation features are elements used for categorizing mutations
such as:
sample1 chr1 100 A C
sample1 chr1 200 A T
sample1 chr2 100 G T
sample2 chr1 300 T C
sample3 chr3 400 T C
Here, inputFile is the path for the input file. numBases is the number of flanking bases to consider including the central base (if you want to consider two 5’ and 3’ bases, then set 5). Also, you can add transcription direction information using trDir. numSig sets the number of mutation signatures estimated from the input data. You will see a warning message on some mutations are being removed.
library(HiLDA)
## Loading required package: ggplot2
library(tidyr)
library(ggplot2)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
inputFile <- system.file("extdata/esophageal.mp.txt.gz", package="HiLDA")
G <- hildaReadMPFile(inputFile, numBases=5, trDir=TRUE)
## Warning in hildaReadMPFile(inputFile, numBases = 5, trDir = TRUE): Out of
## 24861 mutations, we could obtaintranscription direction information for 24728
## mutation. Other mutations are removed.
Also, we also provided a small simulated dataset which contains 10 mutational catalogs and used it for demonstrating the key functions in selectKSigs. We start with loading the sample dataset G stored as extdata/sample.rdata.
library(selectKSigs)
load(system.file("extdata/sample.rdata", package = "selectKSigs"))
After we read in the sample data G, we can run the process from selectKSigs. Here, we specify the inputG as G, the number of cross-validation folds, kfold to be 3, the number of replications, nRep, to be 3, and the upper limit of the K values for exploration to be 7.
After we obtained the results, we can plot each measure by the range of K values that were refitted during the calculation. The optimal value of K is achieved at its minimum value highlighted in grey.
results$Kvalue <- seq_len(nrow(results)) + 1
results_df <- gather(results, Method, value, -Kvalue) %>%
group_by(Method) %>%
mutate(xmin = which.min(value) + 1 - 0.1,
xmax = which.min(value) + 1 + 0.1)
ggplot(results_df) +
geom_point(aes(x = Kvalue, y = value, color = Method), size = 2) +
facet_wrap(~ Method, scales = "free") +
geom_rect(mapping = aes(xmin = xmin, xmax = xmax,
ymin = -Inf, ymax = Inf),
fill = 'grey', alpha = 0.05) +
theme_bw()+
xlab("Number of signatures")
Here is the output of sessionInfo()
for reproducibility in the future.
sessionInfo()
## R version 4.1.1 (2021-08-10)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 20.04.3 LTS
##
## Matrix products: default
## BLAS: /home/biocbuild/bbs-3.14-bioc/R/lib/libRblas.so
## LAPACK: /home/biocbuild/bbs-3.14-bioc/R/lib/libRlapack.so
##
## 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
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] selectKSigs_1.6.0 dplyr_1.0.7 tidyr_1.1.4 HiLDA_1.8.0
## [5] ggplot2_3.3.5 BiocStyle_2.22.0
##
## loaded via a namespace (and not attached):
## [1] bitops_1.0-7
## [2] matrixStats_0.61.0
## [3] bit64_4.0.5
## [4] filelock_1.0.2
## [5] progress_1.2.2
## [6] httr_1.4.2
## [7] GenomeInfoDb_1.30.0
## [8] tools_4.1.1
## [9] bslib_0.3.1
## [10] utf8_1.2.2
## [11] R6_2.5.1
## [12] R2WinBUGS_2.1-21
## [13] DBI_1.1.1
## [14] BiocGenerics_0.40.0
## [15] colorspace_2.0-2
## [16] withr_2.4.2
## [17] prettyunits_1.1.1
## [18] tidyselect_1.1.1
## [19] curl_4.3.2
## [20] bit_4.0.4
## [21] compiler_4.1.1
## [22] Biobase_2.54.0
## [23] xml2_1.3.2
## [24] DelayedArray_0.20.0
## [25] labeling_0.4.2
## [26] rtracklayer_1.54.0
## [27] bookdown_0.24
## [28] sass_0.4.0
## [29] scales_1.1.1
## [30] rappdirs_0.3.3
## [31] stringr_1.4.0
## [32] digest_0.6.28
## [33] Rsamtools_2.10.0
## [34] rmarkdown_2.11
## [35] BSgenome.Hsapiens.UCSC.hg19_1.4.3
## [36] XVector_0.34.0
## [37] pkgconfig_2.0.3
## [38] htmltools_0.5.2
## [39] MatrixGenerics_1.6.0
## [40] highr_0.9
## [41] dbplyr_2.1.1
## [42] fastmap_1.1.0
## [43] BSgenome_1.62.0
## [44] rlang_0.4.12
## [45] RSQLite_2.2.8
## [46] farver_2.1.0
## [47] TxDb.Hsapiens.UCSC.hg19.knownGene_3.2.2
## [48] jquerylib_0.1.4
## [49] BiocIO_1.4.0
## [50] generics_0.1.1
## [51] jsonlite_1.7.2
## [52] gtools_3.9.2
## [53] BiocParallel_1.28.0
## [54] RCurl_1.98-1.5
## [55] magrittr_2.0.1
## [56] GenomeInfoDbData_1.2.7
## [57] Matrix_1.3-4
## [58] Rcpp_1.0.7
## [59] munsell_0.5.0
## [60] S4Vectors_0.32.0
## [61] fansi_0.5.0
## [62] abind_1.4-5
## [63] lifecycle_1.0.1
## [64] stringi_1.7.5
## [65] yaml_2.2.1
## [66] SummarizedExperiment_1.24.0
## [67] zlibbioc_1.40.0
## [68] BiocFileCache_2.2.0
## [69] grid_4.1.1
## [70] blob_1.2.2
## [71] parallel_4.1.1
## [72] forcats_0.5.1
## [73] crayon_1.4.1
## [74] lattice_0.20-45
## [75] Biostrings_2.62.0
## [76] cowplot_1.1.1
## [77] GenomicFeatures_1.46.0
## [78] hms_1.1.1
## [79] KEGGREST_1.34.0
## [80] magick_2.7.3
## [81] knitr_1.36
## [82] pillar_1.6.4
## [83] GenomicRanges_1.46.0
## [84] boot_1.3-28
## [85] rjson_0.2.20
## [86] biomaRt_2.50.0
## [87] stats4_4.1.1
## [88] XML_3.99-0.8
## [89] R2jags_0.7-1
## [90] glue_1.4.2
## [91] evaluate_0.14
## [92] BiocManager_1.30.16
## [93] vctrs_0.3.8
## [94] png_0.1-7
## [95] gtable_0.3.0
## [96] purrr_0.3.4
## [97] assertthat_0.2.1
## [98] cachem_1.0.6
## [99] xfun_0.27
## [100] restfulr_0.0.13
## [101] coda_0.19-4
## [102] rjags_4-12
## [103] tibble_3.1.5
## [104] GenomicAlignments_1.30.0
## [105] AnnotationDbi_1.56.0
## [106] memoise_2.0.0
## [107] IRanges_2.28.0
## [108] ellipsis_0.3.2