Skip to content

Commit e18e71b

Browse files
committed
add documentation + code cleanup
1 parent c1c77c1 commit e18e71b

File tree

10 files changed

+254
-50
lines changed

10 files changed

+254
-50
lines changed

Tests/Unit/test_parameter.py

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,3 +545,150 @@ def test_findpath():
545545
os.environ['BCP_PATH'] = '/tmp:.:..'
546546
assert os.path.exists(bcp.find_file_in_bcp_path('__testfile__.tsv'))
547547
os.remove('../__testfile__.tsv')
548+
549+
550+
def test_parameter_ordering():
551+
import biocrnpyler as bcp
552+
553+
# Create the components for testing
554+
TetR = bcp.Protein('TetR')
555+
aTc = bcp.Species('aTc')
556+
TetR_inactive=bcp.ChemicalComplex([TetR.species, aTc])
557+
ptet = bcp.RegulatedPromoter('ptet', TetR)
558+
dna_GFP = bcp.DNAassembly(
559+
'GFP', promoter=ptet, rbs='RBS', protein='GFP')
560+
561+
# Default case: test everything in PURE< with no parameters
562+
default_mixture = bcp.BasicPURE(
563+
'default', components=[dna_GFP, TetR_inactive])
564+
default_crn = default_mixture.compile_crn()
565+
566+
# Find the binding reactions of TetR to DNA and aTc
567+
aTc_TetR_index = dna_TetR_index = -1
568+
for i, reaction in enumerate(default_crn.reactions):
569+
if not isinstance(reaction.propensity_type, bcp.MassAction):
570+
continue
571+
572+
inputs = [input.species for input in reaction.inputs]
573+
574+
# Find the binding of aTc to TetR
575+
if aTc in inputs and TetR.species in inputs:
576+
aTc_TetR_index = i
577+
578+
# Find the binding of TetR to DNA
579+
if dna_GFP.species in inputs and TetR.species in inputs:
580+
dna_TetR_index = i
581+
assert aTc_TetR_index != -1 and dna_TetR_index != -1
582+
assert default_crn.reactions[
583+
dna_TetR_index].propensity_type.k_forward != 1
584+
assert default_crn.reactions[
585+
aTc_TetR_index].propensity_type.k_forward != 1
586+
587+
# Rebuild using given parameters
588+
baseline_parameters = {
589+
('binding', None, 'kb'): 1,
590+
('binding', None, 'ku'): 0.1,
591+
('binding', None, 'cooperativity'): 2,
592+
}
593+
TetR_inactive=bcp.ChemicalComplex(
594+
[TetR.species, aTc], parameters=baseline_parameters)
595+
dna_GFP = bcp.DNAassembly(
596+
'GFP', promoter=ptet, rbs='RBS', protein='GFP',
597+
parameters=baseline_parameters)
598+
baseline_mixture = bcp.BasicPURE(
599+
'baseline', components=[dna_GFP, TetR_inactive])
600+
baseline_crn = baseline_mixture.compile_crn()
601+
assert baseline_crn.reactions[
602+
dna_TetR_index].propensity_type.k_forward == 1
603+
assert baseline_crn.reactions[
604+
aTc_TetR_index].propensity_type.k_forward == 1
605+
606+
# Override using mechanism subtypes
607+
mechtype_parameters = baseline_parameters | {
608+
('binding', 'dna_protein', 'kb'): 2,
609+
('binding', 'chemical_complex', 'kb'): 3,
610+
}
611+
TetR_inactive=bcp.ChemicalComplex(
612+
[TetR.species, aTc], parameters=mechtype_parameters)
613+
dna_GFP = bcp.DNAassembly(
614+
'GFP', promoter=ptet, rbs='RBS', protein='GFP',
615+
parameters=mechtype_parameters)
616+
mechtype_mixture = bcp.BasicPURE(
617+
'mechtype', components=[dna_GFP, TetR_inactive])
618+
mechtype_crn = mechtype_mixture.compile_crn()
619+
assert mechtype_crn.reactions[
620+
dna_TetR_index].propensity_type.k_forward == 2
621+
assert mechtype_crn.reactions[
622+
aTc_TetR_index].propensity_type.k_forward == 3
623+
624+
# Override using part IDs
625+
partid_parameters = mechtype_parameters | {
626+
('binding', 'ptet_TetR', 'kb'): 4,
627+
('binding', 'aTc_protein_TetR', 'kb'): 5,
628+
}
629+
TetR_inactive=bcp.ChemicalComplex(
630+
[TetR.species, aTc], parameters=partid_parameters)
631+
dna_GFP = bcp.DNAassembly(
632+
'GFP', promoter=ptet, rbs='RBS', protein='GFP',
633+
parameters=partid_parameters)
634+
partid_mixture = bcp.BasicPURE(
635+
'partid', components=[dna_GFP, TetR_inactive])
636+
partid_crn = partid_mixture.compile_crn()
637+
assert partid_crn.reactions[
638+
dna_TetR_index].propensity_type.k_forward == 4
639+
assert partid_crn.reactions[
640+
aTc_TetR_index].propensity_type.k_forward == 5
641+
642+
# Override using mechanism name
643+
mechname_parameters = baseline_parameters | {
644+
('one_step_cooperative_binding', None, 'kb'): 6,
645+
('binding', 'chemical_complex', 'kb'): 7,
646+
}
647+
TetR_inactive=bcp.ChemicalComplex(
648+
[TetR.species, aTc], parameters=mechname_parameters)
649+
dna_GFP = bcp.DNAassembly(
650+
'GFP', promoter=ptet, rbs='RBS', protein='GFP',
651+
parameters=mechname_parameters)
652+
mechname_mixture = bcp.BasicPURE(
653+
'mechname', components=[dna_GFP, TetR_inactive])
654+
mechname_crn = mechname_mixture.compile_crn()
655+
assert mechname_crn.reactions[
656+
dna_TetR_index].propensity_type.k_forward == 6
657+
assert mechname_crn.reactions[
658+
aTc_TetR_index].propensity_type.k_forward == 7
659+
660+
# Override in mixture instead of components
661+
mixture_parameters = baseline_parameters | {
662+
('one_step_cooperative_binding', None, 'kb'): 8,
663+
('binding', 'chemical_complex', 'kb'): 9,
664+
}
665+
TetR_inactive=bcp.ChemicalComplex([TetR.species, aTc])
666+
dna_GFP = bcp.DNAassembly(
667+
'GFP', promoter=ptet, rbs='RBS', protein='GFP')
668+
mixture_mixture = bcp.BasicPURE(
669+
'mixture', components=[dna_GFP, TetR_inactive],
670+
parameters=mixture_parameters)
671+
mixture_crn = mixture_mixture.compile_crn()
672+
assert mixture_crn.reactions[
673+
dna_TetR_index].propensity_type.k_forward == 8
674+
assert mixture_crn.reactions[
675+
aTc_TetR_index].propensity_type.k_forward == 9
676+
677+
# Override in components and not mixture
678+
component_parameters = baseline_parameters | {
679+
('one_step_cooperative_binding', None, 'kb'): 10,
680+
('binding', 'chemical_complex', 'kb'): 11,
681+
}
682+
TetR_inactive=bcp.ChemicalComplex(
683+
[TetR.species, aTc], parameters=component_parameters)
684+
dna_GFP = bcp.DNAassembly(
685+
'GFP', promoter=ptet, rbs='RBS', protein='GFP',
686+
parameters=component_parameters)
687+
mixture_mixture = bcp.BasicPURE(
688+
'mixture', components=[dna_GFP, TetR_inactive],
689+
parameters=mixture_parameters)
690+
mixture_crn = mixture_mixture.compile_crn()
691+
assert mixture_crn.reactions[
692+
dna_TetR_index].propensity_type.k_forward == 10
693+
assert mixture_crn.reactions[
694+
aTc_TetR_index].propensity_type.k_forward == 11

