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

オープン
#4,541 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
matplotlib, python

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Python
スター
2.6k
フォーク
809
平均マージ
1日 1時間
マージ済み PR(30日)
79

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

scverse/scanpy のほかの issue

scverse/scanpy の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。