Skip to main content
M-Optimus prediction server-side model. Loads the exported M-Optimus spatial transcriptomics model. Accepts optional bulk RNA counts alongside the tile image. In the two-stage pipeline, bulk RNA preprocessing and gene count validation happen during prepare_sample (Stage 1), so a malformed bulk_rna field fails only the individual request without affecting the batch.

MOptimusModel

M-Optimus prediction model (224x224, MPP 0.5). Produces per-tile gene expression predictions. Optionally incorporates bulk RNA counts when provided in the request.
Filename of the .pt2 checkpoint.
Torch device string.
Directory containing the checkpoint.
Directory containing gene set CSVs.

input_gene_names

Ordered list of input (bulk RNA) Ensembl gene IDs.

output_gene_names

Ordered list of predicted output Ensembl gene IDs.

get_metadata

Returns base metadata plus input and output gene sets. Returns: Dictionary with model info, gene sets, and I/O specs.

prepare_sample

Deserializes tile image and validates bulk RNA per-sample. Bulk RNA preprocessing and gene count validation happen here so that a single request with malformed RNA data fails with a per-request error (HTTP 400) and never enters the batch.
Raw model request.
Returns: A PreparedSample with tile tensor and optional bulk RNA tensor in extra_tensors. Raises:
  • BioptimusValueError - Tagged with ErrorCode.RNA_SCHEMA_MISMATCH if bulk RNA preprocessing fails or the gene count does not match the model panel. Subclasses ValueError, so it still maps to an HTTP 400 at the API boundary.
  • ValueError - If the tile image is invalid (raised by the base class).

forward

Runs M-Optimus inference with optional bulk RNA (legacy path).
List of tile requests with optional bulk RNA.
Returns: Model output tensor of shape (N, num_output_genes).