calc_pop: Calculation of population dynamics

View source: R/calc_pop.R

calc_popR Documentation

Calculation of population dynamics

Description

Calculates population growth and death rates

Usage

calc_pop(
  data,
  tax_id = c(),
  sample_id = c(),
  wads = "wad",
  iso_trt = c(),
  time = c(),
  abund = "abund",
  t0_grouping = c(),
  mu = 0.6,
  bootstrap = FALSE,
  iters = 999L,
  grouping_cols = c(),
  min_freq = 3,
  correction = TRUE,
  rm_outliers = TRUE,
  non_grower_prop = 0.1
)

Arguments

data

Data as a long-format data.table where each row represents a taxonomic feature within a single fraction. Typically, this is the output from the calc_wad function.

tax_id

Column name specifying unique identifier for each taxonomic feature.

sample_id

Column name specifying unique identifier for each replicate.

wads

Column name specifying weighted average density values. The default option is "wad" which is created by calc_wad.

iso_trt

Column name specifying a two-level categorical column indicating whether a sample has been amended with a stable isotope (i.e., is "heavy") or if isotopic composition is at natural abundance (i.e., "light"). Any terms may be applied but care should be taken for these values. If supplied as a factor, calc_pop will take the lowest level as the "light" treatment and the higher level as the "heavy" treatment. Alternatively, if supplied as a character, calc_pop will coerce the column to a factor and with the default behavior wherein the first value in alphabetical order will be assumed to be the lowest factor level (i.e. the "light" treatment).

time

Column name specifying the timepoint at which each sample was collected. For population rates, the lowest timepoint will be assumed to be the initial timepoints with which to base changes in abundances on.

abund

Column name specifying abundance measurement for each taxon in each sample. The default option is "abund" which is created by calc_wad.

mu

Assumption of the fraction of oxygen atoms incorporated into new DNA that come from water (instead of from carbon sources)

bootstrap

Whether to generate bootstrapped enrichment values for each taxonomic feature across groups of samples. If TRUE, replicates within specified treatment groupings will be randomly resampled with replacement and resulting WAD values used to generate a distribution of enrichment values for each taxon.

iters

Integer specifying the number of bootstrap iterations to perform.

grouping_cols

Column(s) used to indicate bootstrap resampling groups. Within each group, replicates will be resampled with replacement. Resampling will not occur across groups.

min_freq

Minimum number of replicates a taxonomic feature must occur in to be kept. If treatment grouping columns are specified, frequencies will be assessed at this level. For unlabeled "light" samples, treatment groupings will be ignored when assessing adequate frequency of occurrence.

correction

Whether to apply a correction to fractional enrichment values to ensure a certain proportion are positive.

rm_outlers

Whether or not to remove fractional enrichment values that are 1.5X greater or lesser than the distance between the median and interquartile ranges.

non_grower_group

Fractional value applied if correction = TRUE specifying the proportion of the community in each samples assumed to be non-growers and whose median enrichment values will be assumed to be zero. The adjustment necessary to place this median value at zero will be applied as a correction to all enrichment values in the sample.

Details

calc_pop can only calculate growth rates with samples enriched in 18O. As such, the isotope parameter is not included here, but the user must ensure that carbon and nitrogen isotopic samples are not included. The default parameter for mu is 0.6 which was determined by sensitivity analysis to be the value which produced nearly all positive growth rates in a pilot study.

By default, calc_pop averages the abundances of taxa from the initial time point. If boostrap = TRUE, replicates will be resampled (with replacement) then averaged so that population rates are a product of bootstrapped abundances as well as densities.

Value

calc_pop returns a data.table where each row represents a taxonomic feature within a single replicate. The following columns are produced: growth rate (growth), mortality or turnover rate (mortality).

Bootstrap functionality produces the columns: 2.5%, 50%, and 97.5% reflecting the median bootstrapped rate value and the 95% confidence interval of rate values. In addition, probability that a taxon's enrichment was less than zero is represented in the p_val column which is based on the proportion sub-zero bootstrapped observations. Growth and mortality rates are differentiated by the rate column.

References

Koch, Benjamin, et al. 2018. Estimating taxon-specific population dynamics in diverse microbial communities. Ecosphere 9.

See Also

calc_wad, wad_wide

Examples

 # Load in example data
 data(example_qsip)

 # relativize sequence abundances (should be done after taxonomic filtering)
 example_qsip[, rel_abund := seq_abund / sum(seq_abund), by = sampleID]

 # calculate weighted average densities
 wads <- calc_wad(example_qsip,
                  tax_id = 'asv_id', sample_id = 'sampleID', frac_id = 'fraction',
                  frac_dens = 'Density.g.ml', frac_abund = 'avg_16S_g_soil',
                  rel_abund = 'rel_abund',
                  grouping_cols = c('treatment', 'isotope', 'iso_trt', 'Phylum'))

 # calculate population fluxes
 rates <- calc_pop(wads, tax_id = 'asv_id', sample_id = 'sampleID',
                   iso_trt = 'iso_trt', time = 'timepoint')


bramstone/qSIP documentation built on Nov. 22, 2023, 9:11 p.m.