biocrnpyler.components.dna.RNA_construct
- class biocrnpyler.components.dna.RNA_construct(parts_list, name=None, promoter=None, component_enumerators=None, length=0, **kwargs)[source]
-
RNA construct representing a functional transcript.
An RNA construct represents an RNA molecule that can be translated into proteins. Unlike DNA constructs, RNA constructs can only be linear (not circular) and primarily support translation rather than transcription. This class uses the ‘translation’ mechanism to generate protein products and related species/reactions during CRN compilation.
- Parameters:
parts_list (
listoflist) – List of parts in format [[part, direction], …] where parts represent functional RNA elements (RBS sites, coding sequences, etc.).name (
str, optional) – Name of the RNA construct. If None, automatically generated.promoter (
Promoter, optional) – Reference to the promoter that produced this RNA transcript.component_enumerators (
list, optional) – List of enumerators for generating construct variants. Defaults to [TlExplorer()] which explores translational variants.length (
int, default0) – Length of the RNA molecule in nucleotides.**kwargs – Additional keyword arguments passed to parent constructors.
- Attributes:
material_type (
str) – Always ‘rna’ for RNA constructs.promoter (
PromoterorNone) – The promoter that controls transcription of this RNA.length (
int) – Length of the RNA transcript.circular (
bool) – Always False for RNA (RNA cannot be circular).
See also
ConstructBase class for all constructs.
DNA_constructDNA version of constructs.
TlExplorerDefault enumerator for translational exploration.
RNABase class for RNA components.
Notes
RNA_constructs have several key characteristics:
Linear only: RNA molecules cannot be circular
Translation focus: Primarily generates protein products through translation mechanisms
RBS enumeration: Automatically identifies all ribosome binding sites and potential translation products
No transcription: RNA cannot be transcribed to produce other RNA
The default TlExplorer enumerator automatically explores all possible translational units in the RNA construct based on RBS positions.
Examples
Create an mRNA with RBS and coding sequence:
>>> rbs1 = bcp.RBS('RBS1') >>> cds1 = bcp.CDS('GFP') >>> parts = [[rbs1, 'forward'], [cds1, 'forward']] >>> mrna = bcp.RNA_construct( ... parts_list=parts, ... name='mRNA_GFP' ... )
Create a polycistronic mRNA with multiple RBS-CDS pairs:
>>> rbs2 = bcp.RBS('RBS2') >>> cds2 = bcp.CDS('RFP') >>> strong_promoter = bcp.Promoter('pstrong') >>> parts = [ ... [rbs1, 'forward'], [cds1, 'forward'], ... [rbs2, 'forward'], [cds2, 'forward'] ... ] >>> polycistronic = bcp.RNA_construct( ... parts_list=parts, ... name='mRNA_operon', ... promoter=strong_promoter ... )
Methods
Add a single attribute to the component.
Add a mechanism to the construct and all its parts.
Add multiple mechanisms to this component.
Add a monomer to the end of the polymer.
Handle construct changes by resetting caches and updating name.
Generate components for all combinatorial binding states.
Create a reversed construct without computing its hash.
Remove a monomer from the polymer at a specific position.
Invert a direction value.
Compute the best hash considering both rotation and direction.
Generate all derived components and constructs from this construct.
Run all enumerators to generate new construct variants.
Create a circularly permuted version of this construct.
Retrieve a mechanism by type from the component or its mixture.
Retrieve parameter from component or mixture parameter database.
Find and return a part from the construct by various criteria.
Generate a hash string for an ordered list of parts.
Generate a string identifier for a part including its direction.
Create a deep copy of the construct with reversed orientation.
Returns species of DNA construct, using OrderedPolymerSpecies.
Insert a monomer at a specific position in the polymer.
Compute the best hash for a linear construct in either direction.
Generate all combinatorial placement dictionaries for species.
Generate a systematic name for the construct based on its parts.
Create polymer species from combinatorial binding combinations.
Compute a canonical hash for the construct.
Replace a monomer at a specific position in the polymer.
Clear all cached enumeration and prediction data.
Reverse the construct without modifying the underlying DNA.
Compute the most alphabetically ordered circular permutation hash.
Set multiple attributes for the component.
Set the mixture containing this construct and all its parts.
Convert various inputs into Species objects.
Update the base species representation of this construct.
Generate all combinatorial binding state species for the construct.
Update parameters for the construct and all its parts.
Update the direction-independent hash for this construct.
Generate reactions for the construct.
Generate species for the construct.
- __contains__(obj2)[source]
Check if the construct contains a specific part.
Tests whether a DNA_part or copy of a DNA_part exists in this construct’s parts list.
- Parameters:
obj2 (
DNA_part) – The part to search for in the construct.- Returns:
True if the part (or a copy with the same name and type) is in the construct, False otherwise.
- Return type:
bool
Notes
This method supports two types of containment checks:
Direct membership: The exact part object is in the construct (checked via
obj2.parent == self)Copy membership: A different part object with the same type and name exists in the construct
Examples
Check if construct contains a part:
>>> promoter = bcp.Promoter('ptet') >>> rbs = bcp.RBS('RBS_standard') >>> cds = bcp.CDS('GFP') >>> parts = [ ... [promoter, 'forward'], [rbs, 'forward'], [cds, 'forward'] ... ] >>> construct = bcp.Construct( ... parts_list=parts, ... name='gene_circuit' ... ) >>> promoter in construct True
>>> unknown_part = bcp.Promoter('plac') >>> unknown_part in construct False
- __eq__(construct2)[source]
Test equality between two constructs.
Two constructs are considered equal if they have the same string representation and the same name.
- Parameters:
construct2 (
Construct) – The other construct to compare with.- Returns:
True if constructs are equal, False otherwise.
- Return type:
bool
Notes
This is a simple equality test based on string representation. It does not use deep comparison of parts or the direction-independent hash. For more sophisticated equivalence testing that accounts for rotations and reversals, use the
omnihashmethod.See also
omnihashCompute canonical hash accounting for rotation and direction.
- __getitem__(ii)[source]
Get a monomer or slice of monomers from the polymer.
- Parameters:
ii (
intorslice) – Index or slice to retrieve from the polymer.- Returns:
The monomer at the given index, or a tuple of monomers for a slice.
- Return type:
OrderedMonomerortuple
- __len__()[source]
Return the number of monomers in the polymer.
- Returns:
The number of monomers in the polymer sequence.
- Return type:
int
- __setitem__(ii, val)[source]
Replace a monomer at a specific position.
- Parameters:
ii (
int) – Index at which to replace the monomer.val (
OrderedMonomer) – The new monomer to insert at the position.
Notes
Internally calls
replacewith the monomer’s existing direction.
- add_attribute(attribute: str)[source]
Add a single attribute to the component.
Adds an attribute tag to the component’s attribute list and to its associated species object, if one exists. Attributes can be used for mechanism selection, species filtering, and tracking special properties.
- Parameters:
attribute (
str) – Attribute string to add to the component. Must be a non-None string value.- Raises:
AssertionError – If
attributeis not a string or is None.Warning – If the component has no internal species to which the attribute can be added.
Notes
Attributes are commonly used to tag components with properties such as:
Degradation tags (e.g., ‘degtagged’, ‘ssrAtagged’, )
Functional properties (e.g., ‘fluorescent’, ‘membranebound’)
Regulatory elements (e.g., ‘inducible’, ‘repressible’)
Examples
Add attributes to tag a protein with special properties:
>>> protein = bcp.Protein('GFP') >>> protein.add_attribute('fluorescent') >>> protein.add_attribute('ssrAtagged') >>> protein.attributes ['fluorescent', 'ssrAtagged']
- add_mechanism(mechanism, mech_type=None, overwrite=False, optional_mechanism=False)[source]
Add a mechanism to the construct and all its parts.
Adds the mechanism to the construct’s mechanism dictionary and propagates it to all parts in the construct.
- Parameters:
mechanism (
Mechanism) – The mechanism object to add.mech_type (
str, optional) – The mechanism type key. If None, uses the mechanism’smechanism_typeattribute.overwrite (
bool, defaultFalse) – If True, overwrites existing mechanisms with the same type. If False, raises ValueError for duplicate types.optional_mechanism (
bool, defaultFalse) – If True, suppresses ValueError when a mechanism key conflict occurs andoverwriteis False.
Notes
This method:
Adds the mechanism to the construct via the parent Component class
Propagates the mechanism to each part in the construct
This ensures mechanism consistency across the entire construct.
- add_mechanisms(mechanisms: Mechanism | GlobalMechanism, overwrite=False, optional_mechanism=False)[source]
Add multiple mechanisms to this component.
Accepts mechanisms as a single object, list, or dictionary and adds them to the component’s mechanism dictionary.
- Parameters:
mechanisms (
Mechanism,GlobalMechanism,dict, orlist) – The mechanism(s) to add. Can be a single mechanism, a dict with mechanism types as keys and mechanisms as values, or a list of mechanisms.overwrite (
bool, defaultFalse) – If True, replaces any existing mechanisms with the same keys. If False, raises ValueError when keys already exist.optional_mechanism (
bool, defaultFalse) – If True, suppresses ValueError when mechanism key conflicts occur andoverwriteis False.
- Raises:
ValueError – If
mechanismsis not a valid type, or if mechanism key conflicts occur withoverwrite=Falseandoptional_mechanism=False.
- append(part, direction=None)[source]
Add a monomer to the end of the polymer.
Appends a copy of the given monomer to the end of the polymer sequence by calling
insertat the final position.- Parameters:
part (
OrderedMonomer) – The monomer to append. A copy of this monomer will be added.direction (
str,int, orNone, optional) – Direction for the appended monomer. If None, uses the monomer’s existing direction if available.
See also
insertInsert a monomer at a specific position.
Examples
>>> polymer = bcp.OrderedPolymer(parts=[]) >>> mon = bcp.OrderedMonomer() >>> polymer.append(mon, direction='forward') >>> len(polymer) 1
- changed()[source]
Handle construct changes by resetting caches and updating name.
Called when the construct has been modified, this method resets all cached data and regenerates the construct’s name to reflect its current state.
Notes
This method performs two operations:
Resets all cached enumeration and prediction data via
reset_stored_dataRegenerates the construct name via
make_nameto ensure it reflects the current parts configuration
This should be called after any structural modification to the construct.
- combinatorial_enumeration()[source]
Generate components for all combinatorial binding states.
Creates copies of parts that can react with different combinatorial binding states of the construct, ensuring reactions are generated for all possible binding configurations.
- Returns:
Components configured to react with different combinatorial binding states of the construct.
- Return type:
listofComponent
Notes
This method handles the generation of components that account for multiple simultaneous binding events. For example, given construct
<A,B,C>where both A and B can bind RNAP:Binary complexes:
<[A:RNAP],B,C>and<A,[B:RNAP],C>Combinatorial complex:
<[A:RNAP],[B:RNAP],C>
The method returns multiple versions of components A and B, each configured to bind to different pre-existing binding states:
A component binding to
<A,B,C>\(\rightarrow\)<[A:RNAP],B,C>A component binding to
<A,[B:RNAP],C>\(\rightarrow\)<[A:RNAP],[B:RNAP],C>B component binding to
<A,B,C>\(\rightarrow\)<A,[B:RNAP],C>B component binding to
<[A:RNAP],B,C>\(\rightarrow\)<[A:RNAP],[B:RNAP],C>
This ensures proper reaction enumeration for all binding combinations.
- property compartment
The compartment containing this component.
- Type:
Compartment or None
- classmethod create_hashless_reverse(construct)[source]
Create a reversed construct without computing its hash.
Generates a reversed version of the construct with parts in reverse order and flipped directions, but skips hash computation to avoid infinite recursion during hash calculations.
- Parameters:
construct (
Construct) – The construct to reverse.- Returns:
A new construct with reversed parts order and flipped directions, with
make_dirless_hash=Falseto prevent hash computation.- Return type:
Notes
This method is used internally by hash computation routines that need to compare forward and reverse orientations. Setting
make_dirless_hash=Falseprevents infinite loops where hash computation would trigger reverse computation, which would trigger hash computation, etc.The circularity status of the construct is preserved.
- delpart(position)[source]
Remove a monomer from the polymer at a specific position.
Removes the monomer at the given position, shifts all subsequent monomers to lower positions, and calls the
changedcallback.- Parameters:
position (
int) – Index of the monomer to remove. Must be a valid position in the polymer.
See also
Notes
The removed monomer’s
removemethod is called to clear its parent, position, and direction. If the polymer has anameattribute and amake_namemethod, the name is regenerated after deletion.
- direction_invert(dirname)[source]
Invert a direction value.
Converts a direction to its opposite orientation. Used during polymer reversal operations.
- Parameters:
dirname (
str,int, orNone) –The direction to invert. Supported values:
’forward’ \(\rightleftharpoons\) ‘reverse’
0 \(\rightleftharpoons\) 1
None -> None
- Returns:
The inverted direction. Returns the input unchanged if it cannot be inverted.
- Return type:
str,int, orNone- Warns:
UserWarning – If the direction value is not recognized.
Examples
>>> polymer = bcp.OrderedPolymer(parts=[]) >>> polymer.direction_invert('forward') 'reverse' >>> polymer.direction_invert(0) 1
- classmethod direction_rotation_free_hash(construct)[source]
Compute the best hash considering both rotation and direction.
Finds the most alphabetically ordered representation of a circular construct by evaluating all rotations in both forward and reverse orientations.
- Parameters:
construct (
Construct) – The circular construct to hash.- Returns:
hash (
str) – String hash of the most alphabetically ordered permutation in either direction.direction (
int) – Direction of the best ordering: 1 for forward, -1 for reverse.first_position (
int) – The position that should be used as the first position in the best permutation.
Notes
This method:
Computes the best forward rotation using
rotation_free_hashCreates a reversed construct and computes its best rotation
Returns whichever produces the more alphabetically ordered hash
To recreate the canonical form:
If direction is -1, reverse the construct
Rotate to start at
first_position
This provides complete normalization for circular constructs, accounting for both rotation and direction symmetries.
- enumerate_components(previously_enumerated=None)[source]
Generate all derived components and constructs from this construct.
Combines both construct enumeration (e.g., transcripts) and combinatorial component enumeration (for binding states) to produce a complete set of derived components.
- Parameters:
previously_enumerated (
setorlist, optional) – Collection of components already enumerated, used to prevent infinite recursion.- Returns:
All new components and constructs generated, including:
New constructs from enumerators (e.g., RNA_constructs)
Components for combinatorial binding states
- Return type:
listofComponent
Notes
This method generates new components in two scenarios:
Binding-induced species: When a component creates a species that binds to part of the construct. For example,
<A,B,C>\(\rightarrow\)<[A:RNAP],B,C>would return component A configured for this binding.Combinatorial binding states: When multiple components can bind simultaneously. For construct
<A,B,C>where both A and B can bind RNAP:Binary species:
<[A:RNAP],B,C>and<A,[B:RNAP],C>Combinatorial:
<[A:RNAP],[B:RNAP],C>
Returns components A and B configured to bind to various pre-bound states, ensuring all binding combinations are enumerated.
New constructs: Generated by
enumerate_constructs(). For example, a DNA_construct with promoter A generates an RNA_construct containing<B,C>.
- enumerate_constructs(previously_enumerated=None)[source]
Run all enumerators to generate new construct variants.
Applies all component enumerators to this construct to generate derived constructs (e.g., RNA_constructs from transcription).
- Parameters:
previously_enumerated (
setorlist, optional) – Collection of constructs that have already been enumerated, used to prevent infinite recursion and duplicate enumeration.- Returns:
New constructs generated by all enumerators. For DNA_constructs with the default TxExplorer, this includes all possible RNA_construct transcripts.
- Return type:
listofConstruct
Notes
Each enumerator’s
enumerate_componentsmethod is called with this construct and the previously enumerated set, allowing enumerators to explore transcriptional units, translational products, or other construct-derived components.See also
TxExplorerDefault enumerator for DNA transcription exploration.
TlExplorerDefault enumerator for RNA translation exploration.
- get_circularly_permuted(new_first_position)[source]
Create a circularly permuted version of this construct.
Returns a new construct where the circular ordering of parts starts at a different position. Only valid for circular constructs.
- Parameters:
new_first_position (
int) – The index of the part that should become the first position in the new construct.- Returns:
A new circular DNA_construct with parts reordered starting from the specified position.
- Return type:
- Raises:
ValueError – If the construct is linear (circular permutation only applies to circular constructs).
Notes
The parts list is rotated so that
parts_list[new_first_position]becomes the new first element, maintaining the circular structure.Examples
Permute a circular plasmid:
>>> ori = bcp.DNA_part('p15A') >>> promoter = bcp.Promoter('ptet') >>> cds = bcp.CDS('GFP') >>> plasmid = bcp.DNA_construct( ... [[ori, 'forward'], [promoter, 'forward'], [cds, 'forward']], ... circular=True ... ) >>> plasmid DNA_construct = p15A_ptet_GFP_o >>> plasmid.get_circularly_permuted(1) DNA_construct = ptet_GFP_p15A_o
- get_mechanism(mechanism_type, optional_mechanism=False)[source]
Retrieve a mechanism by type from the component or its mixture.
Searches first in the component’s mechanism dictionary, then falls back to the mixture’s mechanisms if not found.
- Parameters:
mechanism_type (
str) – The type identifier of the mechanism to retrieve (e.g., ‘transcription’, ‘translation’, ‘binding’).optional_mechanism (
bool, defaultFalse) – If True, returns None when mechanism not found. If False, raises KeyError when mechanism not found.
- Returns:
The requested mechanism object, or None if not found and
optional_mechanismis True.- Return type:
MechanismorNone- Raises:
TypeError – If
mechanism_typeis not a string.KeyError – If mechanism not found and
optional_mechanismis False.
- get_parameter(param_name: str, part_id=None, mechanism=None, return_numerical=False, return_none=False, check_mixture=True) Parameter | Real[source]
Retrieve parameter from component or mixture parameter database.
Searches first in the component’s parameter database, then falls back to the mixture’s parameter database if not found.
- Parameters:
param_name (
str) – Name of the parameter to retrieve.part_id (
str, optional) – Part identifier for the parameter lookup key.mechanism (
str, optional) – Mechanism identifier for the parameter lookup key.return_numerical (
bool, defaultFalse) – If True, returns the numerical value. If False, returns theParameterobject.return_none (
bool, defaultFalse) – If True, returns None when parameter not found. If False, raises ValueError when parameter not found.check_mixture (
bool, defaultTrue) – If True, searches the mixture’s parameter database if not found in the component’s database.
- Returns:
The parameter object or its numerical value, or None if not found and
return_noneis True.- Return type:
Parameter,Real, orNone- Raises:
ValueError – If parameter not found and
return_noneis False.
Notes
Parameter lookup follows the hierarchy:
Component.parameter_database
Component.mixture.parameter_database (if
check_mixtureis True)
- get_part(part=None, part_type=None, name=None, index=None)[source]
Find and return a part from the construct by various criteria.
Searches the construct’s parts list for a part matching the given criteria. Only one search criterion should be provided at a time.
- Parameters:
part (
DNA_part, optional) – A specific DNA_part instance to find. Matches both type and name.part_type (
type, optional) – Find all parts that are instances of this type (e.g., Promoter).name (
str, optional) – Find part(s) with this exact name.index (
int, optional) – Return the part at this position in parts_list.
- Returns:
Single matching part if exactly one match found. List of parts if multiple matches found. None if no matches found.
- Return type:
- Raises:
ValueError – If multiple search criteria are provided simultaneously, or if invalid types are provided for parameters.
- Warns:
UserWarning – If multiple matching parts are found (returns list).
Notes
The search is performed with the following priority:
Index (direct lookup)
Part instance (type and name must match)
Name (string match)
Type (isinstance check)
Only one search criterion should be provided at a time.
Examples
Find a part by name:
>>> promoter = bcp.Promoter('ptet') >>> rbs = bcp.RBS('RBS_standard') >>> cds = bcp.CDS('GFP') >>> parts = [ ... [promoter, 'forward'], [rbs, 'forward'], [cds, 'forward'] ... ] >>> construct = bcp.Construct( ... parts_list=parts, ... name='gene_circuit', ... circular=False ... ) >>> promoter = construct.get_part(name='ptet')
Get the third part in the construct:
>>> third_part = construct.get_part(index=2)
Find all RBS parts:
>>> all_rbs = construct.get_part(part_type=bcp.RBS)
- classmethod get_partlist_hash(partlist)[source]
Generate a hash string for an ordered list of parts.
Creates a unique string identifier for a parts list by concatenating part names with position indices, capturing the order and content of parts (but not their absolute positions).
- Parameters:
partlist (
list) – List of (part_string, part) tuples where part_string is typically generated byget_partstring.- Returns:
Hash string representing the ordered parts list.
- Return type:
str
Notes
The hash format concatenates each part’s string representation with its index in the list, separated by underscores. This creates a unique identifier for the parts sequence.
- classmethod get_partstring(part)[source]
Generate a string identifier for a part including its direction.
Creates a unique string representation of a part that includes its name and direction but not its position, useful for construct comparison.
- Parameters:
part (
DNA_partorOrderedMonomer) – The part to generate a string identifier for.- Returns:
String combining the part’s name and direction (e.g., ‘promoter_pLacforward’ or ‘gene_GFPreverse’).
- Return type:
str
Notes
This method creates an “orphan” copy of the part (without position or direction) to get the base name, then appends the direction to create a direction-aware identifier.
- get_reversed()[source]
Create a deep copy of the construct with reversed orientation.
Returns a new construct that is the reverse complement of this construct, with all parts in reverse order and flipped directions. The original construct is not modified.
- Returns:
A new construct object with reversed parts and directions.
- Return type:
See also
reverseReverse the construct in place.
Examples
Get reversed version without modifying original:
>>> promoter = bcp.Promoter('ptet') >>> cds = bcp.CDS('GFP') >>> original = bcp.Construct( ... [[promoter, 'forward'], [cds, 'forward']]) >>> original.get_reversed() Construct = GFP_r_ptet_r
- insert(position, part, direction=None)[source]
Insert a monomer at a specific position in the polymer.
Inserts a copy of the given monomer at the specified position, shifting all subsequent monomers to higher positions. Calls the
changedcallback after insertion.- Parameters:
position (
int) – Index at which to insert the monomer. Must be between 0 andlen(polymer)(inclusive).part (
OrderedMonomer) – The monomer to insert. A copy of this monomer will be added.direction (
str,int, orNone, optional) – Direction for the inserted monomer. If None, uses the monomer’s existing direction.
See also
Notes
The monomer is deep-copied before insertion to maintain independence from the original object.
- classmethod linear_direction_free_hash(construct)[source]
Compute the best hash for a linear construct in either direction.
Determines which orientation (forward or reverse) produces the most alphabetically ordered sequence for a linear construct.
- Parameters:
construct (
Construct) – The linear construct to hash.- Returns:
hash (
str) – String hash of the most alphabetically ordered orientation.direction (
int) – Direction of the best ordering: 1 for forward, -1 for reverse.first_position (
int) – Always 0 for linear constructs (no circular permutation).
Notes
This method compares forward and reverse orientations part-by-part, stopping as soon as one orientation is determined to be more alphabetically ordered than the other.
To recreate the canonical form:
If direction is -1, reverse the construct
Start at position 0 (always the first position for linear constructs)
Unlike circular constructs, linear constructs have a defined start and end, so the first_position is always 0.
- located_allcomb(spec_list)[source]
Generate all combinatorial placement dictionaries for species.
Creates all possible combinations of species placements when multiple species can bind at different positions in the construct.
- Parameters:
spec_list (
listofSpecies) – List of species that have position attributes, typically ComplexSpecies that can bind at specific locations.- Returns:
List of dictionaries where each dict maps positions (int) to [species, direction] pairs representing one possible combinatorial binding state.
- Return type:
listofdict
Notes
This method handles the combinatorics of placing multiple binding species at different positions. For example:
Species A binds at position 0
Species B binds at position 3
Species C also binds at position 0
The method generates all valid combinations:
{0: [A, direction]},{0: [C, direction]},{0: [A, direction], 3: [B, direction]},{0: [C, direction], 3: [B, direction]}, etc.The algorithm:
Extracts positions from spec_list
Groups species by position into prototype_list
Generates all position combinations via all_comb
For each position combination, generates all possible species selections at those positions
- make_name()[source]
Generate a systematic name for the construct based on its parts.
Creates a name by concatenating all part names with underscores. Parts in reverse orientation are suffixed with ‘_r’, and circular constructs are suffixed with ‘_o’.
- Returns:
The generated construct name.
- Return type:
str
Examples
Linear construct with forward parts:
>>> promoter = bcp.Promoter('pLac') >>> rbs = bcp.CDS('RBS1') >>> cds = bcp.CDS('GFP') >>> construct = bcp.DNA_construct( ... [[promoter, 'forward'], [rbs, 'forward'], [cds, 'forward']] ... ) >>> construct.make_name() 'pLac_RBS1_GFP'
Linear construct with reversed part:
>>> construct = bcp.DNA_construct( ... [[promoter, 'forward'], [rbs, 'reverse'], [cds, 'forward']] ... ) >>> construct.make_name() 'pLac_RBS1_r_GFP'
Circular construct:
>>> construct = bcp.DNA_construct( ... [[promoter, 'forward'], [rbs, 'forward'], [cds, 'forward']], ... circular=True ... ) >>> construct.make_name() 'pLac_RBS1_GFP_o'
- make_polymers(species_lists, backbone)[source]
Create polymer species from combinatorial binding combinations.
Generates OrderedPolymerSpecies by replacing specific monomers in a backbone polymer with bound versions according to the replacement dictionaries.
- Parameters:
species_lists (
listofdict) – List of replacement dictionaries where each dict maps positions (int) to [species, direction] pairs indicating which monomers to replace with bound versions.backbone (
OrderedPolymerSpecies) – The base polymer species serving as the template for creating bound variants.
- Returns:
List of polymer species representing all specified combinatorial binding states.
- Return type:
listofOrderedPolymerSpecies
Notes
This method takes a backbone polymer (typically the unbound construct) and creates variants where specific positions contain bound complexes.
For example, given backbone
<A,B,C>and replacements:{0: [A:RNAP, forward]}creates<[A:RNAP],B,C>{0: [A:RNAP, forward], 1: [B:RNAP, forward]}creates<[A:RNAP],[B:RNAP],C>
- classmethod omnihash(construct)[source]
Compute a canonical hash for the construct.
Creates the most alphabetically ordered representation of a construct, accounting for direction (forward/reverse) and, for circular constructs, rotation. This provides a unique canonical identifier for functionally equivalent constructs.
- Parameters:
construct (
Construct) – The construct to hash (can be linear or circular).- Returns:
hash (
str) – Canonical hash string with ‘circular’ or ‘linear’ suffix indicating construct topology.direction (
int) – Direction of the canonical form: 1 for forward, -1 for reverse.first_position (
int) – Starting position for the canonical form. For circular constructs, this is the optimal rotation point. For linear constructs, always 0.
Notes
For circular constructs:
Evaluates all rotations in both orientations
Selects the most alphabetically ordered permutation
Appends ‘circular’ to the hash
For linear constructs:
Compares forward and reverse orientations
Selects the most alphabetically ordered orientation
Appends ‘linear’ to the hash
To recreate the canonical form:
If direction is -1, reverse the construct
For circular constructs, rotate to start at
first_positionFor linear constructs,
first_positionis always 0
This hash enables identification of equivalent constructs that differ only in representation (rotation or direction).
Examples
Two circular constructs with the same parts in different rotations will produce the same omnihash:
>>> A, B, C = (bcp.DNA_part(s) for s in ['A', 'B', 'C']) >>> construct1 = bcp.DNA_construct( ... [[A, 'forward'], [B, 'forward'], [C, 'forward']], ... circular=True) >>> construct2 = bcp.DNA_construct( ... [[B, 'forward'], [C, 'forward'], [A, 'forward']], ... circular=True) >>> hash1, _, _ = bcp.Construct.omnihash(construct1) >>> hash2, _, _ = bcp.Construct.omnihash(construct2) >>> hash1 == hash2 True
- replace(position, part, direction=None)[source]
Replace a monomer at a specific position in the polymer.
Removes the monomer at the given position and inserts a copy of the new monomer in its place. Calls the
changedcallback after replacement.- Parameters:
position (
int) – Index of the monomer to replace. Must be a valid position in the polymer.part (
OrderedMonomer) – The monomer to insert. A copy of this monomer will be added.direction (
str,int, orNone, optional) – Direction for the new monomer. If None, uses the monomer’s existing direction.
Notes
The removed monomer’s
removemethod is called to clear its parent, position, and direction attributes.
- reset_stored_data()[source]
Clear all cached enumeration and prediction data.
Resets the cached results from component enumeration, RNA prediction, and protein prediction, forcing these to be recomputed on the next access.
Notes
This method should be called whenever the construct is modified in a way that would invalidate cached data, such as:
Reversing the construct
Changing parts
Updating mechanisms or parameters
The cached attributes that are reset:
out_components: Results fromenumerate_componentspredicted_rnas: List of predicted RNA productspredicted_proteins: List of predicted protein products
- reverse()[source]
Reverse the construct without modifying the underlying DNA.
Creates a reversed representation of the construct where all parts are in reverse order and each part’s direction is flipped. This is useful for generating the reverse complement of a construct.
- Returns:
Returns self after reversing the parts list and flipping directions.
- Return type:
Notes
This method modifies the construct in place by:
Reversing the order of parts in the parts_list
Flipping each part’s direction (forward \(\rightleftharpoons\) reverse)
The underlying DNA sequence is not modified, only the representation changes.
Examples
Reverse a simple construct:
>>> promoter = bcp.Promoter('ptet') >>> gene = bcp.CDS('GFP') >>> construct = bcp.Construct( ... [[promoter, 'forward'], [gene, 'forward']]) >>> construct.reverse() Construct = GFP_r_pLac_r
- classmethod rotation_free_hash(construct)[source]
Compute the most alphabetically ordered circular permutation hash.
Finds the circular permutation of the construct that produces the most alphabetically ordered sequence of parts, providing a canonical representation for circular constructs regardless of starting position.
- Parameters:
construct (
Construct) – The circular construct to hash. Should havecircular=True.- Returns:
hash (
str) – String hash of the most alphabetically ordered permutation.direction (
int) – Always 1 (forward direction, since only rotation is considered).first_position (
int) – The position that should be used as the first position to recreate this canonical permutation.
Notes
This method evaluates every possible starting position for a circular construct and selects the permutation that produces the most alphabetically ordered sequence when parts are compared lexicographically.
To recreate the canonical form from the original construct:
Rotate to start at
first_position
The direction is always 1 because this method only considers rotations, not reversals.
Examples
For a circular construct with parts A, B, C, if starting at C gives the most alphabetically ordered sequence (C, A, B), then
first_positionwould be 2.
- set_attributes(attributes: List[str])[source]
Set multiple attributes for the component.
Adds a list of attribute tags to the component and its associated species by calling
add_attributefor each attribute in the list.- Parameters:
attributes (
listofstrorNone) – List of attribute strings to add to the component. If None, no action is taken.
See also
add_attributeAdd a single attribute to the component.
Examples
>>> comp = bcp.Protein(name="MyProtein") >>> comp.set_attributes(["degtagged", "fluorescent"]) >>> comp.attributes ['degtagged', 'fluorescent']
- set_mixture(mixture)[source]
Set the mixture containing this construct and all its parts.
Propagates the mixture reference to all parts in the construct, ensuring they share access to the same parameter database and mechanisms.
- Parameters:
mixture (
Mixture) – The mixture object that contains this construct.
Notes
This method ensures that all parts in the construct have access to the same mixture-level parameters and mechanisms, maintaining consistency across the entire construct.
- classmethod set_species(species: Species | str, material_type=None, compartment=None, attributes=None) Species[source]
Convert various inputs into Species objects.
- Parameters:
species (
Species,str,Component, orlist) – The species to convert. Can be aSpeciesobject (returned as-is), a string (creates new Species), aComponent(extracts its species), or a list of any of these types.material_type (
str, optional) – Material type for the species (e.g., ‘dna’, ‘rna’, ‘protein’). Only used when creating new Species from strings.compartment (
Compartment, optional) – Compartment to assign to the species. Only used when creating new Species from strings.attributes (
listofstr, optional) – Attributes to assign to the species. Only used when creating new Species from strings.
- Returns:
The converted Species object(s). Returns a list if input was a list.
- Return type:
- Raises:
ValueError – If the input cannot be converted to a valid Species.
- update_base_species(base_name=None, attributes=None)[source]
Update the base species representation of this construct.
Sets the
base_speciesattribute to a Species object representing the construct’s primary chemical species in the CRN.- Parameters:
base_name (
str, optional) – Name for the base species. If None, uses the construct’s name.attributes (
listofstr, optional) – Attribute tags to add to the species.
Notes
The base species serves as the chemical representation of the construct in CRN compilation, with material_type matching the construct’s material_type (e.g., ‘dna’ for DNA_constructs).
- update_combinatorial_complexes(active_components)[source]
Generate all combinatorial binding state species for the construct.
Given components that can bind to different positions in the construct, this method generates all possible combinations of binding states by mixing and matching bound species at different locations.
- Parameters:
active_components (
listofComponent) – Components that generate binding complexes with the construct. Each is assumed to bind at only one position.- Returns:
All possible combinatorial binding states of the construct, including the unbound state and all single and multiple binding combinations.
- Return type:
listofOrderedPolymerSpecies
Notes
The method:
Collects all binary complex species from each active component
Identifies unique positioned complexes
Generates all combinatorial placements using
located_allcombCreates polymer species for each combination using
make_polymers
For example, given construct
<A,B,C>with two components that create<[A:RNAP],B,C>and<A,[B:RNAP],C>, this method generates:<A,B,C>(unbound)<[A:RNAP],B,C>(A bound)<A,[B:RNAP],C>(B bound)<[A:RNAP],[B:RNAP],C>(both bound)
assuming A and B act independently.
- update_parameters(overwrite_parameters=True)[source]
Update parameters for the construct and all its parts.
Propagates parameter updates from the construct’s parameter database to all parts in the parts list, ensuring consistent parameters throughout the construct.
- Parameters:
overwrite_parameters (
bool, defaultTrue) – If True, new parameter values overwrite existing ones in the parts. If False, existing parameters in parts are preserved.
Notes
This method:
Updates the construct’s own parameters via the parent Component class
Propagates these parameters to each part in the construct
This ensures that all parts have access to the same parameter values unless explicitly overridden at the part level.
- update_permutation_hash()[source]
Update the direction-independent hash for this construct.
Generates a unique string representation of the construct that is invariant to direction (forward/reverse) and circular permutations (for circular constructs). This enables comparison of functionally equivalent constructs regardless of their representation.
Notes
The hash is stored in the
directionless_hashattribute and is used for identifying equivalent constructs that differ only in orientation or circular starting position.The hash is computed using the
omnihashclass method, which finds the most alphabetically ordered representation of the construct.See also
omnihashClass method that computes the direction and rotation-free hash.
- update_reactions(norna=False)[source]
Generate reactions for the construct.
- Returns:
Empty list. Base
Constructclass does not generate reactions directly. Subclasses override this method to provide specific reaction generation.- Return type:
listofReaction- Parameters:
norna (
bool, defaultFalse) – If True, RNA-related reactions are excluded (used in some subclass implementations).
Notes
This method is called during CRN compilation by
Mixture.compile_crn(). The base implementation returns an empty list because the base Construct class does not generate reactions directly - reactions are generated by the parts within the construct through their associated mechanisms.Subclasses like
DNA_constructandRNA_constructmay override this to provide construct-specific reaction generation.
- update_species()[source]
Generate species for the construct.
- Returns:
List containing the construct’s primary species representation.
- Return type:
listofSpecies
Notes
This method is called during CRN compilation by
Mixture.compile_crn()to generate the species associated with this construct. For most constructs, this returns a single species representing the entire construct.