How to adjust rooted-tree.qza to follow feature-table or metadata?

Hi everyone!

I have run QIIME2 standard "Moving pictures tutorials", build phyloseq object (say ps1) with the qiime2R package without "rooted-tree.qza", modify the ps1, and then save the object as RDS. The modification of ps1 is mostly filtering by a rule, the notable change is that modified ps1 rows are fewer than the original ps1.

Currently, I wanted to try GLMM-MiRKAT but it requires a rooted tree, i.e. returns the error

# Error:
# Error in GUniFrac(, tree, alpha = c(0.5, 1)) : 
# The OTU table contains unknown OTUs! OTU names
# in the OTU table and the tree should match!

According to the GUniFrac source code here, this error is returned because of this condition is TRUE

if (sum(!(colnames( %in% tree$tip.label)) != 0)

Kindly correct me if I am wrong, but does it mean that if the tree contained more information than OTU table, the same error message also would appear?

If yes, then is there a method to adjust the rooted-tree.qza based on new feature table for example? Like adjusting (or filtering) rep-seqs.qza based on a feature table like this?

By the way, is it qiime phylogeny filter-tree?

Hi @Diki,

I'm not exactly sure what you are looking for but, first you mentioned that you created your phyloseq object without a rooted tree, but go on to say you actually need a tree. So I'm confused as why you are not importing a tree into your phyloseq object in the first place? That should solve all of your issues here.

As for your specific questions, that snippet of code you pasted is just checking to make sure all of your OTUs are represented in the tree, and it will stop if there are OTUs not represented in the tree. It will not error if there are more OTUs in the tree than your table. In fact, the next line of code in that link you sent will just give you a "warning" that there were more OTUs in the tree and just subset your tree to match the OTU table.

Typically we make a feature-table and use its representative sequences to build a tree. That way the table and tree match. If you then filter out some reads from your table, you can still use that original tree, having extra tips in a tree won't cause any issues downstream. If for some reason however you do need to filter your tree to match exactly the table, then the phylogeny filter-tree command you mention is the way to go.

Hope I understood your questions correctly.

1 Like

Hi @Mehrbod_Estaki,

Thank you for the reply!

Yes, it will solve the problem. I am wondering if there is a method to do it without going back, so sorry for making it unnecessary and confusing. I think it is wiser to redo the process.

I also did not know that it is okay to have extra tips in the tree for most analyses (i.e. proven by that quick fix with subsetting you pointed out! (I missed it))!

Thank you very much for the guidance!

Hi @Diki,

Well, technically you aren't going back to anything. Building a tree is just an additional step you run separately. So you use the same representative sequences you made originally and build a tree from that, you can then export the tree into R to join with your phyloseq object.

1 Like


Thank you for your response. It is really helpful!

1 Like

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.