# Calculating diversity from relative abundance

**URL:** https://forum.qiime2.org/t/calculating-diversity-from-relative-abundance/11428
**Category:** General Discussion
**Created:** [September 8, 2019, 7:41pm UTC](https://forum.qiime2.org/t/calculating-diversity-from-relative-abundance/11428 "2019-09-08T19:41:18Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![yipinto](https://forum.qiime2.org/user_avatar/forum.qiime2.org/yipinto/32/13406_2.png) [@yipinto](https://forum.qiime2.org/u/yipinto)
#### Post date: [September 8, 2019, 7:41pm UTC](https://forum.qiime2.org/t/calculating-diversity-from-relative-abundance/11428/1 "2019-09-08T19:41:18Z")

</div>

Hi,  
I'm analyzing shotgun metagenomics data and have read-based relative abundance table (by tools like kraken-braken, metaphlan2 etc). I was wondering if I can use qiime2 to calculate diversity based on relative-abundance table. It seems that some metrics can be calculated from relative abundance (observed OTU, shannon index, Jaccard distance).  
Do you know if it should work properly?  
Any other suggestions from community members on how to approach it?  
Thanks!

---

<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: [September 9, 2019, 6:33pm UTC](https://forum.qiime2.org/t/calculating-diversity-from-relative-abundance/11428/2 "2019-09-09T18:33:03Z")

</div>

Good afternoon,

Yes, this should work fine. The alpha diversity metrics like Shannon and beta diversity metrics like Jaccard will work on any feature-abundance table (regardless if it's relative abundance, and regardless if it's amplicon).

Some of the metrics are phylogenetic, namely Faith's PD and UniFrac. In this case, each feature will have to be placed somewhere on a phylogenetic tree, which is harder for shotgun metagenomics than amplicons, but not impossible.

Colin

---

<div class="post-metadata">

### Author: ![ebolyen](https://forum.qiime2.org/user_avatar/forum.qiime2.org/ebolyen/32/11_2.png) [@ebolyen](https://forum.qiime2.org/u/ebolyen)
#### Post date: [September 9, 2019, 10:09pm UTC](https://forum.qiime2.org/t/calculating-diversity-from-relative-abundance/11428/4 "2019-09-09T22:09:55Z")

</div>

One slight hiccup is the types are currently over-specific. So `qiime diversity alpha/beta` will want a `FeatureTable[Frequency]` since that is a "lowest common denominator" for all of the different measures/metrics.

@ChrisKeefe is currently working on cleaning this up by separating each into their own method so that we can have a more refined notion of the available types. In the meanwhile you would need to lie about the type which I don't strongly recommend, but a deadline is a deadline sometimes.

---

<div class="post-metadata">

### Author: ![shighlander](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/s/ccd318/32.png) [@shighlander](https://forum.qiime2.org/u/shighlander)
#### Post date: [October 21, 2019, 9:35pm UTC](https://forum.qiime2.org/t/calculating-diversity-from-relative-abundance/11428/5 "2019-10-21T21:35:25Z")

</div>

Have you made any progress on this? We have MetaPhlAn2 data that we would like to calculate alpha diversity.

Thanks, Sarah Highlander TGen North

---

<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 22, 2019, 2:32pm UTC](https://forum.qiime2.org/t/calculating-diversity-from-relative-abundance/11428/6 "2019-10-22T14:32:59Z")

</div>



---

<div class="post-metadata">

### Author: ![ChrisKeefe](https://forum.qiime2.org/user_avatar/forum.qiime2.org/chriskeefe/32/1907_2.png) [@ChrisKeefe](https://forum.qiime2.org/u/ChrisKeefe)
#### Post date: [October 22, 2019, 6:06pm UTC](https://forum.qiime2.org/t/calculating-diversity-from-relative-abundance/11428/7 "2019-10-22T18:06:18Z")

</div>



---

<div class="post-metadata">

### Author: ![ChrisKeefe](https://forum.qiime2.org/user_avatar/forum.qiime2.org/chriskeefe/32/1907_2.png) [@ChrisKeefe](https://forum.qiime2.org/u/ChrisKeefe)
#### Post date: [October 22, 2019, 6:06pm UTC](https://forum.qiime2.org/t/calculating-diversity-from-relative-abundance/11428/8 "2019-10-22T18:06:21Z")

</div>



---

<div class="post-metadata">

### Author: ![ChrisKeefe](https://forum.qiime2.org/user_avatar/forum.qiime2.org/chriskeefe/32/1907_2.png) [@ChrisKeefe](https://forum.qiime2.org/u/ChrisKeefe)
#### Post date: [October 22, 2019, 6:56pm UTC](https://forum.qiime2.org/t/calculating-diversity-from-relative-abundance/11428/9 "2019-10-22T18:56:08Z")

</div>

Hi @shighlander!  
[`q2-diversity-lib`](https://github.com/qiime2/q2-diversity-lib/) will not be officially released until January 2020, but even in its current form it should allow you to calculate common alpha diversity indices from relative frequency data. (FaithPD, Pielou's Evenness, Shannon's Entropy, and Observed Features)

The underlying algorithms are the same as those currently used in `q2-diversity`. `q2-diversity-lib` just provides a more robust system of semantic type constraints, slightly improved protections against user error, and method-by-method citations.

If you want to give it a shot, you should probably [create a fresh QIIME 2 environment](https://docs.qiime2.org/2019.7/install/native/) named `div-lib` or something like that. Once you've activated the conda environment you want to use, this should install the package for you:

```auto
pip install git+https://github.com/qiime2/q2-diversity-lib.git#egg=q2-diversity-lib

```

`qiime diversity-lib --help` will give you a list of available Actions, and `qiime diversity-lib [action-name] --help` will tell you how to use them.

Good luck, and please let me know if you run into any issues along the way!  
Chris

---

<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 22, 2019, 7:04pm UTC](https://forum.qiime2.org/t/calculating-diversity-from-relative-abundance/11428/10 "2019-10-22T19:04:00Z")

</div>



---

<div class="post-metadata">

### Author: ![shighlander](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/s/ccd318/32.png) [@shighlander](https://forum.qiime2.org/u/shighlander)
#### Post date: [October 22, 2019, 11:21pm UTC](https://forum.qiime2.org/t/calculating-diversity-from-relative-abundance/11428/11 "2019-10-22T23:21:06Z")

</div>

Thanks, I'll give it a try!

Sarah

---

<div class="post-metadata">

### Author: ![Francis29029](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/f/5f8ce5/32.png) [@Francis29029](https://forum.qiime2.org/u/Francis29029)
#### Post date: [April 16, 2020, 8:07am UTC](https://forum.qiime2.org/t/calculating-diversity-from-relative-abundance/11428/12 "2020-04-16T08:07:32Z")

</div>

Hello, I would like to perform the same calculations, would it be possible to share the commands you used with the q2-diversity plugin to calculate diversity from metaphlan frequency table ?  
Thanks a lot  
FRancis

---

<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: [April 20, 2020, 4:20pm UTC](https://forum.qiime2.org/t/calculating-diversity-from-relative-abundance/11428/13 "2020-04-20T16:20:12Z")

</div>



---

<div class="post-metadata">

### Author: ![ChrisKeefe](https://forum.qiime2.org/user_avatar/forum.qiime2.org/chriskeefe/32/1907_2.png) [@ChrisKeefe](https://forum.qiime2.org/u/ChrisKeefe)
#### Post date: [April 20, 2020, 7:08pm UTC](https://forum.qiime2.org/t/calculating-diversity-from-relative-abundance/11428/14 "2020-04-20T19:08:26Z")

</div>

Hi @Francis29029!  
`q2-diversity` does not currently allow the use of relative-frequency data in calculating alpha/beta diversity. Check out my response to shighlander above for instructions on downloading, installing, and getting command-specific help for `q2-diversity-lib`.

**Please note** : although I believe all of the tools available in the _in-development_ plugin mentioned above are sound, it _has not been officially released yet_. Please post to the forum and @mention me if you run into any unexpected issues.

Thanks,  
Chris

---

<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: [April 20, 2020, 7:23pm UTC](https://forum.qiime2.org/t/calculating-diversity-from-relative-abundance/11428/15 "2020-04-20T19:23:35Z")

</div>



---

<div class="post-metadata">

### Author: ![ChrisKeefe](https://forum.qiime2.org/user_avatar/forum.qiime2.org/chriskeefe/32/1907_2.png) [@ChrisKeefe](https://forum.qiime2.org/u/ChrisKeefe)
#### Post date: [August 28, 2020, 4:29pm UTC](https://forum.qiime2.org/t/calculating-diversity-from-relative-abundance/11428/16 "2020-08-28T16:29:21Z")

</div>

Just an FYI, @shighlander, @Francis29029 - it should now be possible to calculate `observed_features`, `jaccard`, and `shannon` from a `FeatureTable[RelativeFrequency]` using [`q2_diversity.alpha`](https://docs.qiime2.org/2020.8/plugins/available/diversity/alpha/).

---

<div class="post-metadata">

### Author: ![thermokarst](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/t/8e7dd6/32.png) [@thermokarst](https://forum.qiime2.org/u/thermokarst)
#### Post date: [August 28, 2020, 4:32pm UTC](https://forum.qiime2.org/t/calculating-diversity-from-relative-abundance/11428/17 "2020-08-28T16:32:10Z")

</div>


