Skip to content

Gene programs and modules

These tools work on genes across the whole dataset (or a gene subset such as the highly variable genes) rather than on one gene set. They find genes that behave alike: a gene-gene graph and its modules, the nearest neighbors of one gene, and additive expression programs by non-negative matrix factorization (NMF), within one sample or recurring across samples.

Where to find it

Analyze → Genes: Build Gene Graph, Gene PCA, Gene Neighbors, Find Similar Genes, Cluster Genes, NMF Programs, NMF Meta-Programs.

Tool Use it to Output
Gene PCA Embed genes by their expression patterns across cells Gene coordinates
Gene Neighbors Connect each gene to its most similar genes A gene-gene kNN graph
Build Gene Graph Run Gene PCA and Gene Neighbors in one step Both of the above
Find Similar Genes List the genes most like one gene A ranked list, or a gene set
Cluster Genes Partition genes into co-expression modules One module label per gene, and gene sets
NMF Programs Find overlapping programs that cells mix (cycling, hypoxia, interferon response) Per-cell usage scores and one gene set per program
NMF Meta-Programs Find programs that recur independently across samples Per-cell scores and one gene set per meta-program

Clustering partitions: one gene, one module. NMF does not: a gene can carry weight in several programs and each cell is a mix of programs, which is the right shape for states that ride on top of cell identity and share genes with it.

To split one gene set rather than all genes, see Analyze a gene set.

The gene graph

Gene PCA

PCA with genes as observations: each gene is described by its expression across cells, and the components summarize the main patterns genes follow. With Auto-detect PCs on, the number of components is the elbow of the variance curve found by the Kneedle algorithm (Satopää et al. 2011).

Parameter Default What it does
Components empty (auto) Number of PCs. Empty with Auto-detect PCs chooses by Kneedle.
Scale true z-score each gene first, so genes are compared by pattern rather than magnitude.
Auto-detect PCs true Use Kneedle to pick the number of PCs.
Max components 100 PCs computed before Kneedle picks.
Gene Subset highly_variable Boolean .var columns selecting the genes; intersected with the gene mask.
Source matrix X A layer to read instead of .X, such as a smoothed layer from Preprocess → Smooth.
Where What
varm['X_gene_pca'] Gene coordinates.
uns['gene_pca'] Variance explained and parameters.

Gene Neighbors

Builds a k-nearest-neighbor graph between genes, either on the Gene PCA coordinates or directly on expression.

Parameter Default What it does
Basis expression expression compares genes' expression vectors directly; gene_pca uses the Gene PCA coordinates (run Gene PCA first).
Neighbors 10 Neighbors per gene.
Metric euclidean euclidean, cosine or pearson.
Gene Subset (expression basis) highly_variable Genes to include.
Scale (expression basis) true z-score each gene first.
Source matrix (expression basis) X A layer to read instead of .X.
Where What
varp['gene_connectivities'], varp['gene_distances'] The gene graph.

Build Gene Graph

Runs Gene PCA and then Gene Neighbors on the Gene PCA coordinates, in one step.

Parameter Default What it does
Num PCs empty (auto, Kneedle) Gene PCA components.
Scale true z-score genes before PCA.
Neighbors 15 Neighbors per gene.
Metric euclidean euclidean or cosine.
Gene Subset highly_variable Genes to include.

It writes what the two steps write.

Find Similar Genes

Lists the genes closest to a query gene in the gene graph. Needs Gene Neighbors (or Build Gene Graph) first.

Parameter Default What it does
Query gene empty The gene to start from.
Num results 10 How many genes to return.
Similarity connectivities Rank by graph connectivity weight or by distance.

Once a gene graph exists, the Genes panel's Sets tab also shows a Find Similar Genes box (Seed Gene, Number of Similar Genes, default 10). It saves the seed and its neighbors as a set named Similar to <gene> in the Similar Genes category.

Cluster Genes

Leiden clustering (Traag et al. 2019) of the gene graph into co-expression modules. Needs Gene Neighbors (or Build Gene Graph) first. Genes outside the graph are not assigned.

Parameter Default What it does
Resolution 2.0 Higher gives more, smaller modules.
Column name gmod .var column for the module labels.
Where What
var['gmod'] Module label per gene.
uns['gene_modules'] Module membership.

The modules are also added to Gene Clusters as a folder named Clusters (res=…) <time>, one set per module.

NMF Programs

How it works

