Skip to content
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

fixes dendrogram issue #1228 #1614

Merged
merged 9 commits into from Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions scanpy/plotting/_anndata.py
Expand Up @@ -1007,6 +1007,7 @@ def heatmap(
# if colors are not found, assign a new palette
# and save it using the same code for embeddings
from ._tools.scatterplots import _get_palette

_get_palette(adata, groupby)
groupby_colors = adata.uns[groupby + "_colors"]
else:
Expand Down Expand Up @@ -1212,7 +1213,7 @@ def heatmap(

kwds.setdefault('interpolation', 'nearest')
im = heatmap_ax.imshow(obs_tidy.T.values, aspect='auto', **kwds)
heatmap_ax.set_xlim(0 - 0.5, obs_tidy.shape[0] -0.5)
heatmap_ax.set_xlim(0 - 0.5, obs_tidy.shape[0] - 0.5)
heatmap_ax.set_ylim(obs_tidy.shape[1] - 0.5, -0.5)
heatmap_ax.tick_params(axis='x', bottom=False, labelbottom=False)
heatmap_ax.set_xlabel('')
Expand Down Expand Up @@ -1242,7 +1243,7 @@ def heatmap(
heatmap_ax.vlines(
line_positions,
-0.5,
len(var_names) -0.5,
len(var_names) - 0.5,
lw=1,
color='black',
zorder=10,
Expand Down
Binary file modified scanpy/tests/_images/correlation.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified scanpy/tests/_images/dendrogram.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified scanpy/tests/_images/master_dotplot.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified scanpy/tests/_images/master_dotplot3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified scanpy/tests/_images/master_dotplot_dict.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified scanpy/tests/_images/master_dotplot_gene_symbols.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified scanpy/tests/_images/master_dotplot_std_scale_group.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified scanpy/tests/_images/master_dotplot_std_scale_var.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified scanpy/tests/_images/master_heatmap_var_as_dict.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified scanpy/tests/_images/master_matrixplot_std_scale_var_dict.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified scanpy/tests/_images/master_multiple_plots.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified scanpy/tests/_images/master_ranked_genes_dotplot.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified scanpy/tests/_images/master_ranked_genes_heatmap.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified scanpy/tests/_images/master_ranked_genes_heatmap_swap_axes.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified scanpy/tests/_images/master_ranked_genes_matrixplot.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified scanpy/tests/_images/master_ranked_genes_matrixplot_swap_axes.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified scanpy/tests/_images/master_ranked_genes_stacked_violin.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified scanpy/tests/_images/master_ranked_genes_tracksplot.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified scanpy/tests/_images/master_stacked_violin.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified scanpy/tests/_images/master_stacked_violin_gene_symbols.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified scanpy/tests/_images/master_stacked_violin_std_scale_var_dict.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified scanpy/tests/_images/master_tsne.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion scanpy/tools/_dendrogram.py
Expand Up @@ -133,10 +133,12 @@ def dendrogram(
mean_df = rep_df.groupby(level=0).mean()

import scipy.cluster.hierarchy as sch
from scipy.spatial import distance

corr_matrix = mean_df.T.corr(method=cor_method)
corr_condensed = distance.squareform(1 - corr_matrix)
z_var = sch.linkage(
corr_matrix, method=linkage_method, optimal_ordering=optimal_ordering
corr_condensed, method=linkage_method, optimal_ordering=optimal_ordering
)
dendro_info = sch.dendrogram(z_var, labels=list(categories), no_plot=True)

Expand Down