wad_wide: Wide-format for WAD values

View source: R/wad_wide.R

wad_wideR Documentation

Wide-format for WAD values

Description

Transforms weighted average density values into wide-format

Usage

wad_wide(
  data,
  tax_id = c(),
  sample_id = c(),
  wads = "wad",
  iso_trt = c(),
  isotope = c(),
  average_light = TRUE
)

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.

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_excess will take the lowest level as the "light" treatment and the higher level as the "heavy" treatment. Alternatively, if supplied as a character, calc_excess 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).

average_light

Whether to average the "light" WAD values.

Value

wad_wide returns a wide-transformed data.table where each row represents a taxonomic feature within a single replicate. If averaging unamended ("light") values is not performed, each taxon will have one numeric value and one NA value based on whether it was present in an unamended "light" sample or an amended "heavy" sample.

See Also

calc_wad, calc_excess

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'))

 # transform to wide format
 ww <- wad_wide(wads, tax_id = 'asv_id', sample_id = 'sampleID',
                iso_trt = 'iso_trt', isotope = 'isotope')


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