"""cache full + dermal-only umap for dingwall replica.""" from __future__ import annotations import warnings warnings.filterwarnings("ignore") from pathlib import Path import numpy as np import scanpy as sc import anndata as ad import os as _os from pathlib import Path as _Path PANDA_ROOT = _Path(_os.environ.get("PANDA_ROOT", str(_Path(__file__).resolve().parents[2]))) ROOT = Path(str(PANDA_ROOT)) OUT = ROOT / "figures/biology" OUT.mkdir(parents=True, exist_ok=True) CACHE = OUT / "_cache_dingwall_umap.npz" def main(): a = ad.read_h5ad(ROOT / "data/processed/dingwall_replica/dingwall_replica.h5ad") print(f"[cache] loaded dingwall_replica: {a.shape}") sc.pp.neighbors(a, use_rep="X_pca_harmony", n_neighbors=30, random_state=42) sc.tl.umap(a, random_state=42, min_dist=0.3) umap_full = a.obsm["X_umap"].copy() # recompute on dermal-only so Derm0..Derm11 separate is_derm = a.obs["is_dermal_paper"].astype(bool).values adx = a[is_derm].copy() print(f"[cache] dermal subset: {adx.shape}") sc.pp.neighbors(adx, use_rep="X_pca_harmony", n_neighbors=30, random_state=42) sc.tl.umap(adx, random_state=42, min_dist=0.3) umap_derm = adx.obsm["X_umap"].copy() derm_index = np.where(is_derm)[0] np.savez( CACHE, umap_full=umap_full, umap_derm=umap_derm, derm_index=derm_index, obs_names=a.obs_names.astype(str).values, sample=a.obs["sample"].astype(str).values, derm_label=a.obs["derm_label"].astype(str).values, paper_cluster_23=a.obs["paper_cluster_23"].astype(str).values, ) print(f"[cache] wrote {CACHE}") if __name__ == "__main__": main()