# Collapsing feature table to a specific taxonomic rank before diversity analysis?

**URL:** <https://forum.qiime2.org/t/collapsing-feature-table-to-a-specific-taxonomic-rank-before-diversity-analysis/21806>\
**Category:** Library Support\
**Tags:** diversity, alpha, beta, taxonomy\
**Created:** [January 6, 2022, 5:43pm UTC](https://forum.qiime2.org/t/collapsing-feature-table-to-a-specific-taxonomic-rank-before-diversity-analysis/21806 "2022-01-06T17:43:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![pippo\_pippo](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/p/13edae/32.png) [@pippo\_pippo](https://forum.qiime2.org/u/pippo_pippo)\
**Post date:** [January 6, 2022, 5:43pm UTC](https://forum.qiime2.org/t/collapsing-feature-table-to-a-specific-taxonomic-rank-before-diversity-analysis/21806/1 "2022-01-06T17:43:48Z")

</div>

Hi there!

I have a feature tabel from shotgun metagenomic sequencing which I produced with MetaPhlAn3. From there on, I use QIIME to calculate alpha diversity metrics.

I am wondering if I should collapse my feature table to the species rank before doing alpha diversity or if I should use the complete table. Because of how MetaPhlAn works, I do not always have information of every microbe down to the species level (e. g. sometimes down to genus level, sometimes family level etc.).

This gives me some uncertainty:

The full table has significantly more "entries" than the reduced table (because a taxonomic tree is provided which shows every tax rank until the assigned rank of the microbe, see screenshot)

 ![Screenshot from 2022-01-06 18-21-55](https://forum-qiime2-org.s3.dualstack.us-west-2.amazonaws.com/original/2X/0/03c8b48f720dd6601d410178467d597033a33b20.png)

What I am concerned about using the full table is: If I have a sample with 1 species, then I have 7 entries (Kingdom, phylum, class, order, family, genus, species). When there are 2 species, there are 14 entries. But when a microbe was not classified down to the species level, there will be less than 7 entries for the microbe. Also, if 2 species belong to the same genus, the whole taxonomic tree until that genus is only given once. This results in a non-constant number of entries across samples.

On the other hand though, I am missing out information when collapsing to one taxonomic rank. The devlopers of MetaPhlAn also have a tool for differential abundance testing, where they recommend collapsing the feature table.

Do you have any advice about that?

Thanks a lot!!  
Philipp

---

<div class="post-metadata">

**Author:** ![pippo\_pippo](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/p/13edae/32.png) [@pippo\_pippo](https://forum.qiime2.org/u/pippo_pippo)\
**Post date:** [January 10, 2022, 6:41am UTC](https://forum.qiime2.org/t/collapsing-feature-table-to-a-specific-taxonomic-rank-before-diversity-analysis/21806/2 "2022-01-10T06:41:27Z")

</div>

Does anyone have an idea?

---

<div class="post-metadata">

**Author:** ![timanix](https://forum.qiime2.org/user_avatar/forum.qiime2.org/timanix/32/17879_2.png) [@timanix](https://forum.qiime2.org/u/timanix)\
**Post date:** [January 10, 2022, 10:28am UTC](https://forum.qiime2.org/t/collapsing-feature-table-to-a-specific-taxonomic-rank-before-diversity-analysis/21806/3 "2022-01-10T10:28:36Z")

</div>

Hi Philipp,  
As well as I know, in the Metaphlan3 output you will get microbes with the relative abundances (unless you specified otherwise) and this table is already collapsed to the species level. So, the closest option to the ASV or OTU tables will be filtering the tables to contain only species, since (not sure!!!) genus and other annotation levels represent relative abundances of all species, included into this genus or taxa level.

---

<div class="post-metadata">

**Author:** ![pippo\_pippo](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/p/13edae/32.png) [@pippo\_pippo](https://forum.qiime2.org/u/pippo_pippo)\
**Post date:** [January 10, 2022, 11:18am UTC](https://forum.qiime2.org/t/collapsing-feature-table-to-a-specific-taxonomic-rank-before-diversity-analysis/21806/4 "2022-01-10T11:18:34Z")

</div>

Hey Timur,

thanks for your answer!  
your are right, Metaphlan only provides relative abundances. From there you can compute some alpha metrics like observed\_features or shannon\_entropy.  
What I am wondering about is if you should calculate diversity metrics on the full feature table (providing all taxonomic ranks from kingdom to species) or if I should collapse the table to one rank (e. g. species) beforehand.

I would guess that in 16S surveys, there are also sequences that can be assigned only to the phylum level, whereas other sequences can be assigned to genus or species level. Would you collapse that table to e defined taxonomic rank before calculating statistics or would you go with all taxonomic ranks to avoid missing out information?

---

<div class="post-metadata">

**Author:** ![timanix](https://forum.qiime2.org/user_avatar/forum.qiime2.org/timanix/32/17879_2.png) [@timanix](https://forum.qiime2.org/u/timanix)\
**Post date:** [January 10, 2022, 12:37pm UTC](https://forum.qiime2.org/t/collapsing-feature-table-to-a-specific-taxonomic-rank-before-diversity-analysis/21806/5 "2022-01-10T12:37:21Z")

</div>

> [@pippo\_pippo](#):
>
> your are right, Metaphlan only provides relative abundances.

You also can use option `-t rel_ab_w_read_stats` to obtain "absolute" abundances instead of relative ones for each sample and then merge it to one table using modified script that I provided [here](https://forum.biobakery.org/t/merge-metaphlan-tables-py-with-absolute-abundance/1839?u=timyerg).

> [@pippo\_pippo](#):
>
> What I am wondering about is if you should calculate diversity metrics on the full feature table (providing all taxonomic ranks from kingdom to species)

Here I would recommend to filter your table to only include species level annotations and probably unclassified sequences, since genus level annotations in that table include all sequences, assigned to genus level (including sequenced assigned to species).

> [@pippo\_pippo](#):
>
> Would you collapse that table to e defined taxonomic rank before calculating statistics or would you go with all taxonomic ranks to avoid missing out information?

In case with Metaphlane3, I would filter my table to only contain annotations at the desired level (collapse) plus probably keep unassigned queries.

---

<div class="post-metadata">

**Author:** ![system](https://forum-qiime2-org.s3.dualstack.us-west-2.amazonaws.com/original/3X/2/1/21af5fe23cb6f4579467c66a9ed94e55274ca7bd.svg) [@system](https://forum.qiime2.org/u/system)\
**Post date:** [February 10, 2022, 6:37pm UTC](https://forum.qiime2.org/t/collapsing-feature-table-to-a-specific-taxonomic-rank-before-diversity-analysis/21806/6 "2022-02-10T18:37:51Z")

</div>

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