biocrnpyler.components.Integrase_Enumerator

class biocrnpyler.components.Integrase_Enumerator(name: str, int_mechanisms=None)[source]

Bases: GlobalComponentEnumerator

Global enumerator for integrase-mediated DNA recombination products.

An Integrase_Enumerator systematically enumerates all possible DNA constructs that can result from integrase-mediated recombination reactions. Examines all components for integrase attachment sites and generates products for all allowed site pairs.

Parameters:
  • name (str) – Name identifier for the enumerator.

  • int_mechanisms (dict, optional) – Dictionary mapping integrase names (str) to IntegraseRule objects. Default: {‘int1’: IntegraseRule()}

Attributes:

int_mechanisms (dict) – Dictionary of integrase rules.

See also

GlobalComponentEnumerator

Base class for global enumeration.

IntegraseRule

Defines integrase recombination rules.

IntegraseSite

DNA part for attachment sites.

Polymer_transformation

Template for DNA rearrangements.

Notes

Enumeration process:

  1. Identify all integrase attachment sites in components

  2. Group sites by integrase type

  3. For each integrase:

    1. Find all valid site pairs (from reactive_sites)

    2. Check if pair can react (reaction_allowed)

    3. Perform integration to generate products

    4. Store transformation templates in sites

  4. Return list of new DNA constructs

This is a global enumerator because integrase reactions can occur between sites on different constructs (intermolecular reactions). Access to all components is necessary.

Integrase Types Supported:

  • Serine integrases (attB/attP \(\rightarrow\) attL/attR)

  • Tyrosine recombinases (Cre, Flp with homotypic sites)

  • Invertases (inversion only)

  • Resolvases (deletion only)

  • Custom integrase rules

The find_dna_construct method is used to detect duplicates including circular permutations and reversals, preventing redundant construct generation.

Examples

Create an integrase enumerator:

>>> phi_c31 = bcp.IntegraseRule(
...     name='PhiC31',
...     reactions={
...         ('attB', 'attP'): 'attL',
...         ('attP', 'attB'): 'attR'
...     }
... )
>>> enumerator = bcp.Integrase_Enumerator(
...     name='integrase_enum',
...     int_mechanisms={'PhiC31': phi_c31}
... )

Use in a mixture:

>>> mixture = bcp.Mixture(
...     components=[plasmid1, plasmid2],
...     global_component_enumerators=[enumerator]
... )
>>> # Enumerator automatically called during compilation
>>> crn = mixture.compile_crn()

Manual enumeration:

>>> constructs = [plasmid_with_attB, plasmid_with_attP]
>>> new_constructs = enumerator.enumerate_components(constructs)
>>> # new_constructs contains integrated plasmids

Methods

enumerate_components

Enumerate all possible integrase-mediated DNA configurations.

find_dna_construct

Find matching construct in list (handles permutations/reversals).

list_integrase

List all integrase attachment sites in a construct.

reset

Reset linked_sites attribute in all attachment sites.

enumerate_components(components=None, previously_enumerated=None, **kwargs)[source]

Enumerate all possible integrase-mediated DNA configurations.

Systematically generates all DNA constructs that can result from integrase recombination between attachment sites in the input components.

Parameters:
  • components (list of Component, optional) – List of components to enumerate. Only DNA_construct objects are processed.

  • previously_enumerated (list of Component, optional) – List of components already enumerated (used for duplicate detection).

  • **kwargs – Additional keyword arguments (unused).

Returns:

List of newly created DNA constructs from all allowed integrase reactions.

Return type:

list of Construct

Notes

Enumeration algorithm:

  1. Extract all DNA_construct components

  2. List all integrase sites by integrase type

  3. For each integrase in int_mechanisms:

    1. Get all attachment sites for that integrase

    2. Find reactive site types from IntegraseRule

    3. Generate all site pairs (combinations)

    4. For each valid pair:

      • Check if reaction_allowed

      • Perform integrate to generate products

      • Add new constructs to output list

  4. Return all newly generated constructs

Depending on the IntegraseRule settings, the following reaction types are generated:

  • Inversions (same construct, opposite directions)

  • Deletions (same construct, same direction)

  • Integrations (different constructs, at least one circular)

  • Recombinations (two linear constructs)

The integrate method checks existing_dna_constructs (includes both previously_enumerated and newly created constructs) to avoid generating duplicates.

Examples

Enumerate integration products:

>>> enumerator = bcp.Integrase_Enumerator(
...     name='enum',
...     int_mechanisms={'PhiC31': phi_c31_rule}
... )
>>> plasmids = [donor_plasmid, target_plasmid]
>>> products = enumerator.enumerate_components(plasmids)
>>> # products contains integrated plasmids
classmethod find_dna_construct(construct: Construct, conlist: List[Construct])[source]

Find matching construct in list (handles permutations/reversals).

Searches for a construct equivalent to the input, accounting for circular permutations and reversals.

Parameters:
  • construct (Construct) – Construct to find.

  • conlist (list of Construct) – List of constructs to search.

Returns:

If found: (matched_construct, index_function), where index_function maps old indexes to (new_index, direction). If not found: None.

Return type:

tuple of (Construct, callable) or None

Raises:

KeyError – If construct matches multiple constructs in list (should not happen with proper generation order).

Notes

For circular constructs, the following matching logic is used:

  • Try all circular permutations

  • For each permutation, try forward and reverse orientations

For linear constructs, the following matching logic is used:

  • Try forward orientation

  • Try reverse orientation

Uses directionless_hash for fast initial filtering before detailed species comparison.

list_integrase(construct)[source]

List all integrase attachment sites in a construct.

Parameters:

construct (Construct) – DNA construct to examine.

Returns:

Dictionary mapping integrase names (str) to lists of IntegraseSite objects.

Return type:

dict

reset(components=None, **kwargs)[source]

Reset linked_sites attribute in all attachment sites.

Clears stored integration reactions from all integrase sites in components, preparing for fresh enumeration.

Parameters:
  • components (list of Component) – Components containing integrase sites to reset.

  • **kwargs – Additional keyword arguments (unused).

Notes

Called at the start of enumeration to clear previous integration data.