TECHNOLOGY

scVI reference mapping: query genes must match the saved feature registry

In this article
THE QUICK TAKE

Query preparation aligns a dataset to the reference feature contract; adaptation is a separate model-update operation.

The same gene set can arrive in a different order

A query dataset may contain the reference genes in another column order or lack some features entirely. Passing its matrix directly to an scVI reference model can therefore change the meaning of input dimensions. Equal width does not establish that columns describe the expected genes.

The SCVI API reference documents query preparation against the saved reference. Preserve that feature contract alongside the trained parameters.

Query preparation handles a defined alignment

The documented prepare_query_anndata path sorts features to match the reference and pads missing features with zeros. This is a concrete preparation rule, not evidence that an absent measurement was experimentally observed as zero.

Retain the original measured-gene inventory and a preparation report. A later analyst should be able to distinguish source zeros from model-compatible padding. If missing features are numerous, scientific suitability requires separate evaluation rather than being inferred from successful shape alignment.

The registry contains more than gene names

The reference-mapping tutorial explains the reference/query workflow. Matrix layer selection and categorical information must remain consistent with the saved setup.

Do not recreate batch categories by independently assigning arbitrary integer codes. Those codes need their relationship to the reference registry. A familiar category string and a matching numeric dtype are not substitutes for preserving the model setup that gives them meaning.

Adaptation differs from a forward pass

The query-loading implementation supports a reference-update workflow with explicit freezing options. Loading and training query adaptation is not equivalent to merely encoding data through an unchanged model.

Label adapted models as new artifacts and record their reference, query preparation, and training configuration. The model-update guide provides context for comparing changed model behavior rather than attributing every difference to preprocessing alone.

Verify correspondence before biological conclusions

Inspect reference feature names, prepared query order, missing-feature padding, and registry categories on a small example. Keep cell identities aligned through any filtering or reordering before joining embeddings to annotations.

The artifact validation guide motivates preserving this complete bundle. Correct reference mapping establishes computational compatibility; a latent embedding or integrated visualization does not itself prove the biological equivalence of cells, elimination of every batch effect, or clinical validity of downstream labels.

Earn rental income from GPUs

Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.

Explore GPU hosting
← All articles