Skip to content

Commit

Permalink
Merge pull request #16 from icbi-lab/fix-15
Browse files Browse the repository at this point in the history
Reorder chr_pos dict before plotting heatmap
  • Loading branch information
grst committed Aug 25, 2021
2 parents 872db6d + 82730b4 commit c1ed198
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions infercnvpy/pl/_chromosome_heatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ def chromosome_heatmap(
"'cnv_leiden' is not in `adata.obs`. Did you run `tl.leiden()`?"
)
tmp_adata = AnnData(X=adata.obsm["X_cnv"], obs=adata.obs)
chr_pos = list(adata.uns[use_rep]["chr_pos"].values())

# re-sort, as saving & loading anndata destroys the order
chr_pos_dict = dict(
sorted(adata.uns[use_rep]["chr_pos"].items(), key=lambda x: x[1])
)
chr_pos = list(chr_pos_dict.values())

# center color map at 0
norm = TwoSlopeNorm(0, vmin=np.min(tmp_adata.X), vmax=np.max(tmp_adata.X))
Expand All @@ -72,7 +77,7 @@ def chromosome_heatmap(
cmap=cmap,
show_gene_labels=False,
var_group_positions=var_group_positions,
var_group_labels=list(adata.uns["cnv"]["chr_pos"].keys()),
var_group_labels=list(chr_pos_dict.keys()),
norm=norm,
show=False,
**kwargs
Expand Down Expand Up @@ -159,7 +164,11 @@ def chromosome_heatmap_summary(
),
obs=tmp_obs,
)
chr_pos = list(adata.uns[use_rep]["chr_pos"].values())

chr_pos_dict = dict(
sorted(adata.uns[use_rep]["chr_pos"].items(), key=lambda x: x[1])
)
chr_pos = list(chr_pos_dict.values())

# center color map at 0
norm = TwoSlopeNorm(0, vmin=np.min(tmp_adata.X), vmax=np.max(tmp_adata.X))
Expand All @@ -175,7 +184,7 @@ def chromosome_heatmap_summary(
cmap=cmap,
show_gene_labels=False,
var_group_positions=var_group_positions,
var_group_labels=list(adata.uns["cnv"]["chr_pos"].keys()),
var_group_labels=list(chr_pos_dict.keys()),
norm=norm,
show=False,
**kwargs
Expand Down

0 comments on commit c1ed198

Please sign in to comment.