Reformat lineage in chosen ranks, allowing more ranks than 'reformat'. This function only accepts TaxIDs as input (not lineage strings).
taxonkit_reformat2(
file_path,
format_string = "",
miss_rank_repl = "",
miss_taxid_repl = "",
no_ranks = c("no rank", "clade"),
show_lineage_taxids = FALSE,
taxid_field = 1,
trim = FALSE,
text = FALSE,
data_dir = NULL
)The path to the input file with taxonomic IDs. Or file text (text=TRUE)
The output format string with placeholders for each rank. Use "|" to set multiple ranks, the first valid one will be output. Example: "domain|acellular root|superkingdom;phylum;class;order;family;genus;species"
The replacement string for missing rank.
The replacement string for missing taxid.
A character vector of rank names considered as "no-rank". A lineage might have many "no rank" ranks, we only keep the last one below known ranks. Default: c("no rank", "clade")
Logical, indicating whether to show corresponding taxids of reformatted lineage (default: FALSE)
The field index of taxid. Input data should be tab-separated (default: 1)
Logical, indicating whether to not replace missing ranks lower than the rank of the current node (default: FALSE)
logical. If TRUE, file_path is treated as text input
directory containing nodes.dmp and names.dmp (default "/Users/asa/.taxonkit")
A character vector containing the reformatted taxonomic lineages.
Key differences from taxonkit_reformat():
Input: only accepts TaxIDs
Format: accepts more rank placeholders, not just the seven canonical ones
Format: uses full rank names like "species" rather than "s"
Format: supports multiple ranks in one placeholder like "subspecies|strain"
No automatic prefix addition (but you can add them in the format string)
if (FALSE) { # \dontrun{
# Example 1: Basic usage with default format
taxids <- c("9606", "376619", "11932")
tmp_file <- tempfile()
writeLines(taxids, tmp_file)
result <- taxonkit_reformat2(tmp_file)
# Example 2: Custom format with multiple rank options
result2 <- taxonkit_reformat2(
tmp_file,
format_string = "{domain|acellular root|superkingdom};{kingdom};{phylum};{class}"
)
# Example 3: With text input
taxonkit_reformat2(
"2759\n2\n10239",
format_string = "{domain|acellular root|superkingdom}",
text = TRUE
)
# Clean up
unlink(tmp_file)
} # }