Model#

class panorama.systems.models.Model(name='', mandatory=None, accessory=None, forbidden=None, neutral=None, min_mandatory=1, min_total=1, transitivity=0, window=1, same_strand=False, canonical=None)#

Bases: _BasicFeatures, _ModFuFeatures

A Model class representing rules which describe a biological system.

This class provides an abstraction to handle a set of biological rules and their associated functional units and families. It supports operations to query various characteristics of the biological model, including its size, functional units, and families. The Model can also perform checks for consistency and parse data from a given dictionary for initialization and configuration.

name#

Name of the instance.

Type:

str

mandatory#

Set of mandatory functional units or families.

Type:

Set[FuncUnit, Family]

accessory#

Set of accessory functional units or families.

Type:

Set[FuncUnit, Family]

forbidden#

Set of forbidden functional units or families.

Type:

Set[FuncUnit, Family]

neutral#

Set of neutral functional units or families.

Type:

Set[FuncUnit, Family]

min_mandatory#

Minimum number of mandatory functional units required.

Type:

int

min_total#

Minimum total number of functional elements required.

Type:

int

transitivity#

Transitivity value for relationships in functional elements.

Type:

int

window#

Window size used for analysis or traversal.

Type:

int

same_strand#

Indicates if the functional units should be on the same strand.

Type:

bool

canonical#

List containing canonical representations.

Type:

list

__init__(name='', mandatory=None, accessory=None, forbidden=None, neutral=None, min_mandatory=1, min_total=1, transitivity=0, window=1, same_strand=False, canonical=None)#

Initializes attributes of the class and sets up the properties related to the functional units.

Parameters:
  • name (str) – Name of the instance.

  • mandatory (Set[FuncUnit, Family]) – Set of mandatory functional units or families.

  • accessory (Set[FuncUnit, Family]) – Set of accessory functional units or families.

  • forbidden (Set[FuncUnit, Family]) – Set of forbidden functional units or families.

  • neutral (Set[FuncUnit, Family]) – Set of neutral functional units or families.

  • min_mandatory (int) – Minimum number of mandatory functional units required.

  • min_total (int) – Minimum total number of functional elements required.

  • transitivity (int) – Transitivity value for relationships in functional elements.

  • window (int) – Window size used for analysis or traversal.

  • same_strand (bool) – Indicates if the functional units should be on the same strand.

  • canonical (list) – List containing canonical representations.

__repr__()#

Provides a string representation of the object. This method is intended to provide a clear and concise human-readable representation of the object in the form of its class name and name attribute.

Returns:

str – A string containing the class name and the object’s name attribute.

__str__()#

Converts the object representation to its string form.

This method is used to return a string representation of the class instance, primarily for debugging or logging purposes. It includes the name of the class and the value of the name attribute.

Returns:

str – A formatted string containing the class name and the name attribute.

_check()#

Validates the configuration of mandatory and total required elements for a specific type. Ensures that the mandatory elements meet the minimum requirements, both in count and presence, and that the total elements conform to the defined minimum limits.

Raises:
  • Exception – If the number of mandatory elements is lower than the required minimum.

  • Exception – If the number of total elements is lower than the required minimum.

  • Exception – If the minimum mandatory count exceeds the minimum total count.

  • Exception – If no mandatory elements are present.

_child_names(presence=None)#

Retrieves the names of child objects based on their presence status.

Parameters:

presence (str) – A string representing the presence status of child objects to filter (e.g., “active”, “inactive”). If None, retrieves names of all child objects.

Returns:

set – A set containing the names of child objects that match the given presence status, or all child names if presence is None.

_duplicate(filter_type=None)#

Filters and yields child elements based on a specific filter type.

This function allows filtering of child elements according to a specified attribute type, such as ‘mandatory’, ‘accessory’, ‘forbidden’, or ‘neutral’. If no filter type is provided, it selects all available children. It iterates through the filtered children and yields those with a duplicate value of 1 or higher.

Parameters:

filter_type (str) – The type of filter to apply to the children. Acceptable values are ‘mandatory’, ‘accessory’, ‘forbidden’, ‘neutral’, or None. Defaults to None.

Yields:

object

Each child element that matches the filter condition and has a

duplicate value of 1 or higher.

_mk_child_getter()#

Creates a dictionary for retrieving child objects by their names.

This method iterates over the _children attribute and maps each child’s name to the child object itself, storing these key-value pairs in the _child_getter dictionary. This allows efficient access to child objects later based on their names.

add(func_unit)#

Adds a functional unit to one of the sets in the instance based on its presence attribute.

Parameters:

func_unit (FuncUnit) – The functional to be added.

check_model()#

Validates the consistency of a model by invoking an internal check method.

Raises:

Exception – Indicates a failure in model consistency, including the name of the model and the specific error message.

property child_type#

Determines the consistent child type for the instance.

Raises:

Exception – If the child type among children is inconsistent.

Returns:

Any – The consistent child type of the instance.

duplicate_fu(filter_type=None)#

Duplicates items based on the specified filter type.

Parameters:

filter_type (str) – The type of filter to apply for duplicates. If None, no specific filter is applied.

Yields:

Any – The duplicated items obtained from the filtering process.

property families: Generator[Family, None, None]#

Gets a generator that yields Family objects from all functional units.

Yields:

Generator[Family, None, None] – A generator that yields Family objects.

property func_units: Generator[FuncUnit, None, None]#

Retrieves generator of functional units.

Returns:

Generator[FuncUnit, None, None] – A generator yielding functional units from the collection of child elements.

func_units_names(presence)#

Returns the names of child units based on their presence.

Parameters:

presence (str) – The presence status used for filtering child units.

Returns:

Any – A list or collection of child unit names filtered by presence.

get(name)#

Retrieves a function unit by its name.

Parameters:

name (str) – The name of the function unit to be retrieved.

Returns:
  • Union[FuncUnit] – The function unit matching the specified name, or

  • any applicable type derived from FuncUnit.

Return type:

FuncUnit

read(data_model)#

Reads a data model dictionary and initializes or updates the object’s attributes.

Parameters:

data_model (dict) – Dictionary containing the data model information. Must include the mandatory keys ‘name’, ‘parameters’, and ‘func_units’. Optionally, it may include ‘window’ and ‘canonical’ attributes.

static read_model(data_model)#

Reads a data model dictionary and initializes a Model object with it.

Parameters:

data_model (dict) – A dictionary containing the data model to be read.

Returns:

Model – An instance of the Model class populated with the provided data.

Return type:

Model

read_parameters(parameters, param_keys)#

Reads and assigns parameters from a provided dictionary or falls back to parent attributes if the parameter is not found.

Parameters:
  • parameters (Dict[str, Union[str, int, bool]]) – A dictionary containing parameter key-value pairs.

  • param_keys (Set[str]) – A list of keys to be retrieved from the parameters’ dictionary.

property size: Tuple[int, int]#

Returns the size of the current object in terms of functional units and families.

Returns:
  • Tuple[int, int] – A tuple where the first element is the number of

  • functional units, and the second element is the number of families.