modos.helpers.schema#

Introspection utilities for the MODO schema.

This module provides helpers for accessing the schema structure and for converting instances to different representations.

Attributes#

Classes#

UserElementType

Enumeration of element types exposed to the user.

ElementType

Enumeration of all element types.

Functions#

class_from_name(name)

dict_to_instance(element)

is_full_id(element_id)

Checks if an element_id contains the element type as prefix.

set_haspart_relationship(child_class, child_path, ...)

Add element to the hasPart attribute of a parent zarr group

update_haspart_id(element)

update the id of the has_part property of an element to use the full id including its type

set_data_path(element[, source_file])

Set the data_path attribute, if it is not specified to the modo root.

is_uri(text)

Checks if input is a valid URI.

load_schema()

Return a view over the schema structure.

load_prefixmap()

Load the prefixmap.

get_slots(target_class[, required_only])

Return a list of required slots for a class.

instance_to_graph(instance)

get_slot_range(slot_name)

Return the class-independent range of a slot.

get_enum_values(enum_name)

get_haspart_property(child_class)

Return the name of the "has_part" property for a target class.

Module Contents#

modos.helpers.schema.SCHEMA_PATH[source]#
modos.helpers.schema.class_from_name(name)[source]#
Parameters:

name (str)

modos.helpers.schema.dict_to_instance(element)[source]#
Parameters:

element (Mapping[str, Any])

Return type:

Any

modos.helpers.schema.is_full_id(element_id)[source]#

Checks if an element_id contains the element type as prefix.

Examples

>>> is_full_id("sample1")
False
>>> is_full_id("data/test")
True
>>> is_full_id("/assay/test_assay")
True
Parameters:

element_id (str)

Return type:

bool

modos.helpers.schema.set_haspart_relationship(child_class, child_path, parent_group)[source]#

Add element to the hasPart attribute of a parent zarr group

Parameters:
modos.helpers.schema.update_haspart_id(element)[source]#

update the id of the has_part property of an element to use the full id including its type

Parameters:

element (modos_schema.datamodel.DataEntity | modos_schema.datamodel.Sample | modos_schema.datamodel.Assay | modos_schema.datamodel.ReferenceGenome | modos_schema.datamodel.MODO)

modos.helpers.schema.set_data_path(element, source_file=None)[source]#

Set the data_path attribute, if it is not specified to the modo root.

Parameters:
Return type:

dict

class modos.helpers.schema.UserElementType[source]#

Bases: str, enum.Enum

Enumeration of element types exposed to the user.

SAMPLE = 'sample'[source]#
ASSAY = 'assay'[source]#
DATA_ENTITY = 'data'[source]#
REFERENCE_GENOME = 'reference'[source]#
get_target_class()[source]#

Return the target class for the element type.

Return type:

type

classmethod from_object(obj)[source]#

Return the element type from an object.

class modos.helpers.schema.ElementType[source]#

Bases: str, enum.Enum

Enumeration of all element types.

SAMPLE = 'sample'[source]#
ASSAY = 'assay'[source]#
DATA_ENTITY = 'data'[source]#
REFERENCE_GENOME = 'reference'[source]#
REFERENCE_SEQUENCE = 'sequence'[source]#
get_target_class()[source]#

Return the target class for the element type.

Return type:

type

classmethod from_object(obj)[source]#

Return the element type from an object.

classmethod from_model_name(name)[source]#

Return the element type from an object name.

Parameters:

name (str)

modos.helpers.schema.is_uri(text)[source]#

Checks if input is a valid URI.

Parameters:

text (str)

modos.helpers.schema.load_schema()[source]#

Return a view over the schema structure.

Return type:

linkml_runtime.utils.schemaview.SchemaView

modos.helpers.schema.load_prefixmap()[source]#

Load the prefixmap.

Return type:

Any

modos.helpers.schema.get_slots(target_class, required_only=False)[source]#

Return a list of required slots for a class.

Parameters:

target_class (type)

Return type:

list[str]

modos.helpers.schema.instance_to_graph(instance)[source]#
Return type:

rdflib.Graph

modos.helpers.schema.get_slot_range(slot_name)[source]#

Return the class-independent range of a slot.

Parameters:

slot_name (str)

Return type:

str

modos.helpers.schema.get_enum_values(enum_name)[source]#
Parameters:

enum_name (str)

Return type:

Optional[list[str]]

modos.helpers.schema.get_haspart_property(child_class)[source]#

Return the name of the “has_part” property for a target class. If no such property is in the schema, return None.

Examples

>>> get_haspart_property('AlignmentSet')
'has_data'
>>> get_haspart_property('Assay')
'has_assay'
Parameters:

child_class (str)

Return type:

Optional[str]