biocrnpyler.components.dna.RegulatedPromoter
- class biocrnpyler.components.dna.RegulatedPromoter(name: str, regulators, leak=True, assembly=None, transcript=None, length=0, mechanisms=None, parameters=None, **kwargs)[source]
Bases:
PromoterPromoter with simple independent regulatory binding.
A regulated promoter allows multiple regulatory proteins (activators or repressors) to bind independently to the promoter DNA. Each regulator binds independently, and transcription can occur from both bound and unbound states with different rates. The component uses the ‘binding’ mechanism (
One_Step_Cooperative_Bindingby default) to generate DNA-regulator complexes and the ‘transcription’ mechanism to generate transcription reactions from each regulatory state.- Parameters:
name (
str) – Name of the promoter.regulators (
Species,str, orlist) – Regulator species that bind to the promoter. Can be a single regulator or a list. Each regulator binds independently.leak (
bool, defaultTrue) – If True, allows transcription from the unbound promoter state (leak expression). If False, only bound states transcribe.assembly (
DNAassembly, optional) – The assembly containing this promoter.transcript (
RNAorstr, optional) – The RNA transcript produced by this promoter.length (
int, default0) – Length of the promoter in base pairs.mechanisms (
dictorlist, optional) – Custom mechanisms for this promoter.parameters (
dict, optional) – Parameter values specific to this promoter.**kwargs – Additional keyword arguments passed to parent class.
- Attributes:
See also
PromoterBase promoter class.
ActivatablePromoterHill function-based activation.
RepressiblePromoterHill function-based repression.
CombinatorialPromoterCombinatorial regulation logic.
Notes
Each regulator binds independently, creating multiple DNA-protein complexes. Transcription can occur from each complex with different parameters identified by part_id.
The leak behavior allows modeling of constitutive expression that occurs even without regulator binding.
Examples
Create a promoter with a single regulator:
>>> promoter = bcp.RegulatedPromoter( ... name='p_reg', ... regulators='protein_TF', ... leak=True ... )
Create a promoter with multiple independent regulators:
>>> promoter = bcp.RegulatedPromoter( ... name='p_multi', ... regulators=['protein_TF1', 'protein_TF2'], ... leak=False ... )
Methods
Add a single attribute to the component.
Add a mechanism to this component's mechanism dictionary.
Add multiple mechanisms to this component.
Attach this part to a specific position in a DNA construct.
Enumerate derived components created from this component.
Find the polymer component within this monomer or its species.
Create a promoter instance from another promoter or string.
Retrieve a mechanism by type from the component or its mixture.
Create a copy of this monomer without a parent reference.
Retrieve parameter from component or mixture parameter database.
Get protein product for expression mixtures.
Create a fully detached copy of this monomer.
Get the primary species associated with this promoter.
Insert this monomer into a polymer at a specific position.
Remove this monomer from its parent polymer.
Reverse the orientation of this DNA part.
Set multiple attributes for the component.
Set the direction of the monomer and return self.
Set the mixture containing this component.
Convert various inputs into Species objects.
Compute hash contribution from monomer properties.
Remove this part from its parent construct.
Create a copy of the promoter with updated DNA binding target.
Update the parameter database with new parameters.
Generate reactions for regulated transcription.
Generate species for regulated transcription.
- __eq__(other)[source]
Test equality between two DNA_parts.
Parts are equal if they have the same type, name, parent assembly/ construct, direction, and position.
- Parameters:
other (
DNA_part) – The other part to compare with.- Returns:
True if parts are equal, False otherwise.
- Return type:
bool
Notes
Equality requires matching:
Type (both must be the same DNA_part subclass)
Name (identical names)
Assembly/parent (same parent construct or both have None)
Direction (both forward or both reverse)
Position (same position in parent construct)
Parts are considered equal even if their parent constructs are different objects, as long as the string representations of the parents match.
- 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: Mechanism, mech_type=None, overwrite=False, optional_mechanism=False)[source]
Add a mechanism to this component’s mechanism dictionary.
- Parameters:
mechanism (
Mechanism) – The mechanism object to add.mech_type (
str, optional) – The type key under which to store the mechanism. If None, uses the mechanism’smechanism_typeattribute.overwrite (
bool, defaultFalse) – If True, replaces any existing mechanism with the same key. If False, raises ValueError when key already exists.optional_mechanism (
bool, defaultFalse) – If True, suppresses the ValueError when a mechanism key conflict occurs andoverwriteis False.
- Raises:
TypeError – If
mechanismis not a Mechanism object, or ifmech_typeis not a string.ValueError – If mechanism key already exists,
overwriteis False, andoptional_mechanismis False.
- 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.
- clone(position, direction, parent_dna)[source]
Attach this part to a specific position in a DNA construct.
- Parameters:
position (
int) – Position in the parent DNA where this part should be placed.direction (
str) – Orientation of the part: ‘forward’ or ‘reverse’.parent_dna (
DNA_constructorOrderedPolymer) – The DNA construct that will contain this part.
- Returns:
Returns self after setting position and parent.
- Return type:
Notes
This method establishes the relationship between a part and its containing construct, setting the part’s position and orientation.
- property compartment
The compartment containing this component.
- Type:
Compartment or None
- property dna_species
The chemical species representation of this DNA part.
Returns a Species object with material_type=’part’ representing this DNA_part as a chemical species in the CRN.
- Type:
- property dna_to_bind
DNA species used as transcription template.
If not explicitly set, defaults to the assembly’s DNA species.
- Type:
Species or None
- enumerate_components(previously_enumerated=None) List[source]
Enumerate derived components created from this component.
This method generates new components based on the current component, typically used during CRN compilation to expand higher-level components into their constituent parts and products.
- Parameters:
previously_enumerated (
setorlist, optional) – Collection of components that have already been enumerated, used to prevent infinite recursion in component enumeration.- Returns:
List of new components created from this component. This base implementation returns an empty list.
- Return type:
list
Notes
Subclasses override this method to implement specific enumeration behavior. For example:
A
DNA_constructreturns copies of its parts andRNA_constructobjects representing transcripts.An
RNA_constructreturns copies of its parts andProteincomponents representing translation products.
- find_polymer_component()[source]
Find the polymer component within this monomer or its species.
Searches this monomer and, if it is a
ComplexSpecies, its constituent species to find which one is marked as a polymer component.- Returns:
The monomer that is part of a polymer structure, or None if no polymer component is found.
- Return type:
OrderedMonomerorNone- Raises:
ValueError – If multiple species are marked as polymer components in the same location.
Notes
This method is primarily used internally to handle complex species that may contain monomers as part of larger structures.
- classmethod from_promoter(name, assembly, transcript, protein)[source]
Create a promoter instance from another promoter or string.
Factory method for creating promoters from various input types.
- Parameters:
name (
Promoterorstr) – Either a string name for a new promoter, or an existing Promoter object to copy.assembly (
DNAassembly) – The assembly containing this promoter.transcript (
RNAorstr) – The RNA transcript produced by this promoter.protein (
Protein,str, orlist) – The protein product(s) for expression mixtures.
- Returns:
A new Promoter instance. If
nameis a Promoter, returns a deep copy with updated assembly, transcript, and protein attributes.- Return type:
- Raises:
TypeError – If
nameis neither a string nor a Promoter.
- 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_orphan()[source]
Create a copy of this monomer without a parent reference.
Returns a copy that retains position and direction but has no parent polymer. Useful for temporarily working with monomers outside their polymer context.
- Returns:
A copy of this monomer with parent set to None but position and direction preserved.
- Return type:
See also
get_removedCreate a fully detached copy.
removeRemove this monomer from its parent in place.
Notes
This is a shallow copy of the monomer object itself, though the parent reference is explicitly cleared.
- 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_protein_for_expression()[source]
Get protein product for expression mixtures.
In expression mixtures, transcription may be bypassed and translation may occur directly from DNA. This method returns the protein product when the gene is expressed.
- Returns:
The protein product(s) if transcript is None, otherwise None.
- Return type:
listofSpeciesorNone
Notes
This is used by expression mixtures where the transcript species is omitted and translation occurs directly.
- get_removed()[source]
Create a fully detached copy of this monomer.
Returns a copy with all polymer-related attributes (parent, position, direction) cleared. Also removes ‘forward’ and ‘reverse’ attributes if present.
- Returns:
A copy of this monomer with no parent, position, or direction, and with directional attributes removed.
- Return type:
See also
get_orphanCreate a copy without parent but with position and direction.
removeRemove this monomer from its parent in place.
Notes
This method is useful for creating completely independent copies of monomers that can be reused in different contexts without any polymer associations.
- get_species()[source]
Get the primary species associated with this promoter.
- Returns:
Promoters do not have a primary species; they are part of a DNA assembly.
- Return type:
None
- monomer_insert(parent: OrderedPolymer, position: int, direction=None)[source]
Insert this monomer into a polymer at a specific position.
Sets the monomer’s parent, position, and direction attributes to reflect its insertion into the polymer. Marks the monomer (or its polymer component if it is a complex species) as a polymer component.
- Parameters:
parent (
OrderedPolymer) – The polymer to insert this monomer into.position (
int) – The position index where this monomer is being inserted.direction (
str,int, orNone, optional) – The direction for this monomer. If None, uses the monomer’s existing direction.
- Raises:
ValueError – If position is None, or if parent is None.
- remove()[source]
Remove this monomer from its parent polymer.
Clears the monomer’s parent, position, and direction attributes, effectively detaching it from any polymer structure.
- Returns:
Returns self for method chaining.
- Return type:
See also
get_removedCreate a fully detached copy of the monomer.
get_orphanCreate a copy with parent removed but position and direction preserved.
- reverse()[source]
Reverse the orientation of this DNA part.
Flips the direction of the part between ‘forward’ and ‘reverse’.
- Returns:
Returns self after reversing direction.
- Return type:
Notes
This method is typically called when a containing construct is reversed, ensuring all parts maintain proper relative orientation.
- 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_dir(direction)[source]
Set the direction of the monomer and return self.
Convenience method for setting direction in a fluent interface style.
- Parameters:
direction (
str,int, orNone) – The direction to assign to this monomer.- Returns:
Returns self for method chaining.
- Return type:
Examples
>>> monomer = bcp.OrderedMonomer().set_dir('forward') >>> monomer.direction 'forward'
- set_mixture(mixture) None[source]
Set the mixture containing this component.
- Parameters:
mixture (
MixtureorNone) – The mixture object that contains this component and provides default mechanisms and parameters.
- 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.
- subhash()[source]
Compute hash contribution from monomer properties.
Computes a hash value based on the monomer’s position, direction, and name (if present), excluding the parent reference.
- Returns:
Hash value based on monomer-specific properties.
- Return type:
int
Notes
This method is used by
__hash__to compute the monomer’s hash contribution. It excludes the parent to avoid circular dependencies in hash computation.
- unclone()[source]
Remove this part from its parent construct.
Detaches the part from any parent construct or assembly, resetting its position and parent references.
- Returns:
Returns self after removal from parent.
- Return type:
Notes
This method calls the
removemethod from theOrderedMonomerbase class to detach the part from its parent polymer structure.After calling this method, the part becomes “orphaned” and can be attached to a different construct using
clone.See also
cloneAttach the part to a construct at a specific position.
- update_component(internal_species=None, **kwargs)[source]
Create a copy of the promoter with updated DNA binding target.
Used for component enumeration when promoters are part of larger constructs that need to be duplicated with different species.
- Parameters:
internal_species (
Species, optional) – The new DNA species to use as the binding target.**kwargs – Additional keyword arguments (currently unused).
- Returns:
A shallow copy of this promoter with the updated
dna_to_bindattribute. Returns None if parent is RNA.- Return type:
PromoterorNone- Raises:
TypeError – If parent is neither DNA nor RNA construct.
- update_parameters(parameter_file=None, parameters=None, parameter_database=None, overwrite_parameters=True)[source]
Update the parameter database with new parameters.
- Parameters:
parameter_file (
str, optional) – Path to a CSV or TSV file containing parameters to load.parameters (
dict, optional) – Dictionary of parameters to add. Keys follow the format (mechanism, part_id, param_name).parameter_database (
ParameterDatabase, optional) – Another parameter database to merge into component’s database.overwrite_parameters (
bool, defaultTrue) – If True, new parameter values overwrite existing ones. If False, existing parameters are preserved.
- update_reactions()[source]
Generate reactions for regulated transcription.
Uses the ‘binding’ mechanism to generate binding reactions for each regulator and the ‘transcription’ mechanism to generate transcription reactions for each regulatory state (bound and unbound).
- Returns:
List containing all binding reactions for regulators and transcription reactions for each DNA state.
- Return type:
listofReaction
Notes
Reactions are generated for:
Regulator binding and unbinding to DNA
Transcription from unbound DNA (if leak is True)
Transcription from each DNA-regulator complex
- update_species()[source]
Generate species for regulated transcription.
Uses the ‘transcription’ and ‘binding’ mechanisms to generate species for regulator-DNA binding and transcription from each regulatory state. Generates DNA-regulator complexes and identifies which complexes can transcribe.
- Returns:
List containing all DNA-regulator complexes and species generated by the transcription mechanism for each regulatory state.
- Return type:
listofSpecies
Notes
The method generates:
DNA-regulator binding complexes for each regulator
Transcription-related species for unbound DNA (if leak is True)
Transcription-related species for each DNA-regulator complex
Complexes are stored in
self.complexesfor use inupdate_reactions.