-
Notifications
You must be signed in to change notification settings - Fork 187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
very different weighted unifrac values for qiime2 versus phyloseq #956
Comments
Rarefaction in Phyloseq vs rarefaction in qiime 2? |
The OTU table was already rarefied before beta-diversity calculation with either phyloseq or qiime2. Qiime2 rarefies without replacement, so using a rarefying sampling depth set to the same value as the sample sums for the pre-rarefied OTU table is equivalent to not rarefying (at least, it should be). |
Hi, I would guess that you have been using an un-rooted phylogenetic tree when calculating the Unifrac distances. To calculate the UniFrac distances you need a rooted tree, and I'm 95% sure that Qiime2 and phyloseq are using different ways to root the phylogenetic tree. Best, |
I believe that all of the trees that I've been using for testing are with rooted phylogenies. I've posted a Jupyter notebook on the qiime2 forum if you'd like to see an example with the |
Dear Nick Did you hear anything from the Phyloseq guys or the Qiime2 team? |
I think that Greg Caporaso was going to look into it, but I haven't heard anything about it. I just ended up using qiime2 instead of phyloseq, because it generated more realistic results for my dataset. |
I have exactly the same issue. Moreover, there are two different ways in phyloseq to get wunifrac distance matrix, and both give different results (UniFrac(X, weighted=TRUE, normalized=TRUE) vs. distance(X, method="wunifrac")). |
@siberianhigh how do the two phyloseq methods compare to the weighted Unifrac that QIIME2 is producing? |
@cjfields they both are different from qiime (and much more similar to each other than to qiime). I still prefer QIIME1, but in my experience there is no difference with QIIME2. |
Moreover, "Depending on the method argument, distance() wraps one of UniFrac, DPCoA, JSD, vegdist, betadiver, designdist, or dist." So, I don't understand the origin of these differences.. |
My lab has been dealing with this as well. I tried to make a reproducible test based off skbio's python Unifrac (which is what QIIME runs under the hood, I think), and I actually can't get it to run in phyloseq. skbio documentation: http://scikit-bio.org/docs/0.4.2/generated/generated/skbio.diversity.beta.unweighted_unifrac.html Code adapted to phyloseq
The result of this is
I don't know the guts of how UniFrac is calculated, but it seems that the code is making an assumption that isn't always satisfied. (That there are fewer tips than internal nodes?) Given that I also ran into an independent error (#1215) using data phyloseq had filtered, I think it's fair to say that the phyloseq UniFrac implementation still has some bugs in it. Unfortunately, I don't know phylogenetic trees and UniFrac well enough to suggest fixes or I'd try to do so. The QIIME developers claims to benchmark their UniFrac against the original PyCogent implementation every build, so it's probably the safer bet to use QIIME for UniFrac until this is resolved. (If need be, you can import the resulting distance matrix into R for downstream analysis.) |
@wallacelab have you tried other UniFrac implementations within R, such as |
@cjfields I finally got time to test this, comparing unifrac from
Short version is that phyloseq still fails on this, but the other three give identical unweighted unifrac distances (0.3692308). The weighted value is different from rbiom (1.543434) to GUniFrac (0.3275034), which I suspect is due to the latter normalizing it, but I haven't had a chance to confirm. Still working to check with QIIME, but I think your idea of just using a different library is probably a good one. (Note: |
Okay, I did some more digging to compare to QIIME. First, bash script to get sample data and run UniFrac (data is QIIME's own Moving Pictures tutorial):
Now, R script to compare UniFrac measures:
Of note,
The final matrix of comparisons (= correlations among the distance matrices) is:
So in short, So it seems if you have to pick one, pick |
Update: I realized I hadn't rarefied the data before doing UniFrac. Rarefaction makes the Unweighted Unifac equal across everything (except phyloseq), but weighted still only matches for rbiom:
So at least as far as matching QIIME goes, rbiom seems the most reliable. (Incidentally, I also tried this with the benchmark data skbio uses for unit testing, and in that case everything but phyloseq matches 100% for both metrics. Looks like there's some complication in real data that the benchmark isn't capturing.) |
@wallacelab I'm able to reproduce this, great walkthrough! I suspect the fast UniFrac method implemented in phyloseq has issues with weighting. It does look like UniFrac distance is supposedly tested? |
Yes, and that testing seems to work. (I plugged the data into my comparison and it came out fine; code at end):
It looks like some programs have different defaults for normalization, but otherwise everything matches. So it looks like the test data lacks whatever feature is causing issues for phyloseq. (I suspect it's with the phylogenetic tree having an odd number of total edges, given the error it spits out.) Notably, the Global Patterns tree used in the unit test has 998 edges (even) and works, but the Moving Pictures one has 1515 (odd) and fails. Code for above comparison:
|
@wallacelab odd, this almost sounds like a fence-post error but only for weighted UniFrac. I see how it fell through the cracks; definitely worth adding a simple test case for catching this. |
Hi @wallacelab and @cjfields, if you want to compare phyloseq's weighted unifrac calculation to rbiom's, you should set phyloseq_weighted = phyloseq::UniFrac(phyloseq_data, weighted=TRUE, normalized = FALSE) Then running @wallacelab 's code gives near perfect similarity between phyloseq and rbiom's weighted calculations. Rbiom is computing the quantity (Please let me know if I've missed something here) |
Ping. Interested in any updates here. Is this just a normalization difference? |
No, it's not. Different normalization defaults are a minor part of it, but the bigger issue seems to be that Phyloseq is making assumptions about the data without checking if those assumptions are true. The two outstanding problems I see are:
So no, not just normalization. (Though it would be nice to include a message to the user when UniFrac is run so they know what the default is.) |
@wallacelab do you have a comparison of the speeds for each implementation of unifrac that you list above? I'm processing a large OTU table right now with GUniFrac, and it's been running for ~72 hours, so I'm looking for a faster implementation. |
@nick-youngblut I didn't, but it's not too hard to test. (see https://www.alexejgossmann.com/benchmarking_r/ for benchmarking tutorial)
Which results (on my computer) in
So looks like rbiom is fastest (~2.5x faster than phyloseq and ~300x faster than gunifrac) |
I can back up those results. With an OTU table of approx. 6000 x 3500, GUniFrac didn't finish after 72 hours, while rbiom (with 4 threads) finished in < 1 hour. I didn't try phyloseq due to the questionable results that it can generate. |
Any updates on this? |
For phyloseq unifrac I wonder if this will solve any of the discrepancies? I was having issues with edges in the tree and doing this resolved them. But, never validated answers against other programs calculating unifrac tree = read.tree("FinalRFiles/SalAMPtree.nwk") This fixes issue with tree$edge issue and unifrac calculations latersee #936new_tre <- ape::multi2di(tree) Which is mentioned above, but sounds like this may be a bad fix? |
I cannot add much to this thread but all I can say is I have a massive dataset of vertebrate gut microbiomes and the phyloseq unifrac ordination leads to a drastically different biological conclusion from the qiime2 ordination. I made to sure to rarefy in phyloseq as well. Based off this thread I will be sticking with the qiime2 output but I hope this gets fixed! |
It's getting close to 4 years since my original post of this issue, and it seems that qiime (qiime2 now) is still the way to go for calculating (phylogenetic) beta diversity. It might be best to include large warnings in the documentation that qiime2 and phyloseq can generate very different beta diversity values |
@nick-youngblut I agree re: warnings. Unfortunately (on the surface at least) it appears there has been very little additional maintenance or development on phyloseq, though hopefully that will change! |
Hi @nick-youngblut - could you comment if this is happening with unweighted unifrac also, or only weighted unifrac. I have noticed that weighted unifrac in phyloseq seems very different in biological conclusion from other measures such as bray-curtis. |
@CarlyMuletzWolz see the above posts on unweighted unifrac |
A couple of members of my lab and I have been getting very different results when using qiime2 versus phyloseq for calculating weighted unifrac values. It seems that the default parameters used by these tools (qiime diversity core-metrics-phylogenetic versus phyloseq::distance) generate very different weighted unifrac values, even when pre-rarefying the dataset (since qiime2 automatically rarefies).
I've already posted this issue with a reproducible example with the
GlobalPatterns
dataset on the qiime2 forum.Any idea why there's such a big difference between the qiime2 and phyloseq defaults for calculating weighted unifrac values? Moreover, which method is generating "correct" weighted unifrac values? At least from analyzing my own microbiome dataset, the conclusions are completely different depending on if I use the qiime2- versus phyloseq-generated weighted unifrac values.
The text was updated successfully, but these errors were encountered: