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#
Facade class to wrap model DataEntity to facilitate file handling (including index files). |
|
Enumeration of element types exposed to the user. |
|
Enumeration of all element types. |
Functions#
|
|
|
|
|
Update the metadata of a zarr group with the metadata of a model element. |
|
Checks if an element_id contains the element type as prefix. |
|
Add element to the hasPart attribute of a parent zarr group |
|
update the id of the has_part property of an element to use the full id including its type |
|
Set the data_path attribute, if it is not specified to the modo root. |
|
Generate the BLAKE2b checksum of the file_obj digest. |
|
Checks if input is a valid URI. |
Return a view over the schema structure. |
|
Load the prefixmap. |
|
|
Return a list of required slots for a class. |
|
|
|
Return the class-independent range of a slot. |
|
|
|
Return the name of the "has_part" property for a target class. |
Module Contents#
- modos.helpers.schema.dict_to_instance(element)[source]#
- Parameters:
element (Mapping[str, Any])
- Return type:
Any
- modos.helpers.schema.update_metadata_from_model(group, element)[source]#
Update the metadata of a zarr group with the metadata of a model element.
- Parameters:
group (zarr.hierarchy.group)
element (modos_schema.datamodel.DataEntity | modos_schema.datamodel.Sample | modos_schema.datamodel.Assay | modos_schema.datamodel.ReferenceGenome)
- 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
- modos.helpers.schema.set_haspart_relationship(child_class, child_path, parent_group)[source]#
Add element to the hasPart attribute of a parent zarr group
- 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:
element (modos_schema.datamodel.DataEntity)
source_file (Optional[Union[pathlib.Path, str]])
- Return type:
modos_schema.datamodel.DataEntity
- class modos.helpers.schema.DataElement(model, storage)[source]#
Facade class to wrap model DataEntity to facilitate file handling (including index files).
- Parameters:
model (DataElement.__init__.model)
- _update_checksum(source_path)[source]#
- Parameters:
source_path (pathlib.Path)
- add_file(source_path, target_path)[source]#
Add a file to target_path to the storage. If existing also add the index file and update data_path and checksum in metadata
- Parameters:
source_path (pathlib.Path)
target_path (pathlib.Path)
- move_file(target_path)[source]#
Move a file from the path specified in metadata to the target_path. If existing also move the index file.
- Parameters:
target_path (pathlib.Path)
- remove_file(rm_path)[source]#
Remove a file and its related index from the storage.
- Parameters:
rm_path (pathlib.Path)
- update_file(new_path, source_file=None)[source]#
Update file, its corresponding index file and metadata, based on new data_path and source_file.
There are four cases: 1. Neither path nor contents changed –> do nothing. 2. Only contents changed –> overwrite the file(s). 3. Only path changed -> move file(s). 4. Both path and contents changed -> add new file(s) and remove old ones.
- Parameters:
new_path (pathlib.Path) – Path to where the file should be placed.
source_file (pathlib.Path | None) – Path to the file that shall be added. If None the file already associated to the DataElement will be used.
- encrypt(recipient_pubkeys, seckey_path=None, passphrase=None, delete=True)[source]#
Encrypt data path linked to the DataElement. Works for genomic files and their index files.
- Parameters:
recipient_pubkeys (list[os.PathLike] | os.PathLike)
seckey_path (Optional[os.PathLike])
passphrase (Optional[str])
delete (bool)
- decrypt(seckey_path, sender_pubkey=None, passphrase=None)[source]#
Decrypt data path linked to the DataElement. Works for genomic files and their index files.
- Parameters:
seckey_path (os.PathLike)
sender_pubkey (Optional[os.PathLike])
passphrase (Optional[str])
- modos.helpers.schema.compute_checksum(file_obj)[source]#
Generate the BLAKE2b checksum of the file_obj digest.
- Parameters:
file_obj (io.RawIOBase)
- Return type:
- class modos.helpers.schema.UserElementType[source]#
-
Enumeration of element types exposed to the user.
- modos.helpers.schema.load_schema()[source]#
Return a view over the schema structure.
- Return type:
linkml_runtime.utils.schemaview.SchemaView
- modos.helpers.schema.get_slots(target_class, required_only=False)[source]#
Return a list of required slots for a class.
- modos.helpers.schema.get_slot_range(slot_name)[source]#
Return the class-independent range of a slot.