Extract the 'phylum' and 'species' under "classification" using Taxize package in R
0
1
Entering edit mode
7.2 years ago
horsedog ▴ 60

I have a bunch of bateria and I want to know their taxanomic name, here I use Taxize package in R and got the "table" of taxanomy, due to the format problem here I'm not able to show it clearly, but for example it's like there are three titles for three columns naming "name", "rank" and "id", and below "rank", there are "phylum", "class", "order", "family", "genus". and "species", accordingly below "name" they are Firmicutes, Erysipelotrichia, Erysipelotrichales, Erysipelotrichaceae, Erysipelatoclostridium, [Clostridium] innocuum, here I need the name of phylum and genus for this bacteria, which are Firmicutes and Erysipelatoclostridium, how I can extract them(there are 184 bacteria i want to do the same way) this is not a data frame so I try to use data,frame(), but it says cannot coerce class ""classification"" to a data.frame, and I don't know how to extract the information that I want, anybody knows it? Many thanks!

R • 4.5k views
ADD COMMENT
0
Entering edit mode

could you post example data here and the code you have used?

ADD REPLY
0
Entering edit mode

SInce you are using taxize package, following is the easier way to get the information you want (in a dataframe):

> library(taxize)
> specieslist <- c("Clostridium botulinum","Bacillus subtilis")
> tax_name(query = c(specieslist), get = c("phylum","genus"), db = "ncbi")

you can change database such as itis instead of ncbi. code output:

    db                 query     phylum       genus
1 ncbi Clostridium botulinum Firmicutes Clostridium
2 ncbi     Bacillus subtilis Firmicutes    Bacillus

output as data frame:

> test=tax_name(query = c(specieslist), get = c("phylum","genus"), db = "ncbi")
 > class(test)
[1] "data.frame"
ADD REPLY
0
Entering edit mode

If you already have a classification object, use the following code (but change the row ids as per your object):

library(taxize)
specieslist <- c("Clostridium botulinum","Bacillus subtilis")
test=classification(specieslist, db = 'itis')

test (classification object)

> test
$`Clostridium botulinum`
                   name       rank     id
1              Bacteria    kingdom     50
2          Posibacteria subkingdom 956097
3            Firmicutes     phylum 956114
    .....
    ..... so on

$`Bacillus subtilis`
               name       rank     id
1          Bacteria    kingdom     50
2      Posibacteria subkingdom 956097
3        Firmicutes     phylum 956114
    .....
    ..... so on

attr(,"class")
[1] "classification"
attr(,"db")
[1] "itis"

In this classification class, for each bacterium, row 3 and 7 are phylum and genus respectively. So following code extracts phylum and genus for two bacteria and saves them as dataframe.

test1=as.data.frame(t(sapply(names(test), function (x) test[[x]] [,1])[c(3,7),]))
names(test1)=test[[1]][,2][c(3,7)]

test object is obtained above.

output of test1:

> test1
                          phylum       genus
Clostridium botulinum Firmicutes Clostridium
Bacillus subtilis     Firmicutes    Bacillus
ADD REPLY

Login before adding your answer.

Traffic: 2673 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