Keeps only the tips of tree whose accessions are in keep, for example
the genomes sylph detected in a cohort, so the tree can be plotted and its
covariance matrix computed.
Usage
gtdb_tree_prune(
tree,
keep,
accession = "accession",
collapse_singles = TRUE,
quiet = FALSE
)Arguments
- tree
A GTDB tree from
gtdb_tree_read().- keep
The genomes to keep: a character vector of accessions (with or without the
RS_/GB_prefix), or a data frame with them in theaccessioncolumn, such as the output ofsylph2lab::sylph_aggregate()or a table of model estimates.- accession
Column of
keepholding the accessions, whenkeepis a data frame.- collapse_singles
If
TRUE(the default), remove internal nodes left with one child, keeping their clade names as described above.- quiet
If
TRUE, no message about how many tips were kept.
Details
Pruning leaves internal nodes with a single child, which are removed
(collapse_singles = TRUE). GTDB names clades on internal nodes, and a
removed node often carries one, e.g. the only remaining genus of a family.
Before removing such a node, its taxa are moved to its child, so the
pruned tree keeps every GTDB clade name that still has an internal node
("o__Enterobacterales; f__Enterobacteriaceae"). Names on a node whose
only remaining descendant is a single tip (e.g. a genus with one genome
in your data) are kept in the tree's tip.taxa element, a character
vector parallel to tip.label, which gtdb_tip_taxonomy() reads.
Accessions in keep that are not tips of tree are reported with a
warning. Usually they come from a different GTDB release from the tree,
or from the other domain's tree: read both the bac120 and the ar53
trees (see gtdb_tree_read()).
Examples
tree <- gtdb_tree_read(gtdb_example("tree"))
detections <- read.csv(gtdb_example("detections"))
# the genomes detected in the stool swabs only
stool <- detections[detections$isolation_source == "Stool Swab", ]
stool_tree <- gtdb_tree_prune(tree, stool)
#> Kept 457 of 560 tips.
stool_tree
#>
#> Phylogenetic tree with 457 tips and 456 internal nodes.
#>
#> Tip labels:
#> GCF_037023725.1, GCF_001457615.1, GCF_001598695.1, GCF_002925905.1, GCF_000742135.1, GCF_000828055.2, ...
#> Node labels:
#> , 7:d__Bacteria, 1, 0, 100:p__Pseudomonadota, 97:c__Gammaproteobacteria, ...
#>
#> Rooted; includes branch length(s).