# Humann2:"The condensed distance matrix must contain only finite values" when barplotting

**URL:** <https://forum.biobakery.org/t/humann2-the-condensed-distance-matrix-must-contain-only-finite-values-when-barplotting/3445>\
**Category:** HUMAnN\
**Created:** [April 12, 2022, 11:44am UTC](https://forum.biobakery.org/t/humann2-the-condensed-distance-matrix-must-contain-only-finite-values-when-barplotting/3445 "2022-04-12T11:44:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![PatrickSchimmel](https://avatars.discourse-cdn.com/v4/letter/p/f9ae1b/32.png) [@PatrickSchimmel](https://forum.biobakery.org/u/PatrickSchimmel)\
**Post date:** [April 12, 2022, 11:44am UTC](https://forum.biobakery.org/t/humann2-the-condensed-distance-matrix-must-contain-only-finite-values-when-barplotting/3445/1 "2022-04-12T11:44:02Z")

</div>

Hi all,  
Thanks in advance for the help.  
I’ve been working quite a long time with HumanN2 on a metagenomics dataset and never had this error before, no i see it for several gene familie abundances. I have merged the samples, normalized them to cpm, regrouped and renamed them according to Kegg Orthology, hence the filename example

humann2\_barplot -i “/120422\_datasetx\_genefamilies\_merged\_norm\_KO\_REGROUP\_KO\_RENAME\_meta.tsv” -s similarity metadata -f K01428 -m TIMEANDFEEDING -o GraphX -g -r -w 1

gives the following:  
"Regrouping to genera (before selecting/sorting strata)  
Traceback (most recent call last):  
File “/tools/software/bioinfo-tools/miniconda/miniconda3/envs/Humann2/bin/humann2\_barplot”, line 11, in   
sys.exit(main())  
File “/tools/software/bioinfo-tools/miniconda/miniconda3/envs/Humann2/lib/python2.7/site-packages/humann2/tools/humann2\_barplot.py”, line 349, in main  
table.sort( method )  
File “/tools/software/bioinfo-tools/miniconda/miniconda3/envs/Humann2/lib/python2.7/site-packages/humann2/tools/humann2\_barplot.py”, line 256, in sort  
order = sch.leaves\_list( sch.linkage( norm.transpose(), metric=“braycurtis” ) )  
File “/tools/software/bioinfo-tools/miniconda/miniconda3/envs/Humann2/lib/python2.7/site-packages/scipy/cluster/hierarchy.py”, line 1109, in linkage  
raise ValueError(“The condensed distance matrix must contain only "  
ValueError: The condensed distance matrix must contain only finite values.”

I have been plotting genes out of this dataset regularly, only today I noticed this one, and tried some more genes. occurs sometimes.  
Any ideas what could be causing it, is the data formatting? Did an infinite value sneak in some where?  
Thanks alot!  
Best,  
Patrick

---

<div class="post-metadata">

**Author:** ![franzosa](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/franzosa/32/3511_2.png) [@franzosa](https://forum.biobakery.org/u/franzosa)\
**Post date:** [June 29, 2022, 8:51pm UTC](https://forum.biobakery.org/t/humann2-the-condensed-distance-matrix-must-contain-only-finite-values-when-barplotting/3445/2 "2022-06-29T20:51:29Z")

</div>

I believe this is either an error from trying to compute a distance on an empty vector OR it may have to do with a change in how scipy handled 0 distances between versions. If you try the updated humann\_barplot bundled with the current (v3) version of the software it should be more robust to these issues. The new barplot can still be used with data generated from HUMAnN 2.

---

<div class="post-metadata">

**Author:** ![MEGAN-obsidian](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/megan-obsidian/32/3374_2.png) [@MEGAN-obsidian](https://forum.biobakery.org/u/MEGAN-obsidian)\
**Post date:** [August 19, 2025, 2:12am UTC](https://forum.biobakery.org/t/humann2-the-condensed-distance-matrix-must-contain-only-finite-values-when-barplotting/3445/3 "2025-08-19T02:12:26Z")

</div>

I fixed it. You’d better make sure all your data had been transfered from float to integer
