Skip to content

Instantly share code, notes, and snippets.

@sckott
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sckott/8825559 to your computer and use it in GitHub Desktop.
Save sckott/8825559 to your computer and use it in GitHub Desktop.
Taxize

Using taxize to get a classification

Install taxize

install.packages("taxize")

Load taxize

library(taxize)

Get a set of species names

sp <- names_list("species", 10)

Get classifications for each species

res <- classification(sp, db = "col")

Remove missing taxa

res <- res[!is.na(res)]

Combine results to a data.frame, and select only certain ranks

library(plyr)
ldply(res, function(x) x[x$rank %in% c('Kingdom','Family','Genus'),])

Or this way

library(plyr)
library(reshape2)
ldply(res, function(x){
  tmp <- data.frame(t(x$name))
  names(tmp) <- x$rank
  tmp
})
                          .id Kingdom       Phylum         Class      Order         Family     Genus
1       Pohlia camptotrachela Plantae    Bryophyta     Bryopsida    Bryales       Bryaceae    Pohlia
2       Spiridens vieillardii Plantae    Bryophyta     Bryopsida    Bryales Spiridentaceae Spiridens
3 Gunnera katherine-wilsoniae Plantae Tracheophyta Magnoliopsida Gunnerales    Gunneraceae   Gunnera
4          Encalypta vulgaris Plantae    Bryophyta     Bryopsida  Pottiales  Encalyptaceae Encalypta
5           Hampeella pallens Plantae    Bryophyta     Bryopsida Isobryales Ptychomniaceae Hampeella
write.csv(df, file="awafsdsdf.csv", row.names=FALSE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment