miaTime
is a package in the mia family,
providing tools for time series manipulation using the TreeSummarizedExperiment
data container.
miaTime
is hosted on Bioconductor, and can be installed
using via BiocManager
.
BiocManager::install("miaTime")
Once installed, miaTime
is made available in the usual
way.
library(miaTime)
#> Loading required package: mia
#> Loading required package: MultiAssayExperiment
#> Loading required package: SummarizedExperiment
#> Loading required package: MatrixGenerics
#> Loading required package: matrixStats
#>
#> Attaching package: 'MatrixGenerics'
#> The following objects are masked from 'package:matrixStats':
#>
#> colAlls, colAnyNAs, colAnys, colAvgsPerRowSet, colCollapse,
#> colCounts, colCummaxs, colCummins, colCumprods, colCumsums,
#> colDiffs, colIQRDiffs, colIQRs, colLogSumExps, colMadDiffs,
#> colMads, colMaxs, colMeans2, colMedians, colMins, colOrderStats,
#> colProds, colQuantiles, colRanges, colRanks, colSdDiffs, colSds,
#> colSums2, colTabulates, colVarDiffs, colVars, colWeightedMads,
#> colWeightedMeans, colWeightedMedians, colWeightedSds,
#> colWeightedVars, rowAlls, rowAnyNAs, rowAnys, rowAvgsPerColSet,
#> rowCollapse, rowCounts, rowCummaxs, rowCummins, rowCumprods,
#> rowCumsums, rowDiffs, rowIQRDiffs, rowIQRs, rowLogSumExps,
#> rowMadDiffs, rowMads, rowMaxs, rowMeans2, rowMedians, rowMins,
#> rowOrderStats, rowProds, rowQuantiles, rowRanges, rowRanks,
#> rowSdDiffs, rowSds, rowSums2, rowTabulates, rowVarDiffs, rowVars,
#> rowWeightedMads, rowWeightedMeans, rowWeightedMedians,
#> rowWeightedSds, rowWeightedVars
#> Loading required package: GenomicRanges
#> Loading required package: stats4
#> Loading required package: BiocGenerics
#> Loading required package: generics
#>
#> Attaching package: 'generics'
#> The following objects are masked from 'package:base':
#>
#> as.difftime, as.factor, as.ordered, intersect, is.element, setdiff,
#> setequal, union
#>
#> Attaching package: 'BiocGenerics'
#> The following objects are masked from 'package:stats':
#>
#> IQR, mad, sd, var, xtabs
#> The following objects are masked from 'package:base':
#>
#> anyDuplicated, aperm, append, as.data.frame, basename, cbind,
#> colnames, dirname, do.call, duplicated, eval, evalq, Filter, Find,
#> get, grep, grepl, is.unsorted, lapply, Map, mapply, match, mget,
#> order, paste, pmax, pmax.int, pmin, pmin.int, Position, rank,
#> rbind, Reduce, rownames, sapply, saveRDS, table, tapply, unique,
#> unsplit, which.max, which.min
#> Loading required package: S4Vectors
#>
#> Attaching package: 'S4Vectors'
#> The following object is masked from 'package:utils':
#>
#> findMatches
#> The following objects are masked from 'package:base':
#>
#> expand.grid, I, unname
#> Loading required package: IRanges
#> Loading required package: GenomeInfoDb
#> Loading required package: Biobase
#> Welcome to Bioconductor
#>
#> Vignettes contain introductory material; view with
#> 'browseVignettes()'. To cite Bioconductor, see
#> 'citation("Biobase")', and for packages 'citation("pkgname")'.
#>
#> Attaching package: 'Biobase'
#> The following object is masked from 'package:MatrixGenerics':
#>
#> rowMedians
#> The following objects are masked from 'package:matrixStats':
#>
#> anyMissing, rowMedians
#> Loading required package: SingleCellExperiment
#> Loading required package: TreeSummarizedExperiment
#> Loading required package: Biostrings
#> Loading required package: XVector
#>
#> Attaching package: 'Biostrings'
#> The following object is masked from 'package:base':
#>
#> strsplit
#> This is mia version 1.15.6
#> - Online documentation and vignettes: https://microbiome.github.io/mia/
#> - Online book 'Orchestrating Microbiome Analysis (OMA)': https://microbiome.github.io/OMA/docs/devel/
miaTime
offers functions to calculate divergences. These
can be calculated based on samples and their corresponding base time
point, e.g., first sample of time series. Moreover, divergences can be
calculated in rolling basis meaning that a sample is compared to
previous ith sample.
Divergences can be calculated with get*Divergence()
functions. In the example below, for each subject, we calculate the
divergence of their samples by comparing them to the first time
point.
data(hitchip1006)
tse <- hitchip1006
res <- getBaselineDivergence(
tse, time.col = "time", group = "sample",
name = c("baseline", "time_diff", "ref_samples"))
res |> head()
#> DataFrame with 6 rows and 3 columns
#> baseline time_diff ref_samples
#> <numeric> <numeric> <character>
#> Sample-1 0 0 Sample-1
#> Sample-2 0 0 Sample-2
#> Sample-3 0 0 Sample-3
#> Sample-4 0 0 Sample-4
#> Sample-5 0 0 Sample-5
#> Sample-6 0 0 Sample-6
A more convenient and preferred approach is to store the values
directly in colData
using the get*Divergence()
functions. In the example below, we calculate stepwise divergences with
a lag of 1, meaning that for each sample, the divergence is calculated
by comparing it to the previous time point for the same subject.
tse <- addStepwiseDivergence(tse, time.col = "time")
colData(tse)
#> DataFrame with 1151 rows and 13 columns
#> age sex nationality DNA_extraction_method project
#> <integer> <factor> <factor> <factor> <factor>
#> Sample-1 28 male US NA 1
#> Sample-2 24 female US NA 1
#> Sample-3 52 male US NA 1
#> Sample-4 22 female US NA 1
#> Sample-5 25 female US NA 1
#> ... ... ... ... ... ...
#> Sample-1168 50 female Scandinavia r 40
#> Sample-1169 31 female Scandinavia r 40
#> Sample-1170 31 female Scandinavia r 40
#> Sample-1171 52 male Scandinavia r 40
#> Sample-1172 52 male Scandinavia r 40
#> diversity bmi_group subject time sample divergence
#> <numeric> <factor> <factor> <numeric> <character> <numeric>
#> Sample-1 5.76 severeobese 1 0 Sample-1 NA
#> Sample-2 6.06 obese 2 0 Sample-2 0.411871
#> Sample-3 5.50 lean 3 0 Sample-3 0.627062
#> Sample-4 5.87 underweight 4 0 Sample-4 0.728678
#> Sample-5 5.89 lean 5 0 Sample-5 0.348764
#> ... ... ... ... ... ... ...
#> Sample-1168 5.87 severeobese 244 8.1 Sample-1168 0.492691
#> Sample-1169 5.87 overweight 245 2.3 Sample-1169 0.284404
#> Sample-1170 5.92 overweight 245 8.2 Sample-1170 0.531075
#> Sample-1171 6.04 overweight 246 2.1 Sample-1171 0.306739
#> Sample-1172 5.74 overweight 246 7.9 Sample-1172 0.485427
#> time_diff ref_samples
#> <numeric> <character>
#> Sample-1 NA NA
#> Sample-2 0 Sample-1
#> Sample-3 0 Sample-2
#> Sample-4 0 Sample-3
#> Sample-5 0 Sample-4
#> ... ... ...
#> Sample-1168 0.0 Sample-1127
#> Sample-1169 0.0 Sample-1167
#> Sample-1170 0.0 Sample-1166
#> Sample-1171 0.7 Sample-1086
#> Sample-1172 0.1 Sample-1162
We can visualize time series data with miaViz. Below, we visualize 2 most abundant taxa.
library(miaViz)
#> Loading required package: ggplot2
#> Loading required package: ggraph
#>
#> Attaching package: 'miaViz'
#> The following object is masked from 'package:mia':
#>
#> plotNMDS
p <- plotSeries(tse, x = "time", y = getTop(tse, 5))
p
See articles for more detailed example workflows.
sessionInfo()
#> R Under development (unstable) (2024-12-10 r87437)
#> 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=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: UTC
#> tzcode source: system (glibc)
#>
#> attached base packages:
#> [1] stats4 stats graphics grDevices utils datasets methods
#> [8] base
#>
#> other attached packages:
#> [1] miaViz_1.15.2 ggraph_2.2.1
#> [3] ggplot2_3.5.1 miaTime_0.99.0
#> [5] mia_1.15.6 TreeSummarizedExperiment_2.15.0
#> [7] Biostrings_2.75.2 XVector_0.47.0
#> [9] SingleCellExperiment_1.29.1 MultiAssayExperiment_1.33.1
#> [11] SummarizedExperiment_1.37.0 Biobase_2.67.0
#> [13] GenomicRanges_1.59.1 GenomeInfoDb_1.43.2
#> [15] IRanges_2.41.2 S4Vectors_0.45.2
#> [17] BiocGenerics_0.53.3 generics_0.1.3
#> [19] MatrixGenerics_1.19.0 matrixStats_1.4.1
#> [21] knitr_1.49 BiocStyle_2.35.0
#>
#> loaded via a namespace (and not attached):
#> [1] splines_4.5.0 ggplotify_0.1.2
#> [3] tibble_3.2.1 polyclip_1.10-7
#> [5] rpart_4.1.23 DirichletMultinomial_1.49.0
#> [7] lifecycle_1.0.4 lattice_0.22-6
#> [9] MASS_7.3-61 SnowballC_0.7.1
#> [11] backports_1.5.0 magrittr_2.0.3
#> [13] Hmisc_5.2-1 sass_0.4.9
#> [15] rmarkdown_2.29 jquerylib_0.1.4
#> [17] yaml_2.3.10 DBI_1.2.3
#> [19] minqa_1.2.8 abind_1.4-8
#> [21] zlibbioc_1.53.0 purrr_1.0.2
#> [23] yulab.utils_0.1.8 nnet_7.3-19
#> [25] tweenr_2.0.3 sandwich_3.1-1
#> [27] GenomeInfoDbData_1.2.13 ggrepel_0.9.6
#> [29] tokenizers_0.3.0 irlba_2.3.5.1
#> [31] tidytree_0.4.6 vegan_2.6-8
#> [33] rbiom_1.0.3 pkgdown_2.1.1
#> [35] permute_0.9-7 DelayedMatrixStats_1.29.0
#> [37] codetools_0.2-20 DelayedArray_0.33.3
#> [39] scuttle_1.17.0 ggforce_0.4.2
#> [41] tidyselect_1.2.1 aplot_0.2.3
#> [43] UCSC.utils_1.3.0 farver_2.1.2
#> [45] lme4_1.1-35.5 ScaledMatrix_1.15.0
#> [47] viridis_0.6.5 base64enc_0.1-3
#> [49] jsonlite_1.8.9 BiocNeighbors_2.1.2
#> [51] decontam_1.27.0 tidygraph_1.3.1
#> [53] Formula_1.2-5 scater_1.35.0
#> [55] systemfonts_1.1.0 tools_4.5.0
#> [57] ggnewscale_0.5.0 treeio_1.31.0
#> [59] ragg_1.3.3 Rcpp_1.0.13-1
#> [61] glue_1.8.0 gridExtra_2.3
#> [63] SparseArray_1.7.2 xfun_0.49
#> [65] mgcv_1.9-1 dplyr_1.1.4
#> [67] withr_3.0.2 BiocManager_1.30.25
#> [69] fastmap_1.2.0 boot_1.3-31
#> [71] bluster_1.17.0 fansi_1.0.6
#> [73] digest_0.6.37 rsvd_1.0.5
#> [75] R6_2.5.1 gridGraphics_0.5-1
#> [77] textshaping_0.4.1 colorspace_2.1-1
#> [79] lpSolve_5.6.23 utf8_1.2.4
#> [81] tidyr_1.3.1 data.table_1.16.4
#> [83] DECIPHER_3.3.1 graphlayouts_1.2.1
#> [85] httr_1.4.7 htmlwidgets_1.6.4
#> [87] S4Arrays_1.7.1 pkgconfig_2.0.3
#> [89] gtable_0.3.6 janeaustenr_1.0.0
#> [91] htmltools_0.5.8.1 bookdown_0.41
#> [93] scales_1.3.0 ggfun_0.1.8
#> [95] rstudioapi_0.17.1 reshape2_1.4.4
#> [97] checkmate_2.3.2 nlme_3.1-166
#> [99] nloptr_2.1.1 cachem_1.1.0
#> [101] zoo_1.8-12 stringr_1.5.1
#> [103] parallel_4.5.0 vipor_0.4.7
#> [105] foreign_0.8-87 desc_1.4.3
#> [107] pillar_1.9.0 grid_4.5.0
#> [109] vctrs_0.6.5 slam_0.1-55
#> [111] BiocSingular_1.23.0 beachmat_2.23.4
#> [113] cluster_2.1.8 beeswarm_0.4.0
#> [115] htmlTable_2.4.3 evaluate_1.0.1
#> [117] mvtnorm_1.3-2 cli_3.6.3
#> [119] compiler_4.5.0 rlang_1.1.4
#> [121] crayon_1.5.3 tidytext_0.4.2
#> [123] labeling_0.4.3 mediation_4.5.0
#> [125] plyr_1.8.9 fs_1.6.5
#> [127] ggbeeswarm_0.7.2 stringi_1.8.4
#> [129] viridisLite_0.4.2 BiocParallel_1.41.0
#> [131] munsell_0.5.1 lazyeval_0.2.2
#> [133] Matrix_1.7-1 patchwork_1.3.0
#> [135] sparseMatrixStats_1.19.0 igraph_2.1.2
#> [137] memoise_2.0.1 RcppParallel_5.1.9
#> [139] bslib_0.8.0 ggtree_3.15.0
#> [141] ape_5.8-1