louyi871
louyi871

Reputation: 21

unable to import a mothur tree into R

I build a tree by mothur, it produced a newick format file here is the tree file :

(((X32:0.077342,(X13:0.030507,X5:0.032193):0.081108):0.009719,((((((((((X7:0.011658,X16:0.020922):0.004990,X9:0.011395):0.026780,X23:0.044775):0.091180,X100:0.154611):0.041705,((((X8:0.020255,X42:0.008695):0.029872,(X19:0.025754,X61:0.020516):0.036208):0.084498,X218:0.111857):0.022793,X239:0.176169):0.011033):0.063911,(X18:0.070163,X146:0.072237):0.050456):0.014607,(X24:0.065513,X78:0.067187):0.052101):0.010160,X25:0.105835):0.011914,X45:0.130995):0.009387,((X10:0.021955,(X4:0.016382,X1236:0.016838):0.004625):0.036976,X128:0.056704):0.033204):0.006892),(((X6:0.020583,X11:0.012977):0.062459,(X1:0.030791,X22:0.025639):0.033446):0.009294,(X49:0.049533,X3:0.048877):0.011889):0.010353);

When I tried to import it into R using import_mothur {phyloseq}, it gave me error

Error in `taxa_names<-`(`*tmp*`, value = c("X32", "X13", "X5", "X7", "X16",  : 
  taxa_names<-: You are attempting to assign duplicated taxa_names

I looked this tree file and can not find any duplicated names. I used a different dataset (sequence data) but same method in mothur, this worked. I just don't understand which wrong with this file?

Thank you!!!!

Upvotes: 2

Views: 815

Answers (2)

michberr
michberr

Reputation: 303

I just came across this bug myself. The solution that worked for me was to use the read.newick() command from the phytools package to read in the tree file to R. From there you can import the tree into phyloseq with phy_tree() and merge_phyloseq. For some reason the read.tree command in ape doesn't like the clearcut formatted newick files.

xtree <- read.newick("test.tree") phy_xtree <- phy_tree(xtree) # Constructor for phy_tree object physeq_merged <- merge_phyloseq(physeq, phy_xtree) # Merge tree into phyloseq object

Upvotes: 3

MrFlick
MrFlick

Reputation: 206253

The file is actually being read by read.tree from the ape package. For some reason it does not like the format of this file. I admit that I am not familiar with this file format, but if you import it with

xtree <- read.tree("test.tree")
plot(xtree)

enter image description here

you see that there are some unnamed tips. Those are causing the problem. The read.table function is assigning those to NODE values rather than TIP values. You can "fix" the tree and get the same result as you would from import_mothur with

xtree$tip.label[c(26,28,30)]<-paste0("X", c(6,1,49))
phyloseq(xtree)

So i'm guessing there's something wrong with your newick format file or there's a bug in the ape::read.tree function.

Upvotes: 1

Related Questions