@@ -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
0 commit comments