aggregate_count: aggregate_count

View source: R/aggregate_count.R

aggregate_countR Documentation

aggregate_count

Description

Aggregate read counts based on taxonomic level

Usage

aggregate_count(count_df, tax_df = NULL, aggregate_by = NULL)

Arguments

count_df

dataframe. count table with samples in columns and ASV in rows. feature IDs in row names.

tax_df

dataframe. featureID column should match rownames of count_df. Has columns 'Kingdom','Phylum', 'Class','Order','Family','Genus','Species'. Can also have Taxon column (see details).

aggregate_by

Aggregate counts by taxonomic level. Set to NULL to keep reads at ASV level. default NULL . Must be one of c('Kingdom','Phylum','Class','Order','Family', 'Genus','Species').

Details

If tax_df has sequences column and features are aggregated, the sequence column is set to NA. If tax_df has Taxon column with notation of p__phylum;c__class;o__order... then those are truncated at the aggregation level.

All taxa downstream of aggregation level are set to NA

The aggregated taxonomy table has an additional column, n_collapse, which is the number of ASVs that were aggregated.

Value

returns a list of aggregated count table (count_df) and updated taxonomy table (tax_df)

Examples

data(dss_example)
feature_count <- dss_example$merged_abundance_id %>%
  tibble::column_to_rownames('featureID')

# cleanup sample names
colnames(feature_count) <- paste0('id', colnames(feature_count))
feature_tax <- dss_example$merged_taxonomy

# set row order of count and tax tables to be the same
feature_count <- feature_count[feature_tax$featureID,]
aggregated_list <- aggregate_count(feature_count, feature_tax,
                                  aggregate_by = "Family")

summary(aggregated_list)

OxfordCMS/OCMSutility documentation built on Feb. 27, 2025, 8:19 p.m.