Tutorial:How to get full taxonomy classification using taxize and myTAI
0
4
Entering edit mode
6.6 years ago
Daniel ★ 4.0k

There are lots of questions regarding this, and I have asked them myself over the years, but I've recently found this tool which is great and I thought I'd put a standard example. This might not be the best way of parsing the outputs in R, but as a tool it generates all the right data!

library("taxize")
library("myTAI")
library(dplyr)

lst <- read.csv("/home/temp/species.txt", header=FALSE)

# one sample example (then you're finished!)
taxonomy(organism = "Utamphorophora" , db = "ncbi", output = "classification")

Output

                 name         rank      id
1  cellular organisms      no rank  131567
2           Eukaryota superkingdom    2759
3        Opisthokonta      no rank   33154
4             Metazoa      kingdom   33208
5           Eumetazoa      no rank    6072
6           Bilateria      no rank   33213
7         Protostomia      no rank   33317
8           Ecdysozoa      no rank 1206794
9       Panarthropoda      no rank   88770
10         Arthropoda       phylum    6656
11        Mandibulata      no rank  197563
12       Pancrustacea      no rank  197562
13           Hexapoda    subphylum    6960
14            Insecta        class   50557
15         Dicondylia      no rank   85512
16          Pterygota     subclass    7496
17           Neoptera   infraclass   33340
18       Paraneoptera       cohort   33342
19          Hemiptera        order    7524
20     Sternorrhyncha     suborder   33373
21       Aphidomorpha   infraorder   33380
22         Aphidoidea  superfamily   33385
23          Aphididae       family   27482
24          Aphidinae    subfamily  133076
25       Macrosiphini        tribe   33386
26     Utamphorophora        genus  527951

Get taxonomy for entire list

outputlst <- apply(lst, 1, function(x) taxonomy( organism = x , db = "ncbi", output = "classification" ))

# Parse out the taxonomy levels that you require
taxdata = data.frame()
for(x in 1:length(outputlst)){
    tryCatch({
      phylum=filter(outputlst[[x]], rank =="phylum")$name
      class=filter(outputlst[[x]], rank =="class")$name
      order=filter(outputlst[[x]], rank =="order")$name
      family=filter(outputlst[[x]], rank =="family")$name
      genus=filter(outputlst[[x]], rank =="genus")$name
      species=filter(outputlst[[x]], rank =="species")$name

      row <- data.frame(cbind(phylum=phylum,class=class,order=order,family=family,genus=genus))
      taxdata <- bind_rows(taxdata, row)    
    }, error=function(e){cat("ERROR :",conditionMessage(e), "\n")})
}
write.csv(taxdata, file="taxdata-full.txt")

Hope this helps!

taxonomy R • 4.8k views
ADD COMMENT
0
Entering edit mode

this Tutorial help me a lot! thank you so much!

ADD REPLY
0
Entering edit mode

You could give it an upvote.

ADD REPLY
0
Entering edit mode

Is there any way to do this given a list of taxids and not taxonomy names?? Cause that would help me sooo much!

ADD REPLY

Login before adding your answer.

Traffic: 1560 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6