## Get information about Homo sapiens from the
## packaged taxonomy files
taxdir <- system.file("extdata/taxonomy", package = "CHNOSZ")
# H. sapiens' taxonomic id
id1 <- 9606
# That is a species
getrank(id1, taxdir)
# The next step up the taxonomy
id2 <- parent(id1, taxdir)
print(id2)
# That is a genus
getrank(id2, taxdir)
# That genus is "Homo"
sciname(id2, taxdir)
# We can ask what phylum is it part of?
id3 <- parent(id1, taxdir, "phylum")
# Answer: "Chordata"
sciname(id3, taxdir)
# H. sapiens' complete taxonomy
id4 <- allparents(id1, taxdir)
sciname(id4, taxdir)
## The names of the organisms in the supplied taxonomy files
taxdir <- system.file("extdata/taxonomy", package = "CHNOSZ")
id5 <- c(83333, 4932, 9606, 186497, 243232)
sciname(id5, taxdir)
# These are not all species, though
# (those with "no rank" are something like strains,
# e.g. Escherichia coli K-12)
getrank(id5, taxdir)
# Find the species for each of these
id6 <- sapply(id5, function(x) parent(x, taxdir = taxdir, rank = "species"))
unique(getrank(id6, taxdir)) # "species"
# Note that the K-12 is dropped
sciname(id6, taxdir)
## The complete nodes.dmp and names.dmp files are quite large,
## so it helps to store them in memory when performing multiple queries
## (this doesn't have a noticeable speed-up for the small files in this example)
taxdir <- system.file("extdata/taxonomy", package = "CHNOSZ")
nodes <- getnodes(taxdir = taxdir)
# All of the node ids in this file
id7 <- nodes$id
# All of the non-leaf nodes
id8 <- unique(parent(id7, nodes = nodes))
names <- getnames(taxdir = taxdir)
sciname(id8, names = names)
Run the code above in your browser using DataLab