Title: | Yet Another TAxonomy Handler |
---|---|
Description: | Provides functions to manage taxonomy when lineages are described with strings and ranks separated with special patterns like "|*__" or ";*__". |
Authors: | Antoine Bichat [aut, cre] |
Maintainer: | Antoine Bichat <[email protected]> |
License: | GPL-3 |
Version: | 1.0.0 |
Built: | 2024-11-09 03:52:33 UTC |
Source: | https://github.com/abichat/yatah |
A dataset containing the abundances of 1585 lineages among 199 patients.
abundances
abundances
A data.frame with 1585 rows and 200 variables:
lineage (string)
abundance of each lineage in the sample XXX (double)
Zeller et al., 2014 (doi:10.15252/msb.20145645), Pasolli et al., 2017 (doi:10.1038/nmeth.4468).
dim(abundances) abundances[1:5, 1:7]
dim(abundances) abundances[1:5, 1:7]
yatah
Ranks handled by yatah
all_ranks
all_ranks
An object of class character
of length 8.
all_ranks
all_ranks
Extract all clades present in the lineages
get_all_clades(lineage, simplify = TRUE)
get_all_clades(lineage, simplify = TRUE)
lineage |
string. Vector of lineages. |
simplify |
logical. Should the output be a vector or a dataframe? |
If a clade correspond to different ranks (e.g. Actinobacteria
is both a phylum and a clade), it will be displayed only one time when
simplify
is set to TRUE
. It is also the case for different
clades with same name and same rank when simplify
is set to
FALSE
.
The clades present in the lineage. Vector of ordered strings or data.frame.
lineage1 <- "k__Bacteria|p__Verrucomicrobia|c__Verrucomicrobiae" lineage2 <- "k__Bacteria|p__Firmicutes|c__Clostridia" lineage3 <- "k__Bacteria|p__Actinobacteria|c__Actinobacteria" get_all_clades(c(lineage1, lineage2, lineage3)) get_all_clades(c(lineage1, lineage2, lineage3), simplify = FALSE)
lineage1 <- "k__Bacteria|p__Verrucomicrobia|c__Verrucomicrobiae" lineage2 <- "k__Bacteria|p__Firmicutes|c__Clostridia" lineage3 <- "k__Bacteria|p__Actinobacteria|c__Actinobacteria" get_all_clades(c(lineage1, lineage2, lineage3)) get_all_clades(c(lineage1, lineage2, lineage3), simplify = FALSE)
Extract the clade of a desired rank in a lineage
get_clade(lineage, rank = yatah::all_ranks, same = TRUE)
get_clade(lineage, rank = yatah::all_ranks, same = TRUE)
lineage |
string. Vector of lineages. |
rank |
The desired rank of the clade. |
same |
logical. Does the lineage have the same depth? Default to |
A string.
lineage1 <- "k__Bacteria|p__Verrucomicrobia|c__Verrucomicrobiae" lineage2 <- "k__Bacteria|p__Firmicutes|c__Clostridia" get_clade(c(lineage1, lineage2), "phylum")
lineage1 <- "k__Bacteria|p__Verrucomicrobia|c__Verrucomicrobiae" lineage2 <- "k__Bacteria|p__Firmicutes|c__Clostridia" get_clade(c(lineage1, lineage2), "phylum")
Extract the last clade of a lineage
get_last_clade(lineage, same = TRUE)
get_last_clade(lineage, same = TRUE)
lineage |
string. Vector of lineages. |
same |
logical. Does the lineage have the same depth? Default to |
A string. The last clades of the given lineages.
lineage1 <- "k__Bacteria|p__Verrucomicrobia|c__Verrucomicrobiae" lineage2 <- "k__Bacteria|p__Firmicutes|c__Clostridia" get_last_clade(c(lineage1, lineage2))
lineage1 <- "k__Bacteria|p__Verrucomicrobia|c__Verrucomicrobiae" lineage2 <- "k__Bacteria|p__Firmicutes|c__Clostridia" get_last_clade(c(lineage1, lineage2))
Extract the last rank of a lineage
get_last_rank(lineage, same = TRUE)
get_last_rank(lineage, same = TRUE)
lineage |
string. Vector of lineages. |
same |
logical. Does the lineage have the same depth? Default to |
A string. The last rank of the given lineages.
lineage1 <- "k__Bacteria|p__Verrucomicrobia|c__Verrucomicrobiae" lineage2 <- "k__Bacteria|p__Firmicutes|c__Clostridia" get_last_rank(c(lineage1, lineage2))
lineage1 <- "k__Bacteria|p__Verrucomicrobia|c__Verrucomicrobiae" lineage2 <- "k__Bacteria|p__Firmicutes|c__Clostridia" get_last_rank(c(lineage1, lineage2))
Test if a lineage belongs to a clade
is_clade(lineage, clade, rank = c(".", yatah::all_ranks))
is_clade(lineage, clade, rank = c(".", yatah::all_ranks))
lineage |
string. Vector of lineages. |
clade |
string. |
rank |
string. One of |
If rank
is set to .
, clade is looked for
among all ranks.
logical.
lineage1 <- "k__Bacteria|p__Verrucomicrobia|c__Verrucomicrobiae" lineage2 <- "k__Bacteria|p__Firmicutes|c__Clostridia" is_clade(c(lineage1, lineage2), clade = "Verrucomicrobia", rank = "phylum") is_clade(c(lineage1, lineage2), clade = "Clostridia")
lineage1 <- "k__Bacteria|p__Verrucomicrobia|c__Verrucomicrobiae" lineage2 <- "k__Bacteria|p__Firmicutes|c__Clostridia" is_clade(c(lineage1, lineage2), clade = "Verrucomicrobia", rank = "phylum") is_clade(c(lineage1, lineage2), clade = "Clostridia")
Test if a string is a lineage
is_lineage(string)
is_lineage(string)
string |
string to be tested as lineage. |
Alphanumeric character, hyphen, dots, square brackets and non-consecutive underscores are allowed in clades names.
A logical.
is_lineage("k__Bacteria|p__Firmicutes|c__Clostridia|o__Clostridiales")
is_lineage("k__Bacteria|p__Firmicutes|c__Clostridia|o__Clostridiales")
Test if a lineage goes down to a specified rank
is_rank(lineage, rank = yatah::all_ranks) is_at_least_rank(lineage, rank = yatah::all_ranks)
is_rank(lineage, rank = yatah::all_ranks) is_at_least_rank(lineage, rank = yatah::all_ranks)
lineage |
string. Vector of lineages. |
rank |
string. One of |
logical.
lineage1 <- "k__Bacteria|p__Verrucomicrobia|c__Verrucomicrobiae" lineage2 <- "k__Bacteria|p__Firmicutes|c__Clostridia" is_rank(c(lineage1, lineage2), "class") is_rank(c(lineage1, lineage2), "order") is_at_least_rank(c(lineage1, lineage2), "phylum") is_at_least_rank(c(lineage1, lineage2), "order")
lineage1 <- "k__Bacteria|p__Verrucomicrobia|c__Verrucomicrobiae" lineage2 <- "k__Bacteria|p__Firmicutes|c__Clostridia" is_rank(c(lineage1, lineage2), "class") is_rank(c(lineage1, lineage2), "order") is_at_least_rank(c(lineage1, lineage2), "phylum") is_at_least_rank(c(lineage1, lineage2), "order")
Compute taxonomic table from lineages.
taxtable(lineage)
taxtable(lineage)
lineage |
string. Vector of lineages. |
Duplicated lineages are removed.
A data.frame with columns corresponding to different ranks.
lineage1 <- "k__Bacteria|p__Verrucomicrobia|c__Verrucomicrobiae" lineage2 <- "k__Bacteria|p__Firmicutes|c__Clostridia" lineage3 <- "k__Bacteria|p__Firmicutes|c__Bacilli" taxtable(c(lineage1, lineage2, lineage3))
lineage1 <- "k__Bacteria|p__Verrucomicrobia|c__Verrucomicrobiae" lineage2 <- "k__Bacteria|p__Firmicutes|c__Clostridia" lineage3 <- "k__Bacteria|p__Firmicutes|c__Bacilli" taxtable(c(lineage1, lineage2, lineage3))
Compute taxonomic tree from taxonomic table.
taxtree(table, collapse = TRUE, lineage_length = 1, root = "")
taxtree(table, collapse = TRUE, lineage_length = 1, root = "")
table |
dataframe. |
collapse |
logical. Should node with one child be vanished? Default to TRUE. |
lineage_length |
double. Lineage length from the root to the leaves. Default to 1. |
root |
character. Name of the root if there is no natural root. |
A phylo object.
lineage1 <- "k__Bacteria|p__Verrucomicrobia|c__Verrucomicrobiae" lineage2 <- "k__Bacteria|p__Firmicutes|c__Clostridia" lineage3 <- "k__Bacteria|p__Firmicutes|c__Bacilli" table <- taxtable(c(lineage1, lineage2, lineage3)) taxtree(table)
lineage1 <- "k__Bacteria|p__Verrucomicrobia|c__Verrucomicrobiae" lineage2 <- "k__Bacteria|p__Firmicutes|c__Clostridia" lineage3 <- "k__Bacteria|p__Firmicutes|c__Bacilli" table <- taxtable(c(lineage1, lineage2, lineage3)) taxtree(table)
Trim lineages until the shallowest common rank.
trim_common(lineage, remove_void = TRUE, only_tail = TRUE)
trim_common(lineage, remove_void = TRUE, only_tail = TRUE)
lineage |
string. Vector of lineages. |
remove_void |
Should void ranks be removed? Default to |
only_tail |
Logical to be passed to |
The trimmed lineages, with same depth.
lineage1 <- "k__Bacteria|p__Verrucomicrobia|c__Verrucomicrobiae" lineage2 <- "k__Bacteria|p__Firmicutes" lineage3 <- "k__Bacteria|p__|c__Clostridia" trim_common(c(lineage1, lineage2, lineage3), remove_void = FALSE) trim_common(c(lineage1, lineage2, lineage3), only_tail = FALSE)
lineage1 <- "k__Bacteria|p__Verrucomicrobia|c__Verrucomicrobiae" lineage2 <- "k__Bacteria|p__Firmicutes" lineage3 <- "k__Bacteria|p__|c__Clostridia" trim_common(c(lineage1, lineage2, lineage3), remove_void = FALSE) trim_common(c(lineage1, lineage2, lineage3), only_tail = FALSE)
Trim lineages until a specified rank
trim_rank(lineage, rank = yatah::all_ranks, same = TRUE)
trim_rank(lineage, rank = yatah::all_ranks, same = TRUE)
lineage |
string. Vector of lineages. |
rank |
string. One of |
same |
logical. Does the lineage have the same depth? Default to |
Returns NA
if a lineage is not as deep as the specified rank.
The trimmed lineages. Depth could be different among them.
lineage1 <- "k__Bacteria|p__Verrucomicrobia|c__Verrucomicrobiae" lineage2 <- "k__Bacteria|p__Firmicutes|c__Clostridia" trim_rank(c(lineage1, lineage2), rank = "phylum") trim_rank(c(lineage1, lineage2), rank = "genus")
lineage1 <- "k__Bacteria|p__Verrucomicrobia|c__Verrucomicrobiae" lineage2 <- "k__Bacteria|p__Firmicutes|c__Clostridia" trim_rank(c(lineage1, lineage2), rank = "phylum") trim_rank(c(lineage1, lineage2), rank = "genus")
Trim void ranks in lineages
trim_void(lineage, same = TRUE, only_tail = FALSE)
trim_void(lineage, same = TRUE, only_tail = FALSE)
lineage |
string. Vector of lineages. |
same |
logical. Does the lineage have the same depth? Default to |
only_tail |
Logical. If |
If there is a void rank amid a lineage, deeper ranks
will be removed. See the example with lineage3
.
The trimmed lineages. Depth could be different among them.
lineage1 <- "k__Bacteria|p__Verrucomicrobia|c__Verrucomicrobiae|o__|f__" lineage2 <- "k__Bacteria|p__Firmicutes|c__" lineage3 <- "k__Bacteria|p__|c__Verrucomicrobiae|o__|f__" trim_void(c(lineage1, lineage2, lineage3), same = FALSE) trim_void(c(lineage1, lineage2, lineage3), same = FALSE, only_tail = TRUE)
lineage1 <- "k__Bacteria|p__Verrucomicrobia|c__Verrucomicrobiae|o__|f__" lineage2 <- "k__Bacteria|p__Firmicutes|c__" lineage3 <- "k__Bacteria|p__|c__Verrucomicrobiae|o__|f__" trim_void(c(lineage1, lineage2, lineage3), same = FALSE) trim_void(c(lineage1, lineage2, lineage3), same = FALSE, only_tail = TRUE)