MDF Enforced Validator and Loader

Logo

Documentation for MEVAL.

ModelParser Usage

ModelParser (meval/parser.py) is a higher-level wrapper around bento_mdf.MDFReader that offers direct and easy access to MDF model features β€” nodes, properties, edges, and their attributes β€” without needing to work with the underlying bento_mdf.MDFReader objects directly. Validator and Loader both use a ModelParser instance to interpret the model when validating or loading data.

Contents

Instantiation

from meval.parser import ModelParser

model_parser = ModelParser(
    model_file="model.yml",
    props_file="model-props.yml",
    handle="your_project",  # optional model/commons acronym
    if_resolve_edps=False,  # optionally resolve EDP terms
)

The parsed model is stored on model_parser.model (a bento_mdf.MDFReader.model model object) and is used internally by all methods below.

Node introspection

model_parser.get_node_list()
# ['study', 'participant', 'sample', ...]

model_parser.get_node_props_list_required("participant")
model_parser.get_node_key_prop("participant")  # e.g. "participant_id"

Property introspection

model_parser.get_prop_type("participant", "sex")           # e.g. "value_set"
model_parser.get_permissible_values("participant", "sex")  # ["Male", "Female", ...]
model_parser.if_prop_required("participant", "participant_id")  # True

All of the above raise KeyError if the node and/or property is not found in the model, and ValueError (via get_prop_attr_dict, get_prop_type, get_permissible_values, and the if_prop_* methods) if the node exists but does not have the given property.

Node relationships (edges)

model_parser.get_parent_nodes("sample")   # ["participant"]
model_parser.get_root_node()              # "study"
model_parser.get_edge_handle(edge_src="sample", edge_dst="participant")  # "of_participant"
model_parser.get_edge_multiplicity(edge_src="sample", edge_dst="participant")  # "many_to_one"

get_edge_multiplicity and get_edge_handle raise KeyError if no edge exists between the given source and destination nodes.