Skip to contents

Trim lineages until a specified rank

Usage

trim_rank(lineage, rank = yatah::all_ranks, same = TRUE)

Arguments

lineage

string. Vector of lineages.

rank

string. One of c("kingdom", "phylum", "class", "order", "family", "genus", "species", "strain") with partial matching.

same

logical. Does the lineage have the same depth? Default to TRUE.

Value

The trimmed lineages. Depth could be different among them.

Details

Returns NA if a lineage is not as deep as the specified rank.

Examples

lineage1 <- "k__Bacteria|p__Verrucomicrobia|c__Verrucomicrobiae"
lineage2 <- "k__Bacteria|p__Firmicutes|c__Clostridia"
trim_rank(c(lineage1, lineage2), rank = "phylum")
#> [1] "k__Bacteria|p__Verrucomicrobia" "k__Bacteria|p__Firmicutes"     
trim_rank(c(lineage1, lineage2), rank = "genus")
#> [1] NA NA