# Hclust2.py error distance matrix finite values

**URL:** <https://forum.biobakery.org/t/hclust2-py-error-distance-matrix-finite-values/1732>\
**Category:** MetaPhlAn\
**Created:** [March 1, 2021, 9:45am UTC](https://forum.biobakery.org/t/hclust2-py-error-distance-matrix-finite-values/1732 "2021-03-01T09:45:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![saras22](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@saras22](https://forum.biobakery.org/u/saras22)\
**Post date:** [March 1, 2021, 9:45am UTC](https://forum.biobakery.org/t/hclust2-py-error-distance-matrix-finite-values/1732/1 "2021-03-01T09:45:20Z")

</div>

Hi  
I was trying to create heatmap using command:  
hclust2.py -i merged\_abundance\_table\_species.txt -o abundance\_heatmap\_species.png --f\_dist\_f braycurtis --s\_dist\_f braycurtis --cell\_aspect\_ratio 0.5 -l --flabel\_size 10 --max\_flabel\_len 100 --max\_slabel\_len 100 --minv 0.1 --dpi 300 --ftop 25

But I get this Error:  
Traceback (most recent call last):  
File “/home/rakesh/anaconda3/bin/hclust2.py”, line 825, in   
hclust2\_main()  
File “/home/rakesh/anaconda3/bin/hclust2.py”, line 803, in hclust2\_main  
cl.shcluster()  
File “/home/rakesh/anaconda3/bin/hclust2.py”, line 380, in shcluster  
self.shclusters = sph.linkage(self.s\_dm, method=self.args.slinkage)  
File “/home/rakesh/anaconda3/lib/python3.8/site-packages/scipy/cluster/hierarchy.py”, line 1057, in linkage  
raise ValueError("The condensed distance matrix must contain only "  
ValueError: The condensed distance matrix must contain only finite value.

Kindly explain how would I resolve this error. I saw a similar issue they said it is due the rows with zero abundance but how should I remove those values?

Thank You  
Saraswati Awasthi

---

<div class="post-metadata">

**Author:** ![EricDeveaud](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/ericdeveaud/32/912_2.png) [@EricDeveaud](https://forum.biobakery.org/u/EricDeveaud)\
**Post date:** [September 12, 2022, 8:13am UTC](https://forum.biobakery.org/t/hclust2-py-error-distance-matrix-finite-values/1732/2 "2022-09-12T08:13:55Z")

</div>

Hello I have the same problem since long time…  
see: [hclust2-1.0.0 :: test failure · Issue #5 · SegataLab/hclust2 · GitHub](https://github.com/SegataLab/hclust2/issues/5)(among others)

after digging in the data I notidced that `HClustering.s_dm` may contains some `NAN` values.  
I did not digg the code in order where theses `NAN` values comes from.

a workaround that I would like you to investigate // validate is to filter the `NAN` values in the init method `HClustering` class from

```auto
def __init__ ( self, s_dm, f_dm, args = None ):
        self.s_dm=s_dm
        self.f_dm=f_dm
        self.args = args
        self.sclusters = None
        self.fclusters = None
        self.sdendrogram = None
        self.fdendrogram = None

```

to

```auto
def __init__ ( self, s_dm, f_dm, args = None ):
        self.s_dm=[0.0 if np.isnan(x) else x for x in s_dm]
        self.f_dm=[0.0 if np.isnan(x) else x for x in f_dm]
        self.args = args
        self.sclusters = None
        self.fclusters = None
        self.sdendrogram = None
        self.fdendrogram = None

```

as I’m not abble to evaluate the changes it may introduce in the results pertinenece I would like you to review the potential impact of this change.

NB after patcheing `hclust2.py` with the above changes I am abble to generate the heatmap from `HMP.species.txt` example file.

best regards

Eric

PS `matplotlib.cbook.iterable` is deprected since matplotlib 3.1 should use `np.iterable` instead.

regards

Eric
