Cohort, a typed registry that tracks the mapping between patients, wsis, bulk RNA samples, timepoints, labels, and arbitrary clinical metadata. WSIRecord is the single source of truth for each WSI — including per-model outputs and processing status.
Construction paths:
- From a user-provided CSV via
from_csv. - Auto-matching from directories via
from_directories. - From a YAML manifest via
load(for resume).
save and loaded back for full reproducibility and resume support.
Example:
ModelOutput
Name of the model that produced this output.
Path to the embedding output file.
Path to the prediction output file.
Path to the tile coordinates CSV.
Directory containing exported tile images.
Input modalities used for this output (e.g.
["image"] or ["image", "bulk_rna"]).ISO 8601 string of when the output was produced.
Processing status (
"pending", "done", "error").Error message if status is
"error".is_done
True if status is done.
has_embedding
True if an embedding path is set and exists.
has_prediction
True if a prediction path is set and exists.
set_stage_output
embedding_path / prediction_path).
str
required
"embed" or "predict".list[str]
required
Modalities used for this output.
Path
required
Output file path.
str | None
ISO 8601 timestamp.
get_stage_path
str
required
"embed" or "predict".list[str] | None
Modality combination to look up. Falls back to the top-level path when
None.Path | None
Resolved path, or
None if not recorded.to_dict
dict[str, Any]
A dictionary representation of the model output.
from_dict
dict[str, Any]
required
Dictionary with serialised model output fields.
ModelOutput
A new
ModelOutput instance.WSIRecord
Unique patient identifier.
Unique WSI identifier (typically the filename stem).
Path to the WSI file.
Identifier for the paired bulk RNA sample.
Path to the bulk RNA CSV/TSV file.
Path to a tissue mask (pre-computed or cached).
When the mask was computed/discovered.
Temporal ordering label (e.g.
"t0", "t1").Per-model output records keyed by model name.
Arbitrary categorical annotations.
Arbitrary clinical/treatment metadata.
get_output
str
required
Model identifier string.
ModelOutput
The
ModelOutput for the given model.is_stage_done
modality_outputs are tracked, the check is scoped to the record’s current available_modalities so that linking new data (e.g. bulk RNA) automatically surfaces pending work without requiring force=True.
str
required
Model identifier.
str
required
"embed" or "predict".bool
True if the output path exists on disk.has_mask
True if a mask path is set and exists on disk.
available_modalities
"image". Includes "bulk_rna" when bulk_rna_path is set.
to_dict
dict[str, Any]
A dictionary representation of the WSI record.
from_dict
dict[str, Any]
required
Dictionary with serialised WSI record fields.
WSIRecord
A new
WSIRecord instance.PatientRecord
Unique patient identifier.
Ordered list of WSI records (by timepoint).
Patient-level categorical annotations.
Patient-level clinical metadata.
Cohort
WSIRecord entries grouped by patient. It stores all information needed to reproduce and resume an inference run: file locations, pairing logic, timepoints, per-model outputs, labels, and clinical metadata.
Construction: Use from_csv, from_directories, or load rather than calling the constructor directly.
Initial list of
WSIRecord entries.from_csv
wsi_id: WSI identifier (filename stem or full name).
patient_id: if absent, derived fromwsi_id.bulk_rna_id: paired RNA sample identifier.timepoint: temporal label.wsi_path: explicit path override.bulk_rna_path: explicit path override.- Any other columns are treated as labels if prefixed with
label_or as metadata otherwise.
wsi_id, patient_id, bulk_rna_id, timepoint, wsi_path, bulk_rna_path.
Path to the CSV manifest.
Directory to resolve WSI paths from.
Directory to resolve bulk RNA paths from.
Mapping of canonical field names to actual CSV column names. Unmapped fields fall back to their canonical name.
Cohort.
from_directories
t0, t1, …) in alphabetical order.
str | Path
required
Directory containing WSI files.
str | Path | None
Directory containing bulk RNA files. When
None, wsis are registered without RNA.str | Path | None
Directory containing pre-computed masks (PNG files whose stem matches the WSI stem).
Callable[[str], str] | None
Optional callable that maps a filename stem to a patient ID.
Cohort
A populated
Cohort.save
str | Path
required
Destination file path.
Path
The resolved output path.
load
str | Path
required
Path to the YAML manifest file.
Cohort
A fully-populated
Cohort.upsert
str
required
WSI identifier.
str | None
Patient identifier (defaults to wsi_id).
Path | None
Path to WSI file.
Path | None
Path to bulk RNA file.
Path | None
Path to tissue mask.
str | None
Timepoint label.
WSIRecord
The inserted or updated
WSIRecord.get_wsi
None.
str
required
Unique WSI identifier (typically the file stem).
WSIRecord | None
The matching
WSIRecord, or None if not found.link_bulk_rna
bulk_rna_path are skipped.
This enables late-binding of bulk RNA data: build a cohort from WSIs first, then call this method to attach RNA when it becomes available.
str | Path
required
Directory containing bulk RNA files.
set[str] | None
File extensions to match. Defaults to
{".csv", ".tsv"}.str | None
Column delimiter for parsing. When
None the separator is inferred from the file extension.str | None
Column name containing gene identifiers. Required (with
value_column) for long-format files (e.g. GDC/TCGA gene quantification TSVs).str | None
Column name containing expression values to read (e.g.
"tpm_unstranded").bool
When
True, strips version suffixes from gene identifiers (e.g. ENSG…00003.15 → ENSG…00003).int
Number of records that were linked.
add_labels
dict[str, dict[str, Any]]
required
Mapping of
{identifier: {label_name: value}}.str
Key to match on —
"patient_id" or "wsi_id".add_metadata
dict[str, dict[str, Any]]
required
Mapping of
{identifier: {field: value}}.str
Key to match on —
"patient_id" or "wsi_id".add_labels_from_csv
patient_id). Columns prefixed with label_ are treated as labels; remaining columns as metadata.
str | Path
required
Path to the labels CSV.
str
Join key column name.
num_patients
patients
get_patient
PatientRecord for a given patient.
str
required
Patient identifier string.
PatientRecord
The matching
PatientRecord.KeyError— If patient_id is not found.
wsi_ids
patient_ids
wsi_paths
None).
pending
str
required
Model identifier.
str
required
"embed" or "predict".list[WSIRecord]
List of
WSIRecord entries still needing processing.to_csv
save.
str | Path
required
Destination file path.
Path
The resolved output path.
summary
str
Multi-line summary string.

