# Total Bacteria species relative abundance no longer sums to 1 after converting the SGB profile to GTDB

**URL:** <https://forum.biobakery.org/t/total-bacteria-species-relative-abundance-no-longer-sums-to-1-after-converting-the-sgb-profile-to-gtdb/4913>\
**Category:** MetaPhlAn\
**Created:** [March 3, 2023, 9:32pm UTC](https://forum.biobakery.org/t/total-bacteria-species-relative-abundance-no-longer-sums-to-1-after-converting-the-sgb-profile-to-gtdb/4913 "2023-03-03T21:32:12Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fangxi\_Xu](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/fangxi_xu/32/824_2.png) [@Fangxi\_Xu](https://forum.biobakery.org/u/Fangxi_Xu)\
**Post date:** [March 3, 2023, 9:32pm UTC](https://forum.biobakery.org/t/total-bacteria-species-relative-abundance-no-longer-sums-to-1-after-converting-the-sgb-profile-to-gtdb/4913/1 "2023-03-03T21:32:12Z")

</div>

Hi,  
I used **MetaPhlAn version 4.0.4 (17 Jan 2023)** to perform taxonomy profiling on our shotgun metagenomic samples and after getting the metaphlan profiles (SGB level), I used the **sgb\_to\_gtdb\_profile.py** command to convert the SGB profiles to GTDB profiles.  
However, after converting, the total bacteria relative abundance of some samples became no longer 100% . Some became down to ~ 98.5 - 99% and some became up to 100.0001%.  
I wonder why the relative abundances of species changed after re-annotating the taxa?  
Can you please suggest some solutions to proceed with?  
Can we renormalize the GTDB profiles to sum to 100%?

Thank you so much.

Best,  
Fangxi

---

<div class="post-metadata">

**Author:** ![aitor.blancomiguez](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/aitor.blancomiguez/32/86_2.png) [@aitor.blancomiguez](https://forum.biobakery.org/u/aitor.blancomiguez)\
**Post date:** [March 6, 2023, 8:48am UTC](https://forum.biobakery.org/t/total-bacteria-species-relative-abundance-no-longer-sums-to-1-after-converting-the-sgb-profile-to-gtdb/4913/2 "2023-03-06T08:48:52Z")

</div>

Hi @Fangxi_Xu  
Could you share with as an example profile (both the metaphlan default output and the gtdb converted) to have a better look into the problem?

---

<div class="post-metadata">

**Author:** ![Fangxi\_Xu](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/fangxi_xu/32/824_2.png) [@Fangxi\_Xu](https://forum.biobakery.org/u/Fangxi_Xu)\
**Post date:** [March 6, 2023, 4:51pm UTC](https://forum.biobakery.org/t/total-bacteria-species-relative-abundance-no-longer-sums-to-1-after-converting-the-sgb-profile-to-gtdb/4913/3 "2023-03-06T16:51:35Z")

</div>

Hi @aitor.blancomiguez ,  
Thank you for your prompt response. Please find 2 MetaPhlAn SGB profiles and 2 converted GTDB profiles attached.  
The sample S16 had total bacteria relative abundance 100% in the SGB profile and 100.00002% in the GTDB profile; while sample S43 had total bacteria relative abundance 100% and 97.77355000000001% in the GTDB profile.  
These are oral samples from mice. Please let me know if more information is needed.  
Thank you so much for your help.

Best,  
Fangxi

[gtdb\_profile\_S16.txt](https://forum.biobakery.org/uploads/short-url/9jEJaUXsFfCyyuzfMQWFBLqW2of.txt) (3.6 KB)  
[gtdb\_profile\_S43.txt](https://forum.biobakery.org/uploads/short-url/qWBrdLZKNKh0wxK4iY0VKcntcyV.txt) (27.0 KB)  
[metaphlan\_profile\_S16.txt](https://forum.biobakery.org/uploads/short-url/tvpUr0sensZ2xuklP09F1TlBWKx.txt) (7.7 KB)  
[metaphlan\_profile\_S43.txt](https://forum.biobakery.org/uploads/short-url/1ApsZbrWwDLDxa6cMqd0tNNrOEW.txt) (68.6 KB)

---

<div class="post-metadata">

**Author:** ![aitor.blancomiguez](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/aitor.blancomiguez/32/86_2.png) [@aitor.blancomiguez](https://forum.biobakery.org/u/aitor.blancomiguez)\
**Post date:** [March 13, 2023, 9:28am UTC](https://forum.biobakery.org/t/total-bacteria-species-relative-abundance-no-longer-sums-to-1-after-converting-the-sgb-profile-to-gtdb/4913/4 "2023-03-13T09:28:25Z")

</div>

Hi @Fangxi_Xu  
I had a look at the problem and it seems it is due to some decimal rounding step when reporting the original metaphlan results. As the abundances of higher taxonomic levels are sum up from the species level (up to 5 decimals), the rounding error seems to be increasing. Renormalizing the abundances to 100% in each tax level would solve the issue. I included the re-normalization step in the script uploaded to the github repo ([MetaPhlAn/sgb\_to\_gtdb\_profile.py at master · biobakery/MetaPhlAn · GitHub](https://github.com/biobakery/MetaPhlAn/blob/master/metaphlan/utils/sgb_to_gtdb_profile.py)). I will include it in the next metaphlan release but if you download it you can use it as:  
`$ python path_to_the_script/sgb_to_gtdb_profile.py -i .....`

---

<div class="post-metadata">

**Author:** ![Fangxi\_Xu](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/fangxi_xu/32/824_2.png) [@Fangxi\_Xu](https://forum.biobakery.org/u/Fangxi_Xu)\
**Post date:** [March 22, 2023, 4:17pm UTC](https://forum.biobakery.org/t/total-bacteria-species-relative-abundance-no-longer-sums-to-1-after-converting-the-sgb-profile-to-gtdb/4913/5 "2023-03-22T16:17:56Z")

</div>

Hi @aitor.blancomiguez ,  
Thank you for your reply; however, I think it’s not just a decimal rounding issue here.  
Can you please provide some details of how the conversion was performed? Was that done by exact mapping from NCBI annotation to GTDB?  
We noticed that the number of species in these profiles are not matched.  
Can you please look into it?  
Thanks.

Best,  
Fangxi

---

<div class="post-metadata">

**Author:** ![Scott](https://avatars.discourse-cdn.com/v4/letter/s/3e96dc/32.png) [@Scott](https://forum.biobakery.org/u/Scott)\
**Post date:** [March 22, 2023, 4:32pm UTC](https://forum.biobakery.org/t/total-bacteria-species-relative-abundance-no-longer-sums-to-1-after-converting-the-sgb-profile-to-gtdb/4913/6 "2023-03-22T16:32:35Z")

</div>

To add to this, we noticed that the missing relative abundance % in the GTDB assignment is the relative abundance % sum of those taxa found only in the MetaPhlAn assignment minus the relative abundance % sum of those taxa found only in the GTDB assignment. We identified this by matching the relative abundance numbers between the two files and noting where there were discrepancies.

---

<div class="post-metadata">

**Author:** ![aitor.blancomiguez](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/aitor.blancomiguez/32/86_2.png) [@aitor.blancomiguez](https://forum.biobakery.org/u/aitor.blancomiguez)\
**Post date:** [March 23, 2023, 9:24am UTC](https://forum.biobakery.org/t/total-bacteria-species-relative-abundance-no-longer-sums-to-1-after-converting-the-sgb-profile-to-gtdb/4913/7 "2023-03-23T09:24:01Z")

</div>

Hi @Fangxi_Xu and Scott  
For each bacterial and archaeal SGB in the mpa4 database, we got the assignment to the GTDB database using the GTDB-Tk tool. For some SGBs, there is not correspondance in the GTDB database, so the assignment sometimes does not reach the species level.  
`E.g. SGB105011	d __Archaea;p__ Thermoplasmatota;c __Thermoplasmata;o__ ARK-15;f __ARK-15;g__ ARK-15;s__`  
in those cases, abundances of SGBs assigned to the same genus (e.g. ARK-15) but to an unknown species (s\_\_) are sumup as the same taxa. This will happen also for the SGBs that even assigned at the species level, they are assigned to the same GTDB species.  
E.g.

```auto
SGB74984|d __Archaea;p__ Methanobacteriota_B;c __Thermococci;o__ Thermococcales;f __Thermococcaceae;g__ Thermococcus;s__Thermococcus sp012027395
SGB74985|d __Archaea;p__ Methanobacteriota_B;c __Thermococci;o__ Thermococcales;f __Thermococcaceae;g__ Thermococcus;s__Thermococcus sp012027595

```

In the case of eukaryotes, as they are not present in the GTDB database, they are not accounted in the final GTDB profile

---

<div class="post-metadata">

**Author:** ![Scott](https://avatars.discourse-cdn.com/v4/letter/s/3e96dc/32.png) [@Scott](https://forum.biobakery.org/u/Scott)\
**Post date:** [March 23, 2023, 4:34pm UTC](https://forum.biobakery.org/t/total-bacteria-species-relative-abundance-no-longer-sums-to-1-after-converting-the-sgb-profile-to-gtdb/4913/8 "2023-03-23T16:34:50Z")

</div>

Thanks for the clarifications on the mapping and GTDB assignment of SGBs.  
I still don’t understand how we can be missing ~2.22647% relative abundance in the GTDB assignment, though.  
For example, in S43 provided above, k\_\_Bacteria|p\_\_Firmicutes|c\_\_Clostridia|o\_\_Clostridia\_unclassified|f\_\_Clostridia\_unclassified|g\_\_GGB31835|s\_\_GGB31835\_SGB45211 is an abundant SGB in the dataset (~2%) from the MetaPhlan analysis. Although unclassified at the order level, the abundance does not appear to be included elsewhere in the GTDB analysis.

We do not have any Eukaryotes in the analysis, so this does not cause the loss of relative abundance values when going from MetaPhlAn to GTDB.

---

<div class="post-metadata">

**Author:** ![aitor.blancomiguez](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/aitor.blancomiguez/32/86_2.png) [@aitor.blancomiguez](https://forum.biobakery.org/u/aitor.blancomiguez)\
**Post date:** [March 30, 2023, 12:22pm UTC](https://forum.biobakery.org/t/total-bacteria-species-relative-abundance-no-longer-sums-to-1-after-converting-the-sgb-profile-to-gtdb/4913/9 "2023-03-30T12:22:07Z")

</div>

I keep tracing the problem and I think I discover the root of it in line `73` of the code. So when two SGBs were assigned to the same GTDB taxonomy, instead of summing up the abundances, only the abundance of the last SGB in the profile was used. I pushed a fix of the code in the repo: [MetaPhlAn/sgb\_to\_gtdb\_profile.py at master · biobakery/MetaPhlAn · GitHub](https://github.com/biobakery/MetaPhlAn/blob/master/metaphlan/utils/sgb_to_gtdb_profile.py)  
Please, let me know if something is still working wrongly

---

<div class="post-metadata">

**Author:** ![Fangxi\_Xu](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/fangxi_xu/32/824_2.png) [@Fangxi\_Xu](https://forum.biobakery.org/u/Fangxi_Xu)\
**Post date:** [March 31, 2023, 7:30pm UTC](https://forum.biobakery.org/t/total-bacteria-species-relative-abundance-no-longer-sums-to-1-after-converting-the-sgb-profile-to-gtdb/4913/10 "2023-03-31T19:30:59Z")

</div>

Hi @aitor.blancomiguez ,  
Thank you so much for the fixed script. I ran it by removing the last few lines for renormalization and the converted GTDB profiles look good now.

The sums are now very close to 100% and the minor differences are less than ~0.0001% across all our samples.

Will this command be fixed in the next release of MetaPhlAn?

Thank you again for all of your help.

Best,  
Fangxi

---

<div class="post-metadata">

**Author:** ![aitor.blancomiguez](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/aitor.blancomiguez/32/86_2.png) [@aitor.blancomiguez](https://forum.biobakery.org/u/aitor.blancomiguez)\
**Post date:** [April 5, 2023, 2:16pm UTC](https://forum.biobakery.org/t/total-bacteria-species-relative-abundance-no-longer-sums-to-1-after-converting-the-sgb-profile-to-gtdb/4913/11 "2023-04-05T14:16:56Z")

</div>

Hi @Fangxi_Xu  
Yes, it will be included in the next version!

---

<div class="post-metadata">

**Author:** ![Fangxi\_Xu](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/fangxi_xu/32/824_2.png) [@Fangxi\_Xu](https://forum.biobakery.org/u/Fangxi_Xu)\
**Post date:** [April 6, 2023, 2:21pm UTC](https://forum.biobakery.org/t/total-bacteria-species-relative-abundance-no-longer-sums-to-1-after-converting-the-sgb-profile-to-gtdb/4913/12 "2023-04-06T14:21:50Z")

</div>

Great! Looking forward to it. Thanks for all the hard work.

---

<div class="post-metadata">

**Author:** ![aegreen32](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/aegreen32/32/3622_2.png) [@aegreen32](https://forum.biobakery.org/u/aegreen32)\
**Post date:** [April 15, 2026, 4:59pm UTC](https://forum.biobakery.org/t/total-bacteria-species-relative-abundance-no-longer-sums-to-1-after-converting-the-sgb-profile-to-gtdb/4913/13 "2026-04-15T16:59:51Z")

</div>

Hi @Fangxi_Xu !

Exactly what did you do to the updated script? I am having the same issue with my relative abundances no longer summing to 100 after using the conversion script even though I’m using the updated (Oct 2025) script.

I appreciate any guidance you can give me to help replicate what you did. I also understand if you don’t fully remember at this point.

Thanks!

Abbi

---

<div class="post-metadata">

**Author:** ![aegreen32](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/aegreen32/32/3622_2.png) [@aegreen32](https://forum.biobakery.org/u/aegreen32)\
**Post date:** [April 24, 2026, 4:05pm UTC](https://forum.biobakery.org/t/total-bacteria-species-relative-abundance-no-longer-sums-to-1-after-converting-the-sgb-profile-to-gtdb/4913/14 "2026-04-24T16:05:26Z")

</div>

Just wanted to chime back in on here to try to bring more attention back to my question. Even with all the newest versions of the script, software, and databased, things are still not summing up to 1 like it should be. Any help I can get to fix this issue would be much appreciated!

---

<div class="post-metadata">

**Author:** ![Claudia\_Mengoni](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/claudia_mengoni/32/2871_2.png) [@Claudia\_Mengoni](https://forum.biobakery.org/u/Claudia_Mengoni)\
**Post date:** [April 24, 2026, 4:45pm UTC](https://forum.biobakery.org/t/total-bacteria-species-relative-abundance-no-longer-sums-to-1-after-converting-the-sgb-profile-to-gtdb/4913/15 "2026-04-24T16:45:01Z")

</div>

Hi @aegreen32

Can you please upload the metaphlan profile and the converted file so I can take a look?

---

<div class="post-metadata">

**Author:** ![aegreen32](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/aegreen32/32/3622_2.png) [@aegreen32](https://forum.biobakery.org/u/aegreen32)\
**Post date:** [April 24, 2026, 5:16pm UTC](https://forum.biobakery.org/t/total-bacteria-species-relative-abundance-no-longer-sums-to-1-after-converting-the-sgb-profile-to-gtdb/4913/16 "2026-04-24T17:16:54Z")

</div>

Of course! See attached.

[profiled\_metagenome\_beforeConv.txt](https://forum.biobakery.org/uploads/short-url/uJaKLbPFFqiEezo8vo7rVriyE1w.txt) (172.6 KB)

[gtdb\_profile.txt](https://forum.biobakery.org/uploads/short-url/1m98lHX5xdb7xXNEmQ7RJjwOIbF.txt) (64.0 KB)

---

<div class="post-metadata">

**Author:** ![aegreen32](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/aegreen32/32/3622_2.png) [@aegreen32](https://forum.biobakery.org/u/aegreen32)\
**Post date:** [May 6, 2026, 2:41pm UTC](https://forum.biobakery.org/t/total-bacteria-species-relative-abundance-no-longer-sums-to-1-after-converting-the-sgb-profile-to-gtdb/4913/17 "2026-05-06T14:41:07Z")

</div>

Hello! I just realized I didn’t directly reply to your message. Did you see the files I sent? Thanks!

---

<div class="post-metadata">

**Author:** ![Claudia\_Mengoni](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/claudia_mengoni/32/2871_2.png) [@Claudia\_Mengoni](https://forum.biobakery.org/u/Claudia_Mengoni)\
**Post date:** [May 22, 2026, 10:11am UTC](https://forum.biobakery.org/t/total-bacteria-species-relative-abundance-no-longer-sums-to-1-after-converting-the-sgb-profile-to-gtdb/4913/18 "2026-05-22T10:11:01Z")

</div>

Sorry it took me so long to have a look at this. I modified the script, you can download the updated version in github. It handles taxonomy names more carefully now so that when the names are written in slightly different ways it can still retrieve the correct parent. Let me know if you still see any issue.

---

<div class="post-metadata">

**Author:** ![aegreen32](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/aegreen32/32/3622_2.png) [@aegreen32](https://forum.biobakery.org/u/aegreen32)\
**Post date:** [May 24, 2026, 9:50pm UTC](https://forum.biobakery.org/t/total-bacteria-species-relative-abundance-no-longer-sums-to-1-after-converting-the-sgb-profile-to-gtdb/4913/19 "2026-05-24T21:50:31Z")

</div>

No worries! Everything seems to be adding up properly now. Thank you so much for your help!