NMF factorizes the expression matrix into k non-negative programs: each cell's expression is approximated as a weighted sum of programs, and each program is a non-negative weight per gene. Skopia's implementation is a Python port of the single-sample path of GeneNMF (its runNMF and getNMFgenes), solved with fast HALS (Cichocki and Phan 2009). The output follows RcppML's scaling convention (DeBruine et al. 2021), in which each program's gene weights sum to one and programs are sorted by decreasing weight. This matters because the next step compares a gene's weight across programs, and an unnormalized program would look artificially specific.

Each program's gene set is chosen in two steps:

  1. Specificity weighting. Each gene's weight is multiplied by spec ^ w, where spec is the largest share of that gene's total weight any single program takes, and w is Specificity weight. This pushes down genes that load on many programs (housekeeping genes), so the genes that distinguish a program rise.
  2. Cumulative cutoff. The program keeps its top genes until they account for Weight explained of its total weight, capped at Max genes per program.

The cells are scored by their usage of each program, written as a score matrix so each program colors like any score.

Why the specificity weight defaults to 1, not GeneNMF's 5

The exponent bites fast. On a real 24,172-cell E11.5 hindlimb section at k = 12, measured specificity was rarely high (percentiles 0.16, 0.21, 0.27, 0.36, 0.57), so at w = 5 one gene ended up holding most of each program's weight and the cumulative cutoff kept almost nothing: 4 of 12 programs survived, with a median of 4 genes. At w = 1, 11 of 12 survived, and the programs were sharper than with no weighting (the distal program led with Hoxd13 and Hoxd11; with no weighting it led with Stip1 and Sulf2 and the Hox genes fell out of the top 12). GeneNMF applies w = 5 only to the averaged consensus of many programs, which smooths the distribution first; a single factorization has no such averaging. Full sweep: docs/measurements/2026-08-19-gene-nmf-specificity-weight.md in the repository.

Run it

  1. Open Analyze → Genes → NMF Programs.
  2. Set Number of programs (k). NMF does not choose k: too few merges distinct states, too many splits one state across programs. 5 to 15 is the usual range; try a couple of values and keep the one whose programs read as coherent biology.
  3. Check Genes (defaults to highly_variable when it exists; with every gene, housekeeping genes dominate every program), Cells and Source matrix.
  4. Click Find programs. The results list each program's top genes with a Color button; Save all as gene sets adds a folder <name> programs to Gene Clusters.

Reopening the tool on a stored run shows it rather than recomputing.

Parameters

