% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/parse_taxonomy.R
\name{parse_gtdb_taxonomy}
\alias{parse_gtdb_taxonomy}
\title{Parse a GTDB-format taxonomy file}
\usage{
parse_gtdb_taxonomy(file, strain_col = "Strain", fill_missing = TRUE)
}
\arguments{
\item{file}{Path to a GTDB taxonomy TSV file.}

\item{strain_col}{Character; name of the column containing MAG / strain
identifiers (used as row names). Default \code{"Strain"}.}

\item{fill_missing}{Logical; fill missing taxonomy levels as described
above? Default \code{TRUE}.}
}
\value{
A data.frame with \code{strain_col} values as row names and columns:
Domain, Phyla, Class, Order, Family, Genus, Species.
}
\description{
Reads a GTDB taxonomy TSV and cleans every rank by stripping rank
prefixes (\code{d__}, \code{p__}, etc.) and removing sub-designation suffixes on
Phyla and Genus (e.g. \code{Bacillota_C} becomes \code{Bacillota}).  Species are
simplified by removing the genus portion before the space and stripping
trailing digits after \code{"sp"}.
}
\details{
When \code{fill_missing = TRUE} (the default):
\itemize{
\item Family \code{"NA"} is replaced with the Order value.
\item Genus \code{"NA"} or \code{""} is replaced with the Family value.
\item Species \code{""} is replaced with \code{"sp"}.
}
}
\examples{
tsv <- tempfile(fileext = ".tsv")
writeLines(c(
  "Strain\tDomain\tPhyla\tClass\tOrder\tFamily\tGenus\tSpecies",
  "MAG1\td__Bacteria\tp__Bacillota_C\tc__Clostridia\to__Lachnospirales\tf__Lachnospiraceae\tg__Butyrivibrio\ts__Butyrivibrio sp1"
), tsv)
tax <- parse_gtdb_taxonomy(tsv)
tax$Phyla

}
