Skip to content

scene_pipelines.ingestion.mouse

Write helpers for the mouse tables (Strain, Mouse).

Importing this package registers the mouse schema, so it is not re-exported from scene_pipelines.ingestion: labs without mice never import it.

register_mouse

register_mouse(subject_code: str, sex: str, *, lab: DjKey[Lab], date_of_birth: date | None = None, strain: DjKey[Strain] | None = None, genotype: str | None = None, deployment: DjRow[Deployment] | None = None, if_exists: DuplicatePolicy = VERIFY) -> DjKey[Mouse]

Register a mouse by its lab code: the Subject and its Mouse row.

Parameters:

Name Type Description Default
subject_code str

Pseudonymous code, unique within lab.

required
sex str

"M", "F" or "U" (unknown).

required
lab DjKey[Lab]

Existing lab primary key, e.g. {"lab_id": "mlai"}.

required
date_of_birth date | None

Optional date of birth.

None
strain DjKey[Strain] | None

Optional existing Strain key (background strain), e.g. {"strain_name": "C57BL/6J"}; add a new one first with ensure_strain.

None
genotype str | None

Optional free-text genotype (transgenic lines, zygosity).

None
deployment DjRow[Deployment] | None

Optional deployment row. If omitted, built from SCENE_DEPLOYMENT_ID / SCENE_DEPLOYMENT_LABEL.

None
if_exists DuplicatePolicy

Policy applied to the subject and to the mouse row when already registered; see DuplicatePolicy.

VERIFY

Returns:

Type Description
DjKey[Mouse]

Mouse primary key {subject_id: ...} (same as the subject's).

Raises:

Type Description
ValueError

If subject_code is not a valid code, the code belongs to a subject of another kind, strain does not exist, deployment is omitted and SCENE_DEPLOYMENT_ID is unset, or if_exists rejects an existing subject or mouse.

ensure_strain

ensure_strain(strain: DjRow[Strain], *, deployment: DjRow[Deployment] | None = None, if_exists: DuplicatePolicy = VERIFY) -> DjKey[Strain]

Insert a strain row and stamp the deployment that registered it.

Parameters:

Name Type Description Default
strain DjRow[Strain]

Full strain insert dict: strain_name in official nomenclature (e.g. C57BL/6J, not B6) and optional rrid.

required
deployment DjRow[Deployment] | None

Optional deployment row. If omitted, built from SCENE_DEPLOYMENT_ID / SCENE_DEPLOYMENT_LABEL.

None
if_exists DuplicatePolicy

Policy when strain_name is already stored; see DuplicatePolicy.

VERIFY

Returns:

Type Description
DjKey[Strain]

Strain primary key {strain_name: ...}.

Raises:

Type Description
ValueError

If strain_name or rrid is malformed, the name is stored under another spelling, the rrid already belongs to another strain, deployment is omitted and SCENE_DEPLOYMENT_ID is unset, or if_exists rejects the existing row.