Parameter Default What it does
Number of programs (k) 10 Programs to extract.
Genes highly_variable if present, else all genes A boolean .var column; intersected with the gene mask.
Cells All cells All cells, Current selection, or By annotation… (one column's chosen values). Programs are defined only for the cells the model saw; other cells score NaN.
Source matrix X The matrix to factorize. NMF needs non-negative values; scaled or centered data is refused.
transform (second menu under Source matrix) from the detected scale normalize + log1p for raw counts, use as-is for a matrix already on a log scale. Logging an already-logged matrix compresses the high-expression differences the programs are built from, so the default follows the layer's detected scale and says so.
Result name NMF Key for the results. Use a new name to keep several runs.
Specificity weight (advanced) 1 Exponent of the specificity weighting. 1 sharpens programs; 3 and above shrink them to a handful of genes.
Weight explained (advanced) 0.5 Share of a program's weight its gene set covers. Higher gives longer signatures.
Max genes per program (advanced) 200 Cap applied after the cutoff.
L1 sparsity (gene loadings) (advanced) 0 Above 0, zeroes weak gene loadings, giving crisper but narrower programs. 0 matches GeneNMF.
Random seed (advanced) 0 NMF starts from a random initialization. A program that survives several seeds is a real one.
Max iterations (advanced) 500 Upper bound on solver passes; the run stops earlier once the fit stops improving.

What it writes

Where What
obsm[key] Cells × programs usage (NaN outside the fitted cells), registered in uns['skopia_score_matrices'], so each program is a color pill and the matrix doubles as an embedding.
varm['<key>_loadings'] Gene weights per program.
uns['skopia_gene_nmf'][key] Parameters, program gene sets, weights and fit metrics.

Note

The solver splits its two sparse matrix products across threads in a fixed order, so a seeded run gives the same result on any machine. Sparse input is never made dense. On 250,000 cells × 2,000 genes at k = 20 it took 8.8 s, against 48 s for scikit-learn's mu solver at an equal or better fit.

NMF Meta-Programs

How it works

A single factorization of a pooled matrix cannot tell a real gene program from a batch effect. NMF Meta-Programs, a port of the multi-sample half of GeneNMF (multiNMF and getMetaPrograms), factorizes each sample separately at every rank in a sweep, then clusters all the resulting programs by similarity into consensus meta-programs and scores each by sample coverage: the share of samples in which it turned up independently. A program found once can be a batch effect; one found independently in several samples is harder to explain that way.

  1. Each sample (a value of Sample column) is factorized at every k in Ranks to sweep. Samples smaller than Min cells per sample are skipped and named.
  2. Each program's gene weights are specificity-weighted within its own factorization: "how exclusive is this gene among this model's factors". Pooling across the study would make a gene's score depend on how many samples were included, penalizing exactly the recurrent programs the tool looks for.
  3. Programs are compared by cosine similarity of their weights (or Jaccard of their top genes) and clustered by Ward linkage (Ward 1963) into Meta-programs (nMP) groups.
  4. Each meta-program's consensus weights are an outlier-trimmed mean over its programs, so one runaway program cannot carry a gene in. A gene must appear in more than Min gene confidence of the cluster's programs. The meta-program's gene set is then cut by Weight explained.
  5. Meta-programs are ranked by sample coverage, then by silhouette width.

Each cell's score for a meta-program is its expression weighted by the consensus gene weights.

Run it

  1. Open Analyze → Genes → NMF Meta-Programs.
  2. Pick Sample column: the .obs column separating samples, sections or donors.
  3. Check Ranks to sweep (k), Meta-programs (nMP), Genes and Source matrix.
  4. Click Find meta-programs.
  5. Read the results tabs:
    • Programs: each meta-program's genes, sample coverage and silhouette, with Color.
    • Similarity: every program against every other, in dendrogram order, with each meta-program outlined as a block on the diagonal (GeneNMF's plotMetaPrograms). A bright, tight block is a real consensus; a dim block that bleeds into its neighbors is not.
    • Composition: how many of each sample's programs fall in each meta-program, so a sample-specific meta-program shows as one concentrated column.
  6. Save all as gene sets adds a folder <name> meta-programs to Gene Clusters.

Parameters

Parameter Default What it does
Sample column none Categorical .obs column; each value is factorized on its own.
Ranks to sweep (k) 4 to 9 Ranks fit per sample, as in GeneNMF. Sweeping means a program is not an artifact of one choice of k. Wider sweeps cost proportionally more time.
Meta-programs (nMP) 10 Clusters to cut the program tree into. Start near the widest k and check the similarity heatmap: over-cutting splits one block in two.
Genes highly_variable if present A batch-aware HVG column (Highly Variable Genes with Detect within groups of) is better still, since genes variable in only one sample should not drive a consensus.
Source matrix, transform X, from the detected scale As for NMF Programs.
Result name MP Key for the results.
Specificity weight 5 See below.
Weight explained 0.8 See below.
Min gene confidence 0.5 Share of a cluster's programs a gene must appear in to enter the consensus.
Similarity metric cosine (weights) cosine (weights) or jaccard (gene sets).
Min cells per sample 10 Smaller samples are skipped.
Random seed 0
Why these defaults differ from NMF Programs

The single-sample tool lowers the specificity weight to 1 because one factorization has no averaging. Here the consensus averages gene weights over every program in a cluster before the cutoff, which is the smoothing the single-sample path lacks, so GeneNMF's 5 works, provided Weight explained is raised from 0.5 to 0.8 (after strong weighting, the top genes hold most of the mass and 0.5 admits only a handful). Measured on three E11.5 hindlimb sections (117 programs from k = 4 to 9, cut into 8 meta-programs): specificity 5 with weight explained 0.5 lost two of eight meta-programs and left the rest at a median of 7 genes; 5 with 0.8 kept all eight (median 46 genes) and gave the best marker purity of the settings tried (0.72, against 0.56 at specificity 1). Full grid: docs/measurements/2026-08-19-gene-nmf-metaprogram-defaults.md in the repository.

What it writes

Where What
obsm[key] Cells × meta-programs scores, registered in uns['skopia_score_matrices'].
uns['skopia_gene_nmf_meta'][key] Parameters, meta-program gene sets and weights, sample coverage, silhouettes, and the program similarity data.

Tips and pitfalls

Read the silhouette before the gene list

Ward clustering assigns every program to some meta-program, including programs that resemble nothing else. A meta-program with a silhouette below 0.05 is labeled Low silhouette in the results: treat it as a leftover group, not a consensus. On the hindlimb sections one meta-program came back at −0.05, and the similarity heatmap showed a diffuse block of 30 programs that clustered only because they had nowhere else to go.

Low coverage is not always noise

Coverage counts samples, so a program present in only one sample may be real biology that only one sample contains. On the hindlimb sections a distal Hoxd11/Hoxd13/Grem1 meta-program had 1/3 coverage because only one section was cut through the distal limb.