import spanormpy as sn
# adata: the HumanDLPFC AnnData (raw counts in X, coordinates in obsm["spatial"])
keep = sn.filter_genes(adata, prop=0.2, inplace=False) # genes expressed in >= 20% of spots
int(keep.sum()), keep.size(301, 301)
Flag genes expressed in at least prop of the spots.
Mirrors R filterGenes: validates 0 <= prop <= 1 and the counts, then computes rowMeans(counts > 0) >= prop. With inplace=False the boolean mask (R’s return value) is returned. With inplace=True (scanpy filter_genes convention) the genes failing the filter are removed from adata and None is returned.
The code below runs when the site is built, on a small pre-fitted subset of HumanDLPFC (301 genes x 4015 spots; spanorm(sample_p=0.05, df_tps=2), spanorm_svg() and spanorm_pca() already applied) that is fitted once per build and loaded as adata. The outputs are those of the code shown.