biocrnpyler/components/basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ class ChemicalComplex(Component):
513513
List of attribute tags to associate with the complex species. The
514514
complex also inherits attributes from its constituent species.
515515
binding_type : str, default='chemical_complex'
516-
Mechanism subtype for binding reaction parameters.
516+
Part type for binding reaction parameters.
517517
**kwargs
518518
Additional keyword arguments passed to the `Component` base class
519519
constructor.

biocrnpyler/components/combinatorial_complex.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class CombinatorialComplex(Component):
3737
Name of the component. If None, automatically generated from
3838
final_states names.
3939
binding_type : str, default='chemical_complex'
40-
Mechanism subtype for binding reaction parameters.
40+
Part type for binding reaction parameters.
4141
**kwargs
4242
Additional keyword arguments passed to the `Component` base class
4343
constructor.

biocrnpyler/components/dna/misc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class DNABindingSite(DNA_part):
3636
assembly : DNAassembly, optional
3737
The DNA assembly containing this binding site.
3838
binding_type : str, default='dna_protein'
39-
Mechanism subtype for binding reaction parameters.
39+
Part type for binding reaction parameters.
4040
**kwargs
4141
Additional keyword arguments passed to the parent `DNA_part` class.
4242
@@ -258,7 +258,7 @@ class IntegraseSite(DNABindingSite):
258258
If True, integrase must bind before recombination. If False,
259259
recombination occurs without explicit binding (simplified model).
260260
binding_type : str, default='dna_protein'
261-
Mechanism subtype for binding reaction parameters.
261+
Part type for binding reaction parameters.
262262
**kwargs
263263
Additional keyword arguments passed to parent class.
264264

biocrnpyler/components/dna/promoter.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ class Promoter(DNA_part):
5151
dna_to_bind : DNA or Species, optional
5252
The DNA species that serves as the transcription template. If None,
5353
uses the assembly's DNA when available.
54-
binding_type : str, default='dna_protein'
55-
Mechanism subtype for binding reaction parameters.
5654
**kwargs
5755
Additional keyword arguments passed to the parent `DNA_part` class.
5856
@@ -109,12 +107,10 @@ def __init__(
109107
parameters=None,
110108
protein=None,
111109
dna_to_bind=None,
112-
binding_type='dna_protein',
113110
**kwargs,
114111
):
115112
self._dna_bind = dna_to_bind
116113
self.length = length
117-
self.binding_type = binding_type
118114

119115
if transcript is None and assembly is None:
120116
self.transcript = None
@@ -397,6 +393,8 @@ class RegulatedPromoter(Promoter):
397393
Custom mechanisms for this promoter.
398394
parameters : dict, optional
399395
Parameter values specific to this promoter.
396+
binding_type : str, default='dna_protein'
397+
Part type for binding reaction parameters.
400398
**kwargs
401399
Additional keyword arguments passed to parent class.
402400
@@ -455,6 +453,7 @@ def __init__(
455453
length=0,
456454
mechanisms=None,
457455
parameters=None,
456+
binding_type='dna_protein',
458457
**kwargs,
459458
):
460459
Promoter.__init__(
@@ -478,6 +477,7 @@ def __init__(
478477
]
479478

480479
self.leak = leak
480+
self.binding_type = binding_type
481481

482482
self.add_mechanism(One_Step_Cooperative_Binding(), 'binding')
483483
self.complexes = []
@@ -631,6 +631,8 @@ class ActivatablePromoter(Promoter):
631631
leak : bool, default=False
632632
If True, allows basal transcription without activator. If False, no
633633
transcription occurs without activator binding.
634+
binding_type : str, default='dna_protein'
635+
Part type for binding reaction parameters.
634636
**kwargs
635637
Additional keyword arguments passed to parent `Promoter` class.
636638
@@ -669,7 +671,13 @@ class ActivatablePromoter(Promoter):
669671
"""
670672

671673
def __init__(
672-
self, name, activator, transcript=None, leak=False, **kwargs
674+
self,
675+
name,
676+
activator,
677+
transcript=None,
678+
leak=False,
679+
binding_type='dna_protein',
680+
**kwargs,
673681
):
674682
# Always call the superclass __init__() with **kwargs passed through
675683
Promoter.__init__(self, name=name, transcript=transcript, **kwargs)
@@ -682,6 +690,7 @@ def __init__(
682690
self.activator = self.set_species(activator)
683691

684692
self.leak = leak # toggles whether or not there is a leak reaction
693+
self.binding_type = binding_type
685694

686695
# Non-default Mechanisms are added to the Component with
687696
# .add_mechanism
@@ -777,6 +786,8 @@ class RepressiblePromoter(Promoter):
777786
leak : bool, default=False
778787
If True, allows residual transcription even at high repressor
779788
concentrations. If False, transcription is fully repressed.
789+
binding_type : str, default='dna_protein'
790+
Part type for binding reaction parameters.
780791
**kwargs
781792
Additional keyword arguments passed to parent `Promoter` class.
782793
@@ -815,7 +826,13 @@ class RepressiblePromoter(Promoter):
815826
"""
816827

817828
def __init__(
818-
self, name, repressor, transcript=None, leak=False, **kwargs
829+
self,
830+
name,
831+
repressor,
832+
transcript=None,
833+
leak=False,
834+
binding_type='dna_protein',
835+
**kwargs,
819836
):
820837
# Always call the superclass __init__() with **kwargs passed through
821838
Promoter.__init__(self, name=name, transcript=transcript, **kwargs)
@@ -828,6 +845,7 @@ def __init__(
828845
self.repressor = self.set_species(repressor)
829846

830847
self.leak = leak # toggles whether or not there is a leak reaction
848+
self.binding_type = binding_type
831849

832850
# Mechanisms are inherited from the Mixture unless set
833851
# specifically in self.default_mechanisms.
@@ -946,6 +964,8 @@ class CombinatorialPromoter(Promoter):
946964
Dictionary mapping regulator names to their cooperativity values
947965
(Hill coefficients) for binding, e.g., {'regulator1': 2,
948966
'regulator2': 1}.
967+
binding_type : str, default='dna_protein'
968+
Part type for binding reaction parameters.
949969
**kwargs
950970
Additional keyword arguments passed to parent class.
951971
@@ -1024,6 +1044,7 @@ def __init__(
10241044
protein=None,
10251045
tx_capable_list=None,
10261046
cooperativity=None,
1047+
binding_type='dna_protein',
10271048
**kwargs,
10281049
):
10291050
Promoter.__init__(
@@ -1079,6 +1100,7 @@ def __init__(
10791100
self.tx_capable_list = [set(a) for a in newlist]
10801101

10811102
self.leak = leak
1103+
self.binding_type = binding_type
10821104
self.complex_combinations = {}
10831105
self.tx_capable_complexes = []
10841106
self.leak_complexes = []

biocrnpyler/core/component.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -690,8 +690,21 @@ def get_parameter(
690690

691691
# Finally, try the mechanism parameter database
692692
if param is None and self.mechanisms is not None and check_mechanism:
693-
if self.mechanisms.get(mechanism, None):
694-
param = self.mechanisms[mechanism].get_parameter(
693+
if isinstance(mechanism, Mechanism):
694+
key = mechanism.mechanism_type
695+
else:
696+
key = mechanism
697+
698+
if self.mechanisms.get(key, None):
699+
param = self.mechanisms[key].get_parameter(
700+
mechanism, part_id, param_name
701+
)
702+
elif (
703+
self.mixture
704+
and self.mixture.mechanisms
705+
and self.mixture.mechanisms.get(key, None)
706+
):
707+
param = self.mixture.mechanisms[key].get_parameter(
695708
mechanism, part_id, param_name
696709
)
697710

biocrnpyler/core/parameter.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@
5454

5555
from ..utils.units import biocrnpyler_supported_units
5656

57-
# This could later be extended
58-
ParameterKey = namedtuple('ParameterKey', 'mechanism part_id name')
59-
"""Named tuple defining a parameter key.
57+
58+
class ParameterKey(namedtuple('ParameterKey', 'mechanism part_id name')):
59+
"""Named tuple defining a parameter key.
6060
6161
Parameters
6262
----------
@@ -69,7 +69,7 @@
6969
Name of the parameter. Must start with a letter and contain at
7070
least one character.
7171
72-
"""
72+
"""
7373

7474

7575
class Parameter(object):
@@ -1671,7 +1671,7 @@ def find_parameter(self, mechanism, part_id, param_name):
16711671

16721672
if not isinstance(part_id, list):
16731673
part_id = [part_id]
1674-
part_id += [None]
1674+
part_id = part_id + [None]
16751675
parameter_key_list = []
16761676

16771677
# Create a parameter key for each part_id

biocrnpyler/mechanisms/binding_parameters.tsv

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ binding chemical_complex ku 10 uM/sec 90% binding
2121
binding dna_protein kb 0.2 /sec TODO
2222
binding dna_protein ku 1e-3 uM/sec TODO
2323

24-
# One step cooperative binding
25-
cooperative_binding cooperativity 2 number of binding modules to bind simultaneously
24+
# Default cooperativity
25+
binding cooperativity 2 number of binding modules to bind simultaneously
2626

2727
# Two step cooperative binding (oligimerization)
28-
cooperative_binding kb1 1.0 /sec forward rate constant for oligomerization (TODO)
29-
cooperative_binding ku1 0.01 uM/sec reverse rate constant for oligomerization (TODO)
30-
cooperative_binding kb2 1.0 /sec forward rate constant for oligomer-bindee binding (TODO)
31-
cooperative_binding ku2 0.01 uM/sec reverse rate constant for oligomer-bindee binding (TODO)
28+
two_step_cooperative_binding kb1 1.0 /sec forward rate constant for oligomerization (TODO)
29+
two_step_cooperative_binding ku1 0.01 uM/sec reverse rate constant for oligomerization (TODO)
30+
two_step_cooperative_binding kb2 1.0 /sec forward rate constant for oligomer-bindee binding (TODO)
31+
two_step_cooperative_binding ku2 0.01 uM/sec reverse rate constant for oligomer-bindee binding (TODO)

0 commit comments

Comments
 (0)