diff --git a/src/aniclustermap/cluster.py b/src/aniclustermap/cluster.py index 3c2e401..fede665 100644 --- a/src/aniclustermap/cluster.py +++ b/src/aniclustermap/cluster.py @@ -8,6 +8,7 @@ import seaborn as sns from matplotlib.colors import BoundaryNorm from matplotlib.colors import LinearSegmentedColormap as LSC +from scipy.spatial.distance import squareform from seaborn.matrix import ClusterGrid @@ -59,7 +60,7 @@ def clustermap( ani_matrix_df = pd.read_csv(ani_matrix_df, sep="\t", encoding="utf-8") if linkage is None: - linkage = hc.linkage(ani_matrix_df, method="average") + linkage = hc.linkage(squareform(100 - ani_matrix_df), method="average") if cmap_colors is None: cmap_colors = ["lime", "yellow", "red"] diff --git a/src/aniclustermap/scripts/aniclustermap.py b/src/aniclustermap/scripts/aniclustermap.py index b751f07..10c80b5 100644 --- a/src/aniclustermap/scripts/aniclustermap.py +++ b/src/aniclustermap/scripts/aniclustermap.py @@ -9,6 +9,7 @@ import pandas as pd import scipy.cluster.hierarchy as hc import typer +from scipy.spatial.distance import squareform from typer import Option, Typer from aniclustermap import __version__, const @@ -172,7 +173,7 @@ def cli( # Hierarchical clustering ANI matrix logger.info(f"Clustering {mode.value} ANI matrix by scipy UPGMA method") - linkage = hc.linkage(ani_matrix_df, method="average") + linkage = hc.linkage(squareform(100 - ani_matrix_df), method="average") dendrogram_newick_file = outdir / "ANIclustermap_dendrogram.nwk" to_newick_tree(ani_matrix_df, linkage, dendrogram_newick_file) logger.info("Write newick format cluster dendrogram")