PCA diagnostics¶
Inspect PCA results already stored by Scanpy. These examples use the packaged PBMC data and do not recompute PCA.
Install or update with pip install --upgrade 'genome-spy-python[scanpy]'. Choose that environment as your Jupyter kernel.
import scanpy as sc
import genome_spy.integrations.scanpy as gsc
pbmc = sc.datasets.pbmc68k_reduced()
pca_genes = pbmc[:, pbmc.var["highly_variable"]]
Inspect gene loadings¶
See which genes contribute to the first two components. This uses the genes included in the stored PCA.
loadings = gsc.pl.pca_loadings(
pca_genes,
components="1,2",
n_points=10,
width=260,
height=260,
show=False,
)
loadings
Inspect explained variance¶
Show how much variance each component explains. log=True uses a logarithmic value axis.
variance = gsc.pl.pca_variance_ratio(
pbmc,
n_pcs=10,
log=True,
width=360,
height=240,
show=False,
)
variance
Show the PCA overview¶
Cell positions sit above a compact grid. PC1 and PC2 are on the first row; PC3 and explained variance are below. Scroll over the cell plot to zoom.
overview = gsc.pl.pca_overview(
pca_genes,
color="louvain",
size=12,
width=240,
height=240,
zoom=True,
show=False,
)
overview
Data use and provenance
These examples use Scanpy’s packaged, preprocessed PBMC68k data. Credit 10x Genomics and Scanpy’s preprocessing contributors. Source data: CC BY 4.0. Supplied expression, annotations and analysis results are retained.