next up previous
Next: info Up: CHNOSZ examples Previous: util.units

taxonomy

taxnmy>   ## get information about Homo sapiens from the
taxnmy>   ## packaged taxonomy files
taxnmy>   taxdir <- system.file("extdata/taxonomy",package="CHNOSZ")

taxnmy>   # H. sapiens' taxonomic id
taxnmy>   id1 <- 9606

taxnmy>   # that is a species
taxnmy>   getrank(id1,taxdir)
Read 63 records
[1] "species"

taxnmy>   # the next step up the taxonomy
taxnmy>   id2 <- parent(id1,taxdir)
Read 63 records

taxnmy>   print(id2)
[1] 9605

taxnmy>   # that is a genus
taxnmy>   getrank(id2,taxdir)
Read 63 records
[1] "genus"

taxnmy>   # that genus is "Homo"
taxnmy>   sciname(id2,taxdir)
Read 215 records
[1] "Homo"

taxnmy>   # we can ask what phylum is it part of?
taxnmy>   id3 <- parent(id1,taxdir,"phylum")
Read 63 records

taxnmy>   # answer: "Chordata"
taxnmy>   sciname(id3,taxdir)
Read 215 records
[1] "Chordata"

taxnmy>   # H. sapiens' complete taxonomy
taxnmy>   id4 <- allparents(id1,taxdir)
Read 63 records

taxnmy>   sciname(id4,taxdir)
Read 215 records
 [1] "Homo sapiens"        "Homo"                "Homininae"           "Hominidae"          
 [5] "Hominoidea"          "Catarrhini"          "Simiiformes"         "Haplorrhini"        
 [9] "Primates"            "Euarchontoglires"    "Eutheria"            "Theria"             
[13] "Mammalia"            "Amniota"             "Tetrapoda"           "Sarcopterygii"      
[17] "Euteleostomi"        "Teleostomi"          "Gnathostomata"       "Vertebrata"         
[21] "Craniata"            "Chordata"            "Deuterostomia"       "Coelomata"          
[25] "Bilateria"           "Eumetazoa"           "Metazoa"             "Fungi/Metazoa group"
[29] "Eukaryota"           "cellular organisms"  "root"               

taxnmy>   ## the names of the organisms in the supplied
taxnmy>   ## taxonomy files
taxnmy>   taxdir <- system.file("extdata/taxonomy",package="CHNOSZ")

taxnmy>   id5 <- c(83333,4932,9606,186497,243232)

taxnmy>   sciname(id5,taxdir)
Read 215 records
[1] "Escherichia coli K-12"                  "Saccharomyces cerevisiae"              
[3] "Homo sapiens"                           "Pyrococcus furiosus DSM 3638"          
[5] "Methanocaldococcus jannaschii DSM 2661"

taxnmy>   # these are not all species, though
taxnmy>   # (those with "no rank" are something like strains, 
taxnmy>   # e.g. Escherichia coli K-12)
taxnmy>   getrank(id5,taxdir)
Read 63 records
[1] "no rank" "species" "species" "no rank" "no rank"

taxnmy>   # find the species for each of these
taxnmy>   id6 <- sapply(id5,function(x) parent(x,taxdir=taxdir,rank="species"))
Read 63 records
Read 63 records
Read 63 records
Read 63 records
Read 63 records

taxnmy>   stopifnot(unique(getrank(id6,taxdir))=="species")
Read 63 records

taxnmy>   # note that the K-12 is dropped
taxnmy>   sciname(id6,taxdir)
Read 215 records
[1] "Escherichia coli"              "Saccharomyces cerevisiae"      "Homo sapiens"                 
[4] "Pyrococcus furiosus"           "Methanocaldococcus jannaschii"

taxnmy>   ## the complete nodes.dmp and names.dmp files are quite large,
taxnmy>   ## so it helps to store them in memory when performing multiple queries
taxnmy>   ## (this doesn't have a noticeable speed-up for the small files
taxnmy>   ## we use in this example)
taxnmy>   taxdir <- system.file("extdata/taxonomy",package="CHNOSZ")

taxnmy>   nodes <- getnodes(taxdir=taxdir)
Read 63 records

taxnmy>   # all of the node ids in this file
taxnmy>   id7 <- nodes$id

taxnmy>   # all of the non-leaf nodes
taxnmy>   id8 <- unique(parent(id7,nodes=nodes))

taxnmy>   names <- getnames(taxdir=taxdir)
Read 215 records

taxnmy>   sciname(id8,names=names)
 [1] "root"                          "cellular organisms"            "Enterobacteriales"            
 [4] "Enterobacteriaceae"            "Escherichia"                   "Bacteria"                     
 [7] "Proteobacteria"                "Methanococci"                  "Methanocaldococcus"           
[10] "Thermococci"                   "Thermococcales"                "Thermococcaceae"              
[13] "Pyrococcus"                    "Fungi/Metazoa group"           "Dikarya"                      
[16] "Saccharomycotina"              "Saccharomycetes"               "Saccharomycetales"            
[19] "Saccharomycetaceae"            "Saccharomyces"                 "Metazoa"                      
[22] "Deuterostomia"                 "Craniata"                      "Vertebrata"                   
[25] "Euteleostomi"                  "Theria"                        "Euarchontoglires"             
[28] "Simiiformes"                   "Hominoidea"                    "Homininae"                    
[31] "Homo"                          "Archaea"                       "Sarcopterygii"                
[34] "Tetrapoda"                     "Mammalia"                      "Eukaryota"                    
[37] "Eumetazoa"                     "Bilateria"                     "Coelomata"                    
[40] "Amniota"                       "Escherichia coli"              "Chordata"                     
[43] "Gammaproteobacteria"           "Gnathostomata"                 "Teleostomi"                   
[46] "Saccharomyceta"                "Euryarchaeota"                 "Pyrococcus furiosus"          
[49] "Methanococcales"               "Methanocaldococcaceae"         "Hominidae"                    
[52] "Methanocaldococcus jannaschii" "Eutheria"                      "Haplorrhini"                  
[55] "Catarrhini"                    "Primates"                      "Fungi"                        
[58] "Ascomycota"


next up previous
Next: info Up: CHNOSZ examples Previous: util.units