Skip to content

Model conversion

model_conversion

Conversion between bundle JSON values and installed GA4GH models.

Functions:

parse_gkm_values

parse_gkm_values(value: Any) -> Any

Convert valid, discriminator-typed mappings to GA4GH models.

Parameters:

Name Type Description Default
value Any

JSON-compatible value to inspect.

required

Returns:

Type Description
Any

Reference models where possible, with other values preserved.

Raises:

Type Description
BundleValidationError

If a recognized object is invalid.

parse_schema_value

parse_schema_value(value: Any, model: type[BaseModel]) -> Any

Materialize a schema-selected model unless local pointers prevent it.

Parameters:

Name Type Description Default
value Any

Value addressed by a bundle-local pointer.

required
model type[BaseModel]

Reference implementation selected from the target schema.

required

Returns:

Type Description
Any

A validated model, or the original value when local pointers prevent it.

Raises:

Type Description
BundleValidationError

If the target is invalid for its schema model.

parse_schema_references_value

parse_schema_references_value(value: Any, references: tuple[str, ...]) -> Any

Validate a value against the models selected by schema references.

Composition keywords can identify multiple candidate models. Pydantic selects the candidate whose complete structure validates.

Parameters:

Name Type Description Default
value Any

JSON-compatible value to validate.

required
references tuple[str, ...]

Candidate external schema references.

required

Returns:

Type Description
Any

A validated model, or the original value when no model is supported.

Raises:

Type Description
BundleValidationError

If supported models exist but none validate.

model_for_schema_ref

model_for_schema_ref(reference: str | None) -> type[BaseModel] | None

Return the installed model identified by a compatible GA4GH W3ID reference.

Parameters:

Name Type Description Default
reference str | None

Schema reference URL, if present.

required

Returns:

Type Description
type[BaseModel] | None

Matching reference model, or None when it is unsupported.

model_for_schema_references

model_for_schema_references(references: tuple[str, ...]) -> type[BaseModel] | None

Return the first supported model identified by schema references.

Parameters:

Name Type Description Default
references tuple[str, ...]

External schema references in schema order.

required

Returns:

Type Description
type[BaseModel] | None

The first matching reference model, or None when unsupported.