Add a PC heatmap (equivalent of Seurat's `DimHeatmap`) to help choose the number of PCs

Aperta
#4,541 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
matplotlib, python

Direzione di ricerca

Start by reading the existing sc.pl.pca_loadings implementation under scanpy/plotting/_tools/ as the API model, and the plotting tests for it; then look at how varm["PCs"] loadings and obsm["X_pca"] scores are read elsewhere in the same package. The blocking question is the maintainer answer on legacy matplotlib versus the ScanpyV2Preview HoloViews backend, so the first step is getting that decision, not coding. Done means a working sc.pl.pca_heatmap with a test covering the gene/cell selection and the scale=None z-scoring path.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Add a PC heatmap (equivalent of Seurat's DimHeatmap) to help choose the number of PCs

Seurat's DimHeatmap is a common way to decide how many PCs carry biological signal: for each PC it plots the genes with the most extreme loadings against the cells with the most extreme scores, both ordered by PCA. PCs with clear block structure are kept; the cutoff is where the heatmap starts to look "fuzzy". The HBC single-cell training materials, among others, teach this step.

This has been asked before (#505, #904). #505 has a workaround function in the comments, but nothing landed in sc.pl, so users keep re-implementing it.

Proposed API (mirrors pca_loadings):

sc.pl.pca_heatmap(
    adata, components="1,2,3", *,
    n_genes=30, n_cells=500, balanced=True,
    layer=None, use_raw=False, key_added=None,
    scale=None,            # z-score plotted genes on the fly if data look unscaled
    vmin=-2.5, vmax=2.5,   # Seurat's disp.min / disp.max
    show=None, save=None,
)
  • Genes: top n_genes/2 positive and negative loadings from varm["PCs"] (HVG-masked PCA handled, since non-HVG loadings are 0)
  • Cells: n_cells/2 from each end of obsm["X_pca"]
  • scale=None z-scores only the plotted genes (same result as sc.pp.scale) when the matrix has no negative values. This covers the common case where PCA was run on log-normalized data without pp.scale, without densifying the full matrix.

I have a working, tested prototype for the legacy matplotlib backend.

Question for maintainers: given the ongoing move to the HoloViews (ScanpyV2Preview) backend, would you accept this?

  1. legacy only,
  2. v2 only (e.g. returning an hv.HeatMap / hv.Layout, in the style of the new ranking), or
  3. both?

Happy to open a PR in whichever form you prefer.

Lingua principale
Python
Stelle
2.6k
Fork
809
Merge medio
1g 1h
PR unite (30g)
79

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di scverse/scanpy

Tutte le issue di scverse/scanpy

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.