New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Linkage 'Z' contains negative distances. #2804
Comments
This problem is caused by the inclusion of the floating point number 1 in the corr_matrix. Due to the limited precision of floating point numbers, 1 may be greater than 1 when converted to a binary floating point number and then converted to decimal. corr_matrix = mean_df.T.corr(method=cor_method)
corr_matrix = np.where(corr_matrix > 1, 1, corr_matrix ) to solve this problem |
@THZ34 can you create a reproducer where this happens, so I can add a test? |
OK, I've upload the h5ad file to onedrive: https://bioplot-my.sharepoint.com/:u:/g/personal/tanghongzhen_bioplot_onmicrosoft_com/EUbNHPuin5pGuMPrmch6rsQBjHojfikr38EYgZEL4KAZ2A?e=T2YfkO. |
OK, smallest reproducer I could come up with: import scipy.sparse as sp
import numpy as np
import pandas as pd
import scanpy as sc
rep_pca = np.frombuffer(
b'\xf0\x08\xc1?\xe6E+\xbe\xcaI6\xbf\xf3\xecT\xbeM"\xb6\xbe\xbb\xcee\xbe\x8e\xb1p\xbcU\x95\x8f\xbdn\x9f\x06\xbe\x00\xe9\x19\xbd\xd7s0\xbc\x0593\xbd9$/<U\xc6\x90:;;\\\xbd\x0c\xee\xa1\xbb,{7<\xab\xe8\x92\xbb[r\xd2\xbc\xb4\xaa\x0f\xbd\xddg\x01\xbd\x8a\xfe\xe8<\x00\xd3\x17\xbdE\xa4\xc3\xbc(4;\xbd\x015\xf5<\xe4\xb0\x1c<\xdaQ/\xbd\x92\xe0\xaf;\xc6\xad\xfc\xbc\xcd;?\xbcv\x93\xc0\xbcT\xc1\x969:\xb3\x8b\xbc\xf90\x93\xbc0x\xfd\xbc\xd8\xe02\xbc\x89\xb0\x83\xbcz\xa7+\xbc\x14\xa5_\xbc$ \xe0\xbbI\x9d@\xbc\x07\x9b>\xbd\xed\xf2\x9c<\xbf+b\xbc\x8d\xcc\x9b;\xb0\x84g\xbc\xc6c)\xbc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\xe0\xc5\x9a\xbc\xc6\xe7\xd1\xbc\xca\x1b\xfb\xbb1\x07a\xbd="k\xbcm\xe0\xc6<\x13\x07\xf7\xbc\x98#\n\xbd)2\x1c\xbdf*`\xbb,[\x8e\xbb_$*\xbdGF\xda\xbc\xcd\xb1\xe0\xbcg*r<\x85.C<\xa5e\x89\xbd\x81.);*\x94\x86\xbc\x18\x040\xbcFN\xf9\xbc\x81\xd6z\xbb\xdc\xbc\xf1\xbc\x1ba\xfe\xbc4\xaa\x0c\xbd E\x93\xbb\xc9\xde\xb0\xbc\xd1ZJ\xbc\xa6\xf6\xeb\xbc0\xdc\xef\xbbb\x96\xee\xbb\xbd\xda\x9b\xbd\xa9\t\xc5<\x0c\xeeE\xbc%\xce\xa5;\xf7\x97\xcf\xbc\xc3,\x96\xbc\xb2}\x94\xbc0\x9e[\xbb',
dtype=np.float32,
).reshape((7, 50))
rep = sc.AnnData(
sp.csr_matrix(
(
np.array([1.2762934659055623, 1.6916760106710726, 1.6916760106710726]),
np.array([12, 5, 44]),
np.array([0, 0, 0, 0, 0, 1, 2, 3]),
),
shape=(7, 51),
),
dict(leiden=pd.Categorical(["372", "366", "357", "357", "357", "357", "357"])),
obsm=dict(X_pca=np.array(rep_pca, dtype=np.float32)),
)
sc.tl.dendrogram(rep, groupby="leiden") |
Please make sure these conditions are met
What happened?
I'm encountering an error when running the sc.pl.rank_genes_groups_heatmap function in the scanpy package. The error message is "Linkage 'Z' contains negative distances." What could be causing this error and how can I fix it?
Minimal code sample
Error output
Versions
The text was updated successfully, but these errors were encountered: