biocrnpyler.components.dna.DNAassembly
- class biocrnpyler.components.dna.DNAassembly(name: str, dna=None, promoter=None, transcript=None, rbs=None, protein=None, length=None, attributes=None, mechanisms=None, compartment=None, parameters=None, initial_concentration=None, **kwargs)[source]
Bases:
DNAHigh-level representation of a gene expression construct.
A DNAassembly represents a complete gene expression unit combining a promoter region, ribosome binding site (RBS), coding sequence, and the RNA and protein products. This class provides a convenient interface for modeling the central dogma pathway: DNA \(\rightarrow\) RNA \(\rightarrow\) Protein, where the promoter controls transcription and the RBS controls translation.
- Parameters:
name (
str) – Name of the DNA assembly.dna (
DNA,str, orNone, optional) – The DNA species or name for the assembly. If None, a DNA species withnameis created automatically.promoter (
Promoter,str, orNone, optional) – The promoter component or name controlling transcription. If None, no transcription occurs. If a string, a default Promoter is created.transcript (
RNA,str,bool, orNone, optional) – The RNA transcript produced by transcription. If None, an RNA species withnameis created. If False, no transcript is created (used in expression mixtures for direct translation).rbs (
RBS,str, orNone, optional) – The ribosome binding site component or name controlling translation. If None, no translation occurs. If a string, a default RBS is created.protein (
Protein,str, orNone, optional) – The protein product of translation. If None, a Protein species withnameis created automatically.length (
int, optional) – Length of the DNA sequence in base pairs.attributes (
listofstr, optional) – List of attribute tags for the assembly and its species.mechanisms (
dictorlist, optional) – Custom mechanisms for this assembly, overriding mixture defaults.compartment (
Compartment, optional) – The compartment containing this assembly and its products.parameters (
dict, optional) – Parameter values specific to this assembly.initial_concentration (
float, optional) – Initial concentration of the DNA species.**kwargs – Additional keyword arguments passed to the parent
DNAclass.
- Attributes:
dna (
Species) – The DNA species representing the genetic construct.promoter (
PromoterorNone) – The promoter component controlling transcription.rbs (
RBSorNone) – The ribosome binding site controlling translation.transcript (
SpeciesorNone) – The RNA transcript produced by transcription.protein (
SpeciesorNone) – The protein product of translation.
See also
Notes
The DNAassembly automatically coordinates its sub-components (promoter, RBS) by propagating updates to mechanisms, parameters, and mixtures. When mechanisms or parameters are added to the assembly, they are also added to the promoter and RBS (but never overwrite existing values in those components).
The ‘transcription’ mechanism is used by the promoter to generate the species and reactions for transcript and the ‘translation’ mechanism is used by the RBS to generate the species and reactions for ribosome binding and protein production.
For expression mixtures where transcription is bypassed, set
transcript=Falseto enable direct translation from DNA to protein. In this case, the ‘transcription’ mechanism will be used to generate the protein.Examples
Create a simple constitutive gene expression construct:
>>> # Basic assembly with automatic species creation >>> gene = bcp.DNAassembly( ... name='gene_gfp', ... promoter='pconst', ... rbs='rbs1' ... ) >>> gene.dna dna_gene_gfp >>> gene.transcript rna_gene_gfp >>> gene.protein protein_gene_gfp
Create an assembly with custom species names:
>>> gene = bcp.DNAassembly( ... name='gene_reporter', ... promoter='p_lac', ... rbs='rbs_strong', ... transcript='mRNA_gfp', ... protein='protein_gfp' ... )
Create an expression construct (no transcript):
>>> gene = bcp.DNAassembly( ... name='gene_direct', ... promoter='p_const', ... transcript=False, ... protein='protein_x' ... )
Methods
Add a single attribute to the component.
Add a mechanism to the assembly and its sub-components.
Add multiple mechanisms to this component.
Enumerate derived components created from this component.
Retrieve a mechanism by type from the component or its mixture.
Retrieve parameter from component or mixture parameter database.
Get the primary DNA species of this assembly.
Set multiple attributes for the component.
Set the mixture containing this component and its sub-components.
Convert various inputs into Species objects.
Set or update the DNA species for this assembly.
Update parameters for the assembly and its sub-components.
Set or update the promoter component for this assembly.
Set or update the protein product for this assembly.
Set or update the ribosome binding site component.
Generate all reactions associated with this assembly.
Generate all species associated with this assembly.
Set or update the RNA transcript for this assembly.
- 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: str = None, overwrite: bool = False, optional_mechanism: bool = False) None[source]
Add a mechanism to the assembly and its sub-components.
Adds the mechanism to the assembly’s mechanism dictionary and propagates it to the promoter and RBS components without overwriting their existing mechanisms.
- 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 in the assembly. If False, raises ValueError for duplicate types.optional_mechanism (
bool, defaultFalse) – If True, suppresses ValueError when a mechanism key conflict occurs in the assembly andoverwriteis False.
Notes
The mechanism is always added to the promoter and RBS with
optional_mechanism=True, meaning it will never overwrite existing mechanisms in those components even ifoverwrite=True.
- 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.
- property compartment
The compartment containing this component.
- Type:
Compartment 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.
- 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_species()[source]
Get the primary DNA species of this assembly.
- Returns:
The DNA species representing this genetic construct.
- Return type:
- 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: Mixture) None[source]
Set the mixture containing this component and its sub-components.
Also propagates the mixture reference to the promoter and RBS components if they exist.
- Parameters:
mixture (
Mixture) – The mixture object that contains this assembly.
- 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_dna(dna: None | DNA | str, attributes=None) None[source]
Set or update the DNA species for this assembly.
Creates a DNA species from the provided input and updates the DNA references in the promoter and RBS components if they exist.
- Parameters:
dna (
DNA,str, orNone) – The DNA component, species name, or None. If None, creates a DNA species using the assembly’s name. If a string, creates a new DNA species with that name. If a DNA object, uses it directly.attributes (
listofstr, optional) – Attribute tags to add to the DNA species.
Notes
This method automatically updates the
dnaattribute of the promoter and RBS components to maintain consistency across the assembly.
- update_parameters(parameter_file: str = None, parameters: ParameterDatabase = None, overwrite_parameters: bool = True) None[source]
Update parameters for the assembly and its sub-components.
Propagates parameter updates to the DNA assembly itself and to the promoter and RBS components if they exist.
- Parameters:
parameter_file (
str, optional) – Path to a CSV or TSV parameter file to load.parameters (
ParameterDatabase, optional) – ParameterDatabase object to merge with the assembly’s parameters.overwrite_parameters (
bool, defaultTrue) – If True, new parameter values overwrite existing ones. If False, existing parameters are preserved.
Notes
This method calls
update_parameterson:The parent DNA class (updating the DNA’s parameters)
The promoter component (if it exists)
The RBS component (if it exists)
- update_promoter(promoter: Protein | str, transcript: RNA = None, protein: Protein = None) None[source]
Set or update the promoter component for this assembly.
Creates a Promoter component from the provided input and propagates the assembly’s parameters, mixture, and mechanisms to the promoter.
- Parameters:
promoter (
Promoter,str, orNone) – The Promoter component, promoter name, or None. If None, no promoter is created. If a string, creates a default Promoter with that name usingPromoter.from_promoter. If a Promoter object, uses it directly.transcript (
RNA, optional) – The RNA transcript to associate with the promoter. If provided, updates the assembly’s transcript before creating the promoter.protein (
Protein, optional) – The protein product to associate with the promoter (used for some regulatory mechanisms).
Notes
This method automatically:
Propagates the assembly’s parameter database to the promoter
Sets the promoter’s mixture reference
Adds the assembly’s mechanisms to the promoter (without overwriting existing promoter mechanisms)
- update_protein(protein: None | Protein | str, attributes=None) None[source]
Set or update the protein product for this assembly.
Creates a Protein species from the provided input and updates the protein references in the promoter and RBS components if they exist.
- Parameters:
protein (
Protein,str, orNone) – The Protein component, species name, or None. If None, creates a Protein species using the assembly’s name. If a string, creates a new Protein species with that name. If a Protein object, uses it directly.attributes (
listofstr, optional) – Attribute tags to add to the Protein species.
Notes
This method automatically updates the
proteinattribute of the promoter and RBS components to maintain consistency across the assembly.
- update_rbs(rbs: RBS | str, transcript: RNA = None, protein: Protein = None) None[source]
Set or update the ribosome binding site component.
Creates an RBS component from the provided input and propagates the assembly’s parameters, mixture, and mechanisms to the RBS.
- Parameters:
rbs (
RBS,str, orNone) – The RBS component, RBS name, or None. If None, no RBS is created. If a string, creates a default RBS with that name usingRBS.from_rbs. If an RBS object, uses it directly.transcript (
RNA, optional) – The RNA transcript containing the RBS. If provided, updates the assembly’s transcript before creating the RBS.protein (
Protein, optional) – The protein product of translation. If provided, updates the assembly’s protein before creating the RBS.
Notes
This method automatically:
Propagates the assembly’s parameter database to the RBS
Sets the RBS’s mixture reference
Adds the assembly’s mechanisms to the RBS (without overwriting existing RBS mechanisms)
- update_reactions() List[Reaction][source]
Generate all reactions associated with this assembly.
Collects reactions from the promoter and RBS components during CRN compilation.
- Returns:
List of all reactions generated by the promoter and RBS components, including transcription, translation, and regulatory reactions.
- Return type:
listofReaction
Notes
This method is called during CRN compilation by
Mixture.compile_crnto collect all chemical reactions generated by this assembly.
- update_species() List[Species][source]
Generate all species associated with this assembly.
Collects species from the DNA, promoter, and RBS components during CRN compilation.
- Returns:
List containing the DNA species and all species generated by the promoter and RBS components.
- Return type:
listofSpecies
Notes
This method is called during CRN compilation by
Mixture.compile_crnto collect all chemical species generated by this assembly.
- update_transcript(transcript: None | RNA | str | bool, attributes=None) None[source]
Set or update the RNA transcript for this assembly.
Creates an RNA species from the provided input and updates the transcript references in the promoter and RBS components if they exist.
- Parameters:
transcript (
RNA,str,bool, orNone) – The RNA component, species name, False, or None. If None, creates an RNA species using the assembly’s name. If a string, creates a new RNA species with that name. If an RNA object, uses it directly. If False, sets transcript to None (used for expression mixtures without transcription).attributes (
listofstr, optional) – Attribute tags to add to the RNA species.
Notes
Setting
transcript=Falseis used in expression mixtures where translation occurs directly from DNA without an explicit RNA intermediate.This method automatically updates the
transcriptattribute of the promoter and RBS components to maintain consistency.