% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/KeepTaxonomicLevel.R
\name{KeepTaxonomicLevel}
\alias{KeepTaxonomicLevel}
\title{Summarize abundance data at a given taxonomic level}
\usage{
KeepTaxonomicLevel(CrcBiomeScreenObject, level = "Genus")
}
\arguments{
\item{CrcBiomeScreenObject}{A A \code{CrcBiomeScreen} object. object.}

\item{level}{Taxonomic level to summarize to. One of
"Kingdom", "Phylum", "Class", "Order", "Family", "Genus", "Species".}
}
\value{
The CrcBiomeScreenObject with a new data frame aggregated at the specified level.

The same A \code{CrcBiomeScreen} object. object, updated with a slot
\code{@TaxaLevelData} a new data frame in
\code{@GenusLevelData} (or the corresponding level).
}
\description{
Aggregate absolute abundance data in a A \code{CrcBiomeScreen} object. object
to a specified taxonomic level (e.g. "Genus" or "Family").
}
\details{
Keep a specific taxonomic level

This function aggregates abundance data to a specified taxonomic level.
}
\examples{
# Minimal fully runnable example for KeepTaxonomicLevel

# Toy taxa in a simplified MetaPhlAn-like hierarchical format
toy_taxa <- data.frame(
  Taxa = c(
    "D_0__Bacteria|D_1__Firmicutes|D_2__Clostridia|D_3__OrderX|D_4__FamilyX|D_5__GenusA",
    "D_0__Bacteria|D_1__Firmicutes|D_2__Clostridia|D_3__OrderY|D_4__FamilyY|D_5__GenusB"
  ),
  stringsAsFactors = FALSE
)

# Toy abundance matrix (2 taxa, 2 samples)
toy_abs <- data.frame(
  S1 = c(10, 5),
  S2 = c(20, 15)
)
rownames(toy_abs) <- toy_taxa$Taxa

# Dummy sample metadata
toy_sample <- data.frame(
  sample_id = c("S1", "S2")
)

# Construct minimal CrcBiomeScreen object
toy_obj <- new(
  "CrcBiomeScreen",
  AbsoluteAbundance   = toy_abs,
  RelativeAbundance   = data.frame(),
  TaxaData            = toy_taxa,
  SampleData          = toy_sample,
  TaxaLevelData       = NULL,
  NormalizedData      = NULL,
  OriginalNormalizedData = NULL,
  ValidationData      = NULL,
  ModelData           = NULL,
  ModelResult         = NULL,
  EvaluateResult      = list(),
  PredictResult       = NULL
)

# Apply taxonomy splitting + keep genus level
toy_obj <- SplitTaxas(toy_obj)
genus_obj <- KeepTaxonomicLevel(toy_obj, level = "Genus")

# Inspect genus-level abundance
getTaxaLevelData(genus_obj)$GenusLevelData

}
