Sum observation values for each taxon

For a given table in a taxmap object, sum the values in each column for each taxon. This is useful to convert per-observation counts (e.g. OTU counts) to per-taxon counts.

calc_taxon_abund(obj, dataset, cols = NULL, groups = NULL,
  out_names = NULL)

A taxmap object


The name of a table in obj$data.


The columns in dataset to use. By default, all numeric columns are used. Takes one of the following inputs:


All/No columns will used.

Character vector:

The names of columns to use

Numeric vector:

The indexes of columns to use

Vector of TRUE/FALSE of length equal to the number of columns:

Use the columns corresponding to TRUE values.


Group multiple columns per treatment/group. This should be a vector of group IDs (e.g. character, integer) the same length as cols that defines which samples go in which group. When used, there will be one column in the output for each unique value in groups.


The names of count columns in the output. Must be the same length as cols (or unique(groups), if groups is used).


A tibble

See Also

Other calculations: calc_group_mean, calc_group_median, calc_group_rsd, calc_group_stat, calc_n_samples, calc_obs_props, compare_groups, rarefy_obs, zero_low_counts

  • calc_taxon_abund
# Parse dataset for example
x = parse_tax_data(hmp_otus, class_cols = "lineage", class_sep = ";",
                   class_key = c(tax_rank = "info", tax_name = "taxon_name"),
                   class_regex = "^(.+)__(.+)$")
# Calculate the taxon abundance for each numeric column (i.e. sample)
calc_taxon_abund(x, "tax_data")

# Calculate the taxon abundance for a subset of columns
calc_taxon_abund(x, "tax_data", cols = 4:5)
calc_taxon_abund(x, "tax_data", cols = c("700035949", "700097855"))
calc_taxon_abund(x, "tax_data", cols = startsWith(colnames(x$data$tax_data), "70001"))

# Calculate the taxon abundance for groups of columns (e.g. treatments)
#  Note that we do not need to use the "cols" option for this since all
#  numeric columns are samples in this dataset. If there were numeric columns
#  that were not samples present in hmp_samples, the "cols" would be needed.
calc_taxon_abund(x, "tax_data", groups = hmp_samples$sex)
calc_taxon_abund(x, "tax_data", groups = hmp_samples$body_site)

# The above example using the "cols" option, even though not needed in this case
calc_taxon_abund(x, "tax_data", cols = hmp_samples$sample_id,
                 groups = hmp_samples$sex)
# Rename the output columns
calc_taxon_abund(x, "tax_data", cols = hmp_samples$sample_id[1:10],
                 out_names = letters[1:10])
calc_taxon_abund(x, "tax_data", groups = hmp_samples$sex,
                 out_names = c("Women", "Men"))

# Geting a total for all columns 
calc_taxon_abund(x, "tax_data", cols = hmp_samples$sample_id,
                 groups = rep("total", nrow(hmp_samples)))
# }
# }
Documentation reproduced from package metacoder, version 0.2.1, License: GPL-2 | GPL-3

Community examples

Looks like there are no examples yet.