miaSim
implements tools for microbiome data simulation
based on varying ecological modeling assumptions. These can be used to
simulate species abundance matrices, including time series. Detailed
function documentation is available at the function
reference
The miaSim package supports the R/Bioconductor framework based on the TreeSummarizedExperiment data container. For more information on operating with this data format in microbial ecology, see the online tutorial.
The stable Bioconductor release version can be installed as follows.
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
if (!requireNamespace("miaSim", quietly = TRUE))
BiocManager::install("miaSim")
The experimental Bioconductor devel version can be installed as follows.
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
# The following initializes usage of Bioc devel
BiocManager::install(version='devel')
BiocManager::install("miaSim")
Load the library
Some of the models rely on interaction matrices that represents interaction heterogeneity between species. The interaction matrix can be generated with different distributional assumptions.
Generate interactions from normal distribution:
Generate interactions from uniform distribution:
Ricker model is a discrete version of the gLV:
The number of species specified in the interaction matrix must be the same as the species used in the models.
Hubbell Neutral simulation model characterizes diversity and relative abundance of species in ecological communities assuming migration, births and deaths but no interactions. Losses become replaced by migration or birth.
tse_hubbell <- simulateHubbell(n_species = 8,
M = 10,
carrying_capacity = 1000,
k_events = 50,
migration_p = 0.02,
t_end = 100)
One can also simulate parameters for the Hubbell model.
The Self-Organised Instability (SOI) model generates time series for communities and accelerates stochastic simulation.
Stochastic logistic model is used to determine dead and alive counts in community.
The consumer resource model requires the randomE
function. This returns a matrix containing the production rates and
consumption rates of each species. The resulting matrix is used as a
determination of resource consumption efficiency.
# Consumer-resource model as a TreeSE object
tse_crm <- simulateConsumerResource(n_species = 2,
n_resources = 4,
E = randomE(n_species = 2, n_resources = 4))
You could visualize the simulated dynamics using tools from the miaTime package.
The simulated data sets are returned as
TreeSummarizedExperiment
objects. This provides access to a
broad range of tools for microbiome analysis that support this format
(see microbiome.github.io).
More examples on the object manipulation and analysis can be found at OMA Online Manual.
For instance, to plot population density we can use the
miaViz
package:
Source code for replicating the published case studies using the miaSim package (Gao et al. 2023) is available in the phyloseq folder (based on the phyloseq data container). Some of the original case studies have now been replicated also with TreeSummarized, see the TreeSummarizedExperiment folder.
## 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: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
## LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so; LAPACK version 3.12.0
##
## locale:
## [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
## [3] LC_TIME=en_US.UTF-8 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: Etc/UTC
## tzcode source: system (glibc)
##
## attached base packages:
## [1] stats4 stats graphics grDevices utils datasets methods
## [8] base
##
## other attached packages:
## [1] miaViz_1.13.14 ggraph_2.2.1
## [3] ggplot2_3.5.1 mia_1.13.47
## [5] MultiAssayExperiment_1.31.5 miaSim_1.13.0
## [7] TreeSummarizedExperiment_2.13.0 Biostrings_2.75.0
## [9] XVector_0.45.0 SingleCellExperiment_1.27.2
## [11] SummarizedExperiment_1.35.5 Biobase_2.67.0
## [13] GenomicRanges_1.57.2 GenomeInfoDb_1.41.2
## [15] IRanges_2.39.2 S4Vectors_0.43.2
## [17] BiocGenerics_0.53.0 MatrixGenerics_1.17.1
## [19] matrixStats_1.4.1 BiocStyle_2.35.0
##
## loaded via a namespace (and not attached):
## [1] splines_4.4.1 ggplotify_0.1.2
## [3] tibble_3.2.1 polyclip_1.10-7
## [5] rpart_4.1.23 DirichletMultinomial_1.49.0
## [7] deSolve_1.40 lifecycle_1.0.4
## [9] lattice_0.22-6 MASS_7.3-61
## [11] SnowballC_0.7.1 backports_1.5.0
## [13] magrittr_2.0.3 Hmisc_5.2-0
## [15] sass_0.4.9 rmarkdown_2.28
## [17] jquerylib_0.1.4 yaml_2.3.10
## [19] DBI_1.2.3 buildtools_1.0.0
## [21] minqa_1.2.8 abind_1.4-8
## [23] zlibbioc_1.51.2 purrr_1.0.2
## [25] yulab.utils_0.1.7 nnet_7.3-19
## [27] pracma_2.4.4 tweenr_2.0.3
## [29] sandwich_3.1-1 GenomeInfoDbData_1.2.13
## [31] ggrepel_0.9.6 tokenizers_0.3.0
## [33] irlba_2.3.5.1 tidytree_0.4.6
## [35] maketools_1.3.1 vegan_2.6-8
## [37] rbiom_1.0.3 permute_0.9-7
## [39] DelayedMatrixStats_1.29.0 codetools_0.2-20
## [41] DelayedArray_0.33.1 scuttle_1.15.5
## [43] ggforce_0.4.2 tidyselect_1.2.1
## [45] aplot_0.2.3 UCSC.utils_1.1.0
## [47] farver_2.1.2 lme4_1.1-35.5
## [49] ScaledMatrix_1.13.0 viridis_0.6.5
## [51] base64enc_0.1-3 jsonlite_1.8.9
## [53] BiocNeighbors_2.1.0 decontam_1.27.0
## [55] tidygraph_1.3.1 Formula_1.2-5
## [57] scater_1.33.4 tools_4.4.1
## [59] ggnewscale_0.5.0 treeio_1.29.2
## [61] Rcpp_1.0.13 glue_1.8.0
## [63] gridExtra_2.3 SparseArray_1.5.45
## [65] xfun_0.48 mgcv_1.9-1
## [67] dplyr_1.1.4 withr_3.0.2
## [69] BiocManager_1.30.25 fastmap_1.2.0
## [71] boot_1.3-31 bluster_1.17.0
## [73] fansi_1.0.6 digest_0.6.37
## [75] rsvd_1.0.5 R6_2.5.1
## [77] gridGraphics_0.5-1 colorspace_2.1-1
## [79] lpSolve_5.6.21 poweRlaw_0.80.0
## [81] utf8_1.2.4 tidyr_1.3.1
## [83] generics_0.1.3 data.table_1.16.2
## [85] DECIPHER_3.3.0 graphlayouts_1.2.0
## [87] httr_1.4.7 htmlwidgets_1.6.4
## [89] S4Arrays_1.5.11 pkgconfig_2.0.3
## [91] gtable_0.3.6 sys_3.4.3
## [93] janeaustenr_1.0.0 htmltools_0.5.8.1
## [95] scales_1.3.0 ggfun_0.1.7
## [97] knitr_1.48 rstudioapi_0.17.1
## [99] reshape2_1.4.4 checkmate_2.3.2
## [101] nlme_3.1-166 nloptr_2.1.1
## [103] cachem_1.1.0 zoo_1.8-12
## [105] stringr_1.5.1 parallel_4.4.1
## [107] vipor_0.4.7 foreign_0.8-87
## [109] pillar_1.9.0 grid_4.4.1
## [111] vctrs_0.6.5 slam_0.1-54
## [113] BiocSingular_1.23.0 beachmat_2.23.0
## [115] cluster_2.1.6 beeswarm_0.4.0
## [117] htmlTable_2.4.3 evaluate_1.0.1
## [119] mvtnorm_1.3-1 cli_3.6.3
## [121] compiler_4.4.1 rlang_1.1.4
## [123] crayon_1.5.3 tidytext_0.4.2
## [125] labeling_0.4.3 mediation_4.5.0
## [127] plyr_1.8.9 fs_1.6.4
## [129] ggbeeswarm_0.7.2 stringi_1.8.4
## [131] viridisLite_0.4.2 BiocParallel_1.41.0
## [133] munsell_0.5.1 lazyeval_0.2.2
## [135] Matrix_1.7-1 patchwork_1.3.0
## [137] sparseMatrixStats_1.17.2 highr_0.11
## [139] igraph_2.1.1 memoise_2.0.1
## [141] RcppParallel_5.1.9 bslib_0.8.0
## [143] ggtree_3.13.2 ape_5.8