FuncUnit#

class panorama.systems.models.FuncUnit(name='', presence='', mandatory=None, accessory=None, forbidden=None, neutral=None, min_mandatory=1, min_total=1, same_strand=False, transitivity=0, window=1, duplicate=0, model=None, exchangeable=None, multi_system=False, multi_model=False)#

Bases: _BasicFeatures, _FuFamFeatures, _ModFuFeatures

Represents a Functional Unit class that models functional and operational parameters, structural constraints, and various functional units and families. This class provides utilities to manage functional units, their relationships, and interactions.

This class is designed to encapsulate features essential for analyzing and validating relationships between functional sub-elements, families, and systems. It defines the functional unit’s behaviors, attributes, and operations.

name#

Name of the functional unit.

Type:

str

presence#

Defines the presence rule (mandatory, accessory, forbidden, or neutral).

Type:

str

mandatory#

Set of mandatory sub-elements.

Type:

Set[FuncUnit, Family]

accessory#

Set of accessory sub-elements.

Type:

Set[FuncUnit, Family]

forbidden#

Set of forbidden sub-elements.

Type:

Set[FuncUnit, Family]

neutral#

Set of neutral sub-elements.

Type:

Set[FuncUnit, Family]

min_mandatory#

Minimum number of mandatory sub-elements.

Type:

int

min_total#

Minimum number of total sub-elements.

Type:

int

same_strand#

Specifies if sub-elements must be on the same strand.

Type:

bool

transitivity#

Size of the transitive closure used to build the graph.

Type:

int

window#

Number of neighboring genes considered in genomic searches.

Type:

int

duplicate#

Number of duplicates allowed.

Type:

int

exchangeable#

List of exchangeable families.

Type:

Set[str]

multi_system#

Flag indicating if the unit can span multiple systems.

Type:

bool

multi_model#

Flag indicating if the unit can span multiple models.

Type:

bool

__init__(name='', presence='', mandatory=None, accessory=None, forbidden=None, neutral=None, min_mandatory=1, min_total=1, same_strand=False, transitivity=0, window=1, duplicate=0, model=None, exchangeable=None, multi_system=False, multi_model=False)#

Initializes an instance of a class with defined attributes, including functional, operational parameters, and structural constraints. This constructor manages various functionalities and initializes a robust system by leveraging functional units, families, and other attributes.

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

  • presence (str) – Defines the presence rule (mandatory, accessory, forbidden, or neutral).

  • mandatory (Set[FuncUnit, Family]) – Set of mandatory sub-elements.

  • accessory (Set[FuncUnit, Family]) – Set of accessory sub-elements.

  • forbidden (Set[FuncUnit, Family]) – Set of forbidden sub-elements.

  • neutral (Set[FuncUnit, Family]) – Set of neutral sub-elements.

  • min_mandatory (int) – Minimum number of mandatory sub-elements.

  • min_total (int) – Minimum number of total sub-elements.

  • same_strand (bool) – Specifies if sub-elements must be on the same strand.

  • transitivity (int) – Size of the transitive closure used to build the graph.

  • window (int) – Number of neighboring genes considered in genomic searches.

  • duplicate (int) – Number of duplicates allowed.

  • model (Model) – Model in which the functional unit is defined.

  • exchangeable (Set[str]) – List of exchangeable families.

  • multi_system (bool) – Flag indicating if the unit can span multiple systems.

  • multi_model (bool) – Flag indicating if the unit can span multiple models.

__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(family)#

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

Parameters:

family (Family) – The functional to be added.

check_func_unit()#

Check functional unit consistency.

Raises:

Exception – If the functional unit is not consistent.

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_fam(filter_type=None)#

Generates items based on the specified filter type, if provided. This method uses an internal mechanism to yield results that match the filtering criteria.

Parameters:

filter_type (str) – The type of filter to apply. If None, no filtering is applied and all items are yielded.

Yields:

Any – Items matching the filter criteria.

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

Yields Family objects contained in the current object’s children.

Yields:

Generator[Family, None, None] – A generator producing Family objects.

families_names(presence=None)#

Returns a filtered list of family names based on the provided presence criteria.

Parameters:

presence (str) – Filter criteria for the presence of family members. Defaults to None.

Returns:

list – A list of names matching the given presence criteria.

get(name)#

Retrieves an instance of the ‘Family’ class using the provided name.

Parameters:

name (str) – The name of the ‘Family’ instance to retrieve.

Returns:

Union[Family] – The retrieved ‘Family’ instance.

Return type:

Family

property model: Model#

Retrieves the parent model associated with this instance.

Returns:

Model – The parent model object.

read(data_fu)#

Read functional unit.

Parameters:

data_fu (dict) – Data JSON file of all functional units.

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: int#

Gets the size of the collection of families.

The size property calculates and returns the total number of families present in the collection.

Returns:

int – The total number of families in the collection.