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

Fix heatmap passing of uns data to scanpy.pl.heatmap #110

Merged
merged 4 commits into from
Sep 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions src/infercnvpy/pl/_chromosome_heatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ def chromosome_heatmap(
raise ValueError("'cnv_leiden' is not in `adata.obs`. Did you run `tl.leiden()`?")
tmp_adata = AnnData(X=adata.obsm[f"X_{use_rep}"], obs=adata.obs, uns=adata.uns)

# transfer colors from adata if present
if f"{groupby}_colors" in adata.uns:
tmp_adata.uns[f"{groupby}_colors"] = adata.uns[f"{groupby}_colors"]

# 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())
Expand Down Expand Up @@ -145,6 +141,7 @@ def chromosome_heatmap_summary(
groups = adata.obs[groupby].unique()
tmp_obs = pd.DataFrame()
tmp_obs[groupby] = np.hstack([np.repeat(x, 10) for x in groups])
tmp_obs.index = tmp_obs.index.astype(str)

def _get_group_mean(group):
group_mean = np.mean(adata.obsm[f"X_{use_rep}"][adata.obs[groupby] == group, :], axis=0)
Expand All @@ -154,14 +151,9 @@ def _get_group_mean(group):
return group_mean

tmp_adata = sc.AnnData(
X=np.vstack([np.repeat(_get_group_mean(group), 10, axis=0) for group in groups]),
obs=tmp_obs,
X=np.vstack([np.repeat(_get_group_mean(group), 10, axis=0) for group in groups]), obs=tmp_obs, uns=adata.uns
)

# transfer colors from adata if present
if f"{groupby}_colors" in adata.uns:
tmp_adata.uns[f"{groupby}_colors"] = adata.uns[f"{groupby}_colors"]

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

Expand Down