# QIIME2R -\> trouble with phyloseq and rooted tree

**URL:** https://forum.qiime2.org/t/qiime2r-trouble-with-phyloseq-and-rooted-tree/12052
**Category:** Other Bioinformatics Tools
**Tags:** dada2, tree
**Created:** [October 19, 2019, 12:38pm UTC](https://forum.qiime2.org/t/qiime2r-trouble-with-phyloseq-and-rooted-tree/12052 "2019-10-19T12:38:35Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![ben](https://forum.qiime2.org/user_avatar/forum.qiime2.org/ben/32/1790_2.png) [@ben](https://forum.qiime2.org/u/ben)
#### Post date: [October 19, 2019, 12:38pm UTC](https://forum.qiime2.org/t/qiime2r-trouble-with-phyloseq-and-rooted-tree/12052/1 "2019-10-19T12:38:35Z")

</div>

Hi all,

Strange behavior, which wasn't happening when I used the QIIME2R prior, but I am having issues now. I have a merged file w/ 5 different runs. I merged these runs and filtered the file.

I then created a tree with MAFFT and then rooted it. So I have a "rooted\_tree.qza" file. I then used the command from QIIME2R:

> phy\<-qza\_to\_phyloseq("filtered.merge.table.qza", "rooted-tree.qza", "taxonomy.qza","MSQ.mouse.master.map.txt")

This object looks like this:

> phyloseq-class experiment-level object  
> otu\_table() OTU Table: [12722 taxa and 903 samples]  
> sample\_data() Sample Data: [903 samples by 34 sample variables]  
> tax\_table() Taxonomy Table: [12722 taxa by 7 taxonomic ranks]  
> phy\_tree() Phylogenetic Tree: [12722 tips and 12548 internal nodes]

I then give the column names ranks:

> colnames(tax\_table(phy))=c("Domain", "Phylum", "Class", "Order", "Family", "Genus", "OTU")

This file can create a PCOA that is rooted:

 ![47%20AM](https://forum-qiime2-org.s3.dualstack.us-west-2.amazonaws.com/original/2X/8/8ac7463edadec57e8825ce1fc1474b9e4afe6ad3.png)

When I try to subset this file by piping via sample type (e.g., Lung).

> Lung.phy.table = subset\_samples(phy.relative.table, Sample %in% c('Lung'))

Then try to recreate the PCOA with experiment I get this error:

> Warning message:  
> In matrix(tree$edge[order(tree$edge[, 1]), ][, 2], byrow = TRUE, :  
> data length [25269] is not a sub-multiple or multiple of the number of rows [12635]

This sounds like it's an issue with the tree. I've googled this and it's because the tree doesn't match the input file.

> <https://github.com/joey711/phyloseq/issues/936>
>
> I'm running into trouble calculating unifrac distances in phyloseq. I keep getti…ng the following message whenever I run the distance function with weighted or unweighted unifrac:
> 
> \`Warning message: In matrix(tree$edge\[order(tree$edge\[, 1\]), \]\[, 2\], byrow = TRUE, : data length \[86515\] is not a sub-multiple or multiple of the number of rows \[43258\]\`
> 
> I've checked to make sure that my tree is rooted, that there are no 0 count OTUs in my count table, or any NA values in the OTU count table or tree. After seeing this thread I updated phyloseq (v1.23.1), but the problem is still ongoing. A solution will be reached when I run the distance function, but I'm not sure if it can be trusted. Does anyone have any ideas about what this warning means, how much of a problem it is, and how it might be solved? I'd really appreciate the help.
> 
> Thanks in advance! 
> 
> Update: I've updated R to version 3.5 and all packages to the latest versions (vegan v2.5-2, ape v5.1, and phyloseq v1.24.0) but no luck getting rid of the warning.
> 
> Edit: Removed data and code 7/3/18

Interestingly, it also has issues with Bray distance which shouldn't be based on the tree. I"m wondering if there's something to do with how the object is created from the QIIME2 import? Has anyone else had this issue? Ben

edit: Just to be clear, I think I know what the problem is: when I subset the data, what is happening is that the root of the tree is in a ASV which is filtered out with the rest of the subletting to Lung samples only. So, somehow, I need to re-root the tree within this subsetted phyloseq object.

This behavior is slightly troublesome, because I did this before with the objects and I never had a problem with QIIME2 and R, so I'm wondering if something changed now that there's some compatibility issue.

edit edit: I am an idiot. I referred to another phyloseq object.

---

<div class="post-metadata">

### Author: ![Nicholas\_Bokulich](https://forum.qiime2.org/user_avatar/forum.qiime2.org/nicholas_bokulich/32/19937_2.png) [@Nicholas\_Bokulich](https://forum.qiime2.org/u/Nicholas_Bokulich)
#### Post date: [October 21, 2019, 4:07pm UTC](https://forum.qiime2.org/t/qiime2r-trouble-with-phyloseq-and-rooted-tree/12052/2 "2019-10-21T16:07:13Z")

</div>



---

<div class="post-metadata">

### Author: ![jbisanz](https://forum.qiime2.org/user_avatar/forum.qiime2.org/jbisanz/32/1720_2.png) [@jbisanz](https://forum.qiime2.org/u/jbisanz)
#### Post date: [October 21, 2019, 4:18pm UTC](https://forum.qiime2.org/t/qiime2r-trouble-with-phyloseq-and-rooted-tree/12052/3 "2019-10-21T16:18:14Z")

</div>

Hmm, could you post `phy_tree(phy)` and `otu_table(phy)` both before and after subsetting? I wouldn't think this is a function of the import, but maybe in pruning the tree to reflect only the features found in the subset samples.

---

<div class="post-metadata">

### Author: ![Nicholas\_Bokulich](https://forum.qiime2.org/user_avatar/forum.qiime2.org/nicholas_bokulich/32/19937_2.png) [@Nicholas\_Bokulich](https://forum.qiime2.org/u/Nicholas_Bokulich)
#### Post date: [October 21, 2019, 4:23pm UTC](https://forum.qiime2.org/t/qiime2r-trouble-with-phyloseq-and-rooted-tree/12052/4 "2019-10-21T16:23:22Z")

</div>



---

<div class="post-metadata">

### Author: ![ben](https://forum.qiime2.org/user_avatar/forum.qiime2.org/ben/32/1790_2.png) [@ben](https://forum.qiime2.org/u/ben)
#### Post date: [October 21, 2019, 4:36pm UTC](https://forum.qiime2.org/t/qiime2r-trouble-with-phyloseq-and-rooted-tree/12052/5 "2019-10-21T16:36:58Z")

</div>

Sorry, I noticed that the tree was having problems as phy too. I think that it's something to do with the tree object when imported in.

> phy\_tree(phy) Phylogenetic tree with 12722 tips and 12548 internal nodes.  
> Tip labels:  
> 3ea2daa1de72aad93dc07c126b4b48e0, d5c3468dc10229eb5ff8ca83c8380894, af42247fdba1e701315071dfe550fdfa, 98cd99d1c9418a0416dac9d5972afb14, 166781e9335f9d9c4d636da6b160648f, 4f407fe8db166c82928d1797b6093a4e, ...  
> Node labels:  
> root, 0.935, 0.980, 0.769, 0.947, 0.284, ...  
> Rooted; includes branch lengths.

> otu\_table(phy.relative.table)  
> OTU Table: [12722 taxa and 903 samples]  
> taxa are rows

Then it spits out a bunch of relative abundances.

> phy\_tree(Lung.phy.table)  
> Phylogenetic tree with 12722 tips and 12548 internal nodes.  
> Tip labels:  
> 3ea2daa1de72aad93dc07c126b4b48e0, d5c3468dc10229eb5ff8ca83c8380894, af42247fdba1e701315071dfe550fdfa, 98cd99d1c9418a0416dac9d5972afb14, 166781e9335f9d9c4d636da6b160648f, 4f407fe8db166c82928d1797b6093a4e, ...  
> Node labels:  
> root, 0.935, 0.980, 0.769, 0.947, 0.284, ...  
> Rooted; includes branch lengths.

> otu\_table(Lung.phy.table)  
> OTU Table: [12722 taxa and 228 samples]  
> taxa are rows

When I run distance calculations I get:

> wUnif.dist = distance(phy.relative.table, method = "wunifrac")Warning message:  
> In matrix(tree$edge[order(tree$edge[, 1]), ][, 2], byrow = TRUE, :  
> data length [25269] is not a sub-multiple or multiple of the number of rows [12635]

> wUnif.dist = distance(Lung.phy.table, method = "wUniFrac")  
> Warning message:  
> In matrix(tree$edge[order(tree$edge[, 1]), ][, 2], byrow = TRUE, :  
> data length [25269] is not a sub-multiple or multiple of the number of rows [12635]

I want to let you know that the distance matrix is still generated even though there's a warning. Ben

---

<div class="post-metadata">

### Author: ![jbisanz](https://forum.qiime2.org/user_avatar/forum.qiime2.org/jbisanz/32/1720_2.png) [@jbisanz](https://forum.qiime2.org/u/jbisanz)
#### Post date: [October 22, 2019, 4:52pm UTC](https://forum.qiime2.org/t/qiime2r-trouble-with-phyloseq-and-rooted-tree/12052/6 "2019-10-22T16:52:05Z")

</div>

hmm, based on the github issue, perhaps try rerooting the tree. Something like this should do it:

```auto
phy_tree(Lung.phy.table)<-phangorn::midpoint(phy_tree(Lung.phy.table))

```

---

<div class="post-metadata">

### Author: ![ben](https://forum.qiime2.org/user_avatar/forum.qiime2.org/ben/32/1790_2.png) [@ben](https://forum.qiime2.org/u/ben)
#### Post date: [October 22, 2019, 4:53pm UTC](https://forum.qiime2.org/t/qiime2r-trouble-with-phyloseq-and-rooted-tree/12052/7 "2019-10-22T16:53:28Z")

</div>

Thanks, that's what I figured - I'm not sure if it really impacted anything downstream, but I've used QIIME2R before and I can't recall if I've gotten anything issue like this before. Ben

---

<div class="post-metadata">

### Author: ![ben](https://forum.qiime2.org/user_avatar/forum.qiime2.org/ben/32/1790_2.png) [@ben](https://forum.qiime2.org/u/ben)
#### Post date: [October 27, 2019, 7:04pm UTC](https://forum.qiime2.org/t/qiime2r-trouble-with-phyloseq-and-rooted-tree/12052/8 "2019-10-27T19:04:39Z")

</div>

> phy\_tree(phy.relative.table)\<-phangorn::midpoint(phy\_tree(phy.relative.table))  
> wUnif.dist = phyloseq::distance(phy.relative.table, method = "wunifrac")  
> Warning message:  
> In matrix(tree$edge[order(tree$edge[, 1]), ][, 2], byrow = TRUE, :  
> data length [25269] is not a sub-multiple or multiple of the number of rows [12635]
> 
> ### estimate number of axes
> 
> wUniF.pco = dudi.pco(cailliez(wUnif.dist), scannf = FALSE, nf = 3)

Weird, I re-rooted the tree, but I'm still having the issue. Ben

---

<div class="post-metadata">

### Author: ![ben](https://forum.qiime2.org/user_avatar/forum.qiime2.org/ben/32/1790_2.png) [@ben](https://forum.qiime2.org/u/ben)
#### Post date: [October 28, 2019, 5:02pm UTC](https://forum.qiime2.org/t/qiime2r-trouble-with-phyloseq-and-rooted-tree/12052/9 "2019-10-28T17:02:43Z")

</div>

Just a follow up, I re-ran portions of my pipeline (to exclude a set of samples) and the problem went away with the new tree.

So, I'm not sure, maybe I was using the wrong tree at the time. So sorry for the trouble. Ben

---

<div class="post-metadata">

### Author: ![colinbrislawn](https://forum.qiime2.org/user_avatar/forum.qiime2.org/colinbrislawn/32/6221_2.png) [@colinbrislawn](https://forum.qiime2.org/u/colinbrislawn)
#### Post date: [October 28, 2019, 5:28pm UTC](https://forum.qiime2.org/t/qiime2r-trouble-with-phyloseq-and-rooted-tree/12052/10 "2019-10-28T17:28:08Z")

</div>

I don't think anything in Phyloseq needs rooted trees, just FYI.

---

<div class="post-metadata">

### Author: ![ben](https://forum.qiime2.org/user_avatar/forum.qiime2.org/ben/32/1790_2.png) [@ben](https://forum.qiime2.org/u/ben)
#### Post date: [October 28, 2019, 5:29pm UTC](https://forum.qiime2.org/t/qiime2r-trouble-with-phyloseq-and-rooted-tree/12052/11 "2019-10-28T17:29:50Z")

</div>

Hm, weird - I guess I was using the wrong tree. Ben
