addShortTermChange | R Documentation |
Calculates short term changes in abundance of taxa using temporal abundance data.
addShortTermChange(x, ...)
getShortTermChange(x, ...)
## S4 method for signature 'SummarizedExperiment'
addShortTermChange(x, name = "short_term_change", ...)
## S4 method for signature 'SummarizedExperiment'
getShortTermChange(x, time.col, assay.type = "counts", group = NULL, ...)
x |
A
|
... |
additional arguments.
|
name |
|
time.col |
|
assay.type |
|
group |
|
These functions can be utilized to calculate growth metrics for short term change. In specific, the functions calculate the metrics with the following equations:
time\_diff = time_{t} - time_{t-1}
abundance\_diff = abundance_{t} - abundance_{t-1}
growth\_rate = abundance\_diff - abundance_{t-1}
rate\_of\_change = abundance\_diff - time\_diff
getShortTermChange
returns DataFrame
object containing
the short term change in abundance over time for a microbe.
addShortTermChange
, on the other hand, returns a
SummarizedExperiment
object with these results in its metadata
.
Ji, B.W., et al. (2020) Macroecological dynamics of gut microbiota. Nat Microbiol 5, 768–775 . doi: https://doi.org/10.1038/s41564-020-0685-1
getStepwiseDivergence()
library(miaTime)
# Load time series data
data(minimalgut)
tse <- minimalgut
# Get relative abundances
tse <- transformAssay(tse, method = "relabundance")
# Calculate short term changes
df <- getShortTermChange(
tse, assay.type = "relabundance", time.col = "Time.hr",
group = "StudyIdentifier")
# Calculate the logarithm of the ratio described in Ji, B.W., et al. (2020)
tse <- transformAssay(
tse, assay.type = "relabundance", method = "log10", pseudocount = TRUE)
df <- getShortTermChange(
tse, assay.type = "log10", time.col = "Time.hr", group = "StudyIdentifier")
# Select certain bacteria that have highest growth rate
select <- df[["growth_rate"]] |> abs() |> order(decreasing = FALSE)
select <- df[select, "FeatureID"] |> unique() |> head(3)
df <- df[ which(df[["FeatureID"]] %in% select), ]
# Plot results
library(ggplot2)
p <- ggplot(df, aes(x = Time.hr, y = growth_rate, colour = FeatureID)) +
geom_smooth(level = 0.5) +
facet_grid(. ~ StudyIdentifier, scales = "free") +
scale_y_log10()
p
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.