
First off, I'd really like to give a shout-out to the brave people who have created and maintain this
great package - the fame is yours!
So, while exploring the capabilities of the package some issues with the ITIS-Server arose and with large datasets things weren't working out quite well for me.
I then switched to the
NCBI API and saw that the result is much better here (way quicker, on first glance also a higher coverage).
At the time there is no taxize-function that will pull taxonomic details from a classification returned by NCBI, that's why I plugged together a little wrapper - see here:
spec <- data.frame("Species" = I(c("Bryum schleicheri", "Bryum capillare", "Bryum argentum", "Escherichia coli", "Glis glis")))
spl <- strsplit(spec$Species, " ")
spec$Genus <- as.character(sapply(spl, "[[", 1))
gen_uniq <- unique(spec$Genus)
get_sys_level <- function(x){ require(taxize)
a <- classification(get_uid(x))
y <- data.frame(a[[1]])
z <- tryCatch(as.character(y[which(y[,2] == "phylum"), 1]), # in case of any other errors put NA
error = function(e) NA)
z <- ifelse(length(z) != 0, z, NA)
return(data.frame(Taxon = x, Syslevel = z))
}
result <- do.call(rbind, lapply(gen_uniq, get_sys_level))
print(result)
spec_new <- merge(spec, result, by.x = "Genus", by.y = "Taxon")
print(spec_new)