Skip to content

Commit

Permalink
Merge pull request #296 from lilab-bcb/yiming
Browse files Browse the repository at this point in the history
Enforce dissimilarity matrix with main diagonal 0s
  • Loading branch information
yihming committed May 14, 2024
2 parents 77629e2 + 1f1ba67 commit dafa4c5
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pegasus/tools/clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,8 @@ def calc_dendrogram(
linkage_method: ``str``, optional, default: ``ward``
Which linkage criterion to use, used by hierarchical clustering. Available options: ``ward`` (default), ``single``, ``complete``, ``average``, ``weighted``, ``centroid``, ``median``.
See `scipy linkage documentation`_ for details.
res_key: ``str``, optional, default: ``dendrogram``
Key name in ``data.uns`` field to store the calculated dendrogram information, which will be used by ``plot_dendrogram`` function for plotting.
Returns
-------
Expand Down Expand Up @@ -820,6 +822,7 @@ def calc_dendrogram(
from scipy.spatial.distance import squareform

dissim_df = 1 - csi_df
np.fill_diagonal(dissim_df.to_numpy(), 0) # Enforce main diagonal to be 0 to pass squareform requirement
Z = linkage(squareform(dissim_df), method=linkage_method, optimal_ordering=True)

data.uns[res_key] = (Z, dissim_df.index.values.astype(str))

0 comments on commit dafa4c5

Please sign in to comment.