Skip to contents

Introduction

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 multi-assay framework. For more information on operating with this data format in microbial ecology, see the online tutorial.

Installation

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

Examples

Generate species interaction matrices for the models

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:

A_normal <- powerlawA(n_species = 4, alpha = 3)

Generate interactions from uniform distribution:

A_uniform <- randomA(n_species = 10,
                 diagonal = -0.4,
                     connectance = 0.5,
             interactions = runif(n = 10^2, min = -0.8, max = 0.8))

Hubbell model

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.

params_hubbell <- simulateHubbellRates(x0 = c(0,5,10),
    migration_p = 0.1, metacommunity_probability = NULL, k_events = 1, 
    growth_rates = NULL, norm = FALSE, t_end=1000)

Stochastic logistic model

Stochastic logistic model is used to determine dead and alive counts in community.

tse_logistic <- simulateStochasticLogistic(n_species = 5)

Self-Organised Instability (SOI)

The Self-Organised Instability (SOI) model generates time series for communities and accelerates stochastic simulation.

tse_soi <- simulateSOI(n_species = 4, carrying_capacity = 1000,
                       A = A_normal, k_events=5,
               x0 = NULL,t_end = 150, norm = TRUE)

Consumer-resource model

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.

Generalized Lotka-Volterra (gLV)

The generalized Lotka-Volterra simulation model generates time-series assuming microbial population dynamics and interaction.

tse_glv <- simulateGLV(n_species = 4,
                       A = A_normal,
               t_start = 0, 
                       t_store = 1000,
               stochastic = FALSE,
               norm = FALSE)

Ricker model

Ricker model is a discrete version of the gLV:

tse_ricker <- simulateRicker(n_species=4, A = A_normal, t_end=100, norm = FALSE)

The number of species specified in the interaction matrix must be the same as the species used in the models.

Data containers

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:

Case studies

Source code for replicating the published case studies using the miaSim package (Gao et al. 2023) is available in Github (based on the phyloseq data container).

  • micodymora Python package for microbiome simulation

Session info

## R version 4.3.2 (2023-10-31)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 23.10
## 
## Matrix products: default
## BLAS:   /home/leo/bin/R-4.3.2/lib/libRblas.so 
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.11.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: Europe/Helsinki
## tzcode source: system (glibc)
## 
## attached base packages:
## [1] stats4    stats     graphics  grDevices utils     datasets  methods  
## [8] base     
## 
## other attached packages:
##  [1] miaSim_1.9.1                    TreeSummarizedExperiment_2.10.0
##  [3] Biostrings_2.70.1               XVector_0.42.0                 
##  [5] SingleCellExperiment_1.24.0     SummarizedExperiment_1.32.0    
##  [7] Biobase_2.62.0                  GenomicRanges_1.54.1           
##  [9] GenomeInfoDb_1.38.5             IRanges_2.36.0                 
## [11] S4Vectors_0.40.2                BiocGenerics_0.48.1            
## [13] MatrixGenerics_1.14.0           matrixStats_1.2.0              
## [15] BiocStyle_2.30.0               
## 
## loaded via a namespace (and not attached):
##  [1] xfun_0.41               bslib_0.6.1             poweRlaw_0.70.6        
##  [4] lattice_0.22-5          yulab.utils_0.1.2       vctrs_0.6.5            
##  [7] tools_4.3.2             bitops_1.0-7            generics_0.1.3         
## [10] parallel_4.3.2          tibble_3.2.1            fansi_1.0.6            
## [13] pkgconfig_2.0.3         Matrix_1.6-4            desc_1.4.3             
## [16] lifecycle_1.0.4         GenomeInfoDbData_1.2.11 compiler_4.3.2         
## [19] treeio_1.26.0           textshaping_0.3.7       codetools_0.2-19       
## [22] htmltools_0.5.7         sass_0.4.8              lazyeval_0.2.2         
## [25] RCurl_1.98-1.13         yaml_2.3.8              pracma_2.4.4           
## [28] tidyr_1.3.0             pkgdown_2.0.7           pillar_1.9.0           
## [31] crayon_1.5.2            jquerylib_0.1.4         BiocParallel_1.36.0    
## [34] DelayedArray_0.28.0     cachem_1.0.8            abind_1.4-5            
## [37] nlme_3.1-164            tidyselect_1.2.0        digest_0.6.33          
## [40] dplyr_1.1.4             purrr_1.0.2             bookdown_0.37          
## [43] fastmap_1.1.1           grid_4.3.2              cli_3.6.2              
## [46] SparseArray_1.2.3       magrittr_2.0.3          S4Arrays_1.2.0         
## [49] utf8_1.2.4              ape_5.7-1               rmarkdown_2.25.2       
## [52] deSolve_1.40            ragg_1.2.7              memoise_2.0.1          
## [55] evaluate_0.23           knitr_1.45              rlang_1.1.2            
## [58] Rcpp_1.0.11             tidytree_0.4.6          glue_1.6.2             
## [61] BiocManager_1.30.22     jsonlite_1.8.8          R6_2.5.1               
## [64] systemfonts_1.0.5       fs_1.6.3                zlibbioc_1.48.0