biocrnpyler.components.Polymer_transformation

class biocrnpyler.components.Polymer_transformation(partslist, circular=False, parentsdict=None, material_type='dna')[source]

Bases: object

Template for transforming polymer sequences through recombination.

A Polymer_transformation defines a template for creating new polymers from existing ones through recombination reactions. The template specifies a parts list containing placeholders (monomers from input polymers) and new parts (with no parent). This enables complex DNA rearrangements like integration, deletion, and inversion.

Parameters:
  • partslist (list) –

    List of parts defining the output polymer. Can contain:

    • OrderedMonomers from existing polymers (placeholders)

    • Parts with parent=None (inserted into new polymer)

    • Tuples of (part, direction)

  • circular (bool, default False) – Whether the output polymer should be circular.

  • parentsdict (dict, optional) – Dictionary mapping parent polymers to input names (‘input1’, ‘input2’, etc.). If None, automatically generated.

  • material_type (str, default 'dna') – Material type for the created polymer.

Attributes:
  • number_of_inputs (int) – Number of distinct input polymers required.

  • parentsdict (dict) – Mapping from parent polymers to generic input names.

  • partslist (list) – Template parts list with dummy placeholders.

  • circular (bool) – Whether output is circular.

  • material_type (str) – Material type of output polymer.

See also

IntegraseRule

Defines integrase recombination rules.

Integrase_Enumerator

Enumerates integrase products.

OrderedMonomer

Monomer in ordered polymer.

Notes

The transformation works by:

  1. Analyzing partslist to identify parent polymers

  2. Creating generic ‘input#’ placeholders for each parent

  3. Storing template with dummy placeholders

  4. When applied via create_polymer, replacing placeholders with actual parts from input polymers

Placeholder system:

  • Parts from polymers become placeholders referencing position in ‘input#’

  • Parts with parent=None are copied directly into output

  • Complexes bound to parts are transferred to new positions

Examples

Create a simple transformation template:

>>> # Define template: take element 0 from input1, element 2 from
>>> # input2 (reversed), and insert a promoter
>>> template = Polymer_transformation(
...     partslist=[
...         polymer1[0],  # Placeholder for position 0
...         [polymer2[2], 'reverse'],  # Position 2, reversed
...         promoter  # New part (parent=None)
...     ],
...     circular=False
... )
>>> # Apply template to create new polymer
>>> new_polymer = template.create_polymer([polymer1, polymer2])

Integration reaction template:

>>> # Combine two plasmids at cut sites
>>> template = Polymer_transformation(
...     partslist=(
...         plasmid1[:cut1] +
...         [[prod_site1, 'forward']] +
...         plasmid2[cut2+1:] +
...         [[prod_site2, 'forward']] +
...         plasmid1[cut1+1:]
...     ),
...     circular=True
... )

Methods

create_polymer

Create a new polymer from the template using input polymers.

dummify

Create a simplified placeholder polymer.

get_renumbered

Return copy of transformation with output indexes renumbered.

renumber_output

Change the ordering of the output parts list.

reversed

Return circularly permuted version with rotated inputs.

create_polymer(polymer_list, **kwargs)[source]

Create a new polymer from the template using input polymers.

Applies the transformation template to concrete input polymers, replacing placeholders with actual parts and inserting new parts.

Parameters:
  • polymer_list (list of Polymer) – List of input polymers. Must have at least number_of_inputs polymers. Order matters: first polymer is ‘input1’, second is ‘input2’, etc.

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

Returns:

New polymer created by applying the transformation. Type matches the input polymers’ class.

Return type:

Polymer

Notes

Transformation process:

  1. Map polymer_list to ‘input#’ names

  2. For each template part:

    • If placeholder: grab part from appropriate input polymer at specified position

    • If new part: insert the part or its dna_species

    • Handle complex species bound to parts

  3. Create output polymer with specified circularity

When transforming parts with bound complexes, the method attempts to preserve bindings by replacing core parts within complexes.

classmethod dummify(in_polymer, name)[source]

Create a simplified placeholder polymer.

Generates a generic polymer with the same structure (length, directions, circularity) as the input but without specific parts. Used for creating template placeholders.

Parameters:
  • in_polymer (Polymer) – The polymer to simplify.

  • name (str) – Name for the dummy polymer (e.g., ‘input1’).

Returns:

Simplified polymer with generic OrderedMonomers at each position.

Return type:

NamedPolymer

Notes

The dummy polymer preserves only structural information (number of monomers, their directions, and circularity) while removing specific part identities.

get_renumbered(output_renumbering_function)[source]

Return copy of transformation with output indexes renumbered.

Parameters:

output_renumbering_function (callable) – Function mapping old indexes to (new_index, direction) tuples.

Returns:

Copy of this transformation with renumbered output.

Return type:

Polymer_transformation

renumber_output(output_renumbering_function)[source]

Change the ordering of the output parts list.

Applies a renumbering function to rearrange the parts in the template, useful for handling circular permutations or reversals.

Parameters:

output_renumbering_function (callable) – Function that takes an index (int) and returns tuple of (new_index, direction), where direction is ‘f’ (forward) or ‘r’ (reverse).

Notes

Modifies self.partslist in place. Used to adjust transformations when matching against existing constructs.

reversed()[source]

Return circularly permuted version with rotated inputs.

Creates a new transformation where inputs are shuffled: input1 becomes input2, input2 becomes input3, …, last input becomes input1. Used for handling symmetric integrase reactions.

Returns:

New transformation with rotated input assignments.

Return type:

Polymer_transformation

Notes

For single-input transformations, returns self unchanged. Essential for bidirectional integrase reactions where site1/site2 roles can be swapped.