Esempio n. 1
0
def test_single_reaction() -> None:
    rxncon_sys = Quick('A_p+_B_[(r)]').rxncon_system
    assert state_from_str('B_[(r)]-{0}') in rxncon_sys.consumed_states
    assert state_from_str('B_[(r)]-{p}') in rxncon_sys.produced_states

    assert state_from_str('B_[(r)]-{0}') in rxncon_sys.states_for_component(spec_from_str('B'))
    assert state_from_str('B_[(r)]-{p}') in rxncon_sys.states_for_component(spec_from_str('B'))
Esempio n. 2
0
def test_output_reactions() -> None:
    rxncon_sys = Quick("""A_p+_B_[(x)]
                    [output]; ! B_[(x)]-{p}""").rxncon_system

    contingencies = rxncon_sys.contingencies_for_reaction(reaction_from_str('[output]'))

    assert len(contingencies) == 1
    assert isinstance(contingencies[0].effector, StateEffector)
    assert [state_from_str('B@2_[(x)]-{p}')] == contingencies[0].effector.states
Esempio n. 3
0
def test_non_elemental_contingency_single_state() -> None:
    rxncon_sys = Quick('''A_trsl_BmRNA
                       C_p+_B_[(r1)]
                       D_[x]_ppi_B_[y] ; ! B-{p}''').rxncon_system

    contingencies = rxncon_sys.contingencies_for_reaction(reaction_from_str('D_[x]_ppi+_B_[y]'))

    assert len(contingencies) == 1
    print(contingencies[0].effector)
    assert contingencies[0].effector.name == 'B-{p}'
Esempio n. 4
0
def test_inconsistent_system() -> None:
    with pytest.raises(AssertionError):
        Quick('''A_ppi_B ; ! <X>
              C_p+_B_[(r1)]
              D_p+_B_[(r2)]
              <X> ; AND B_[(r1)]-{p}
              <X> ; AND B_[(r1)]-{0}''').rxncon_system

    with pytest.raises(AssertionError):
        Quick('''A_ppi_B ; ! B_[(r1)]-{p}
              A_ppi_B ; ! B_[(r1)]-{0}
              C_p+_B_[(r1)]
              D_p+_B_[(r2)]''').rxncon_system
Esempio n. 5
0
def test_bidirectional_reactions() -> None:
    rxncon_sys = Quick('''A_[x]_ppi_B_[y]; ! A_[(x)]-{p}
                       C_p+_A_[(x)]''').rxncon_system

    #  Forward direction
    contingencies = rxncon_sys.contingencies_for_reaction(reaction_from_str('A_[x]_ppi+_B_[y]'))
    assert len(contingencies) == 1
    assert contingencies[0].effector.states == [state_from_str('A@0_[(x)]-{p}')]
    assert contingencies[0].contingency_type == ContingencyType.requirement

    #  Reverse direction
    contingencies = rxncon_sys.contingencies_for_reaction(reaction_from_str('A_[x]_ppi-_B_[y]'))
    assert len(contingencies) == 0
Esempio n. 6
0
def test_degradation_input_required_no_output() -> None:
    rxncon_sys = Quick("""Decay_DEG_Ndd1mRNA; ! [Ndd1UB]""").rxncon_system
    boolean_model = boolean_model_from_rxncon(rxncon_sys)

    # Component expressions.
    Ndd1mRNA = 'Ndd1mRNA'
    Decay = 'Decay'

    expected_rules = {
        'Decay_deg_Ndd1mRNA': '{0} & {1} & [Ndd1UB]'.format(Ndd1mRNA, Decay),
        '[Ndd1UB]': '[Ndd1UB]',
    }
    rules_found = 0

    for update_rule in boolean_model.update_rules:
        if str(update_rule.target) == 'Decay_deg_Ndd1mRNA':
            assert update_rule.factor.is_equivalent_to(
                venn_from_str(expected_rules[str(update_rule.target)],
                              target_from_str))
            rules_found += 1
        elif str(update_rule.target) == '[Ndd1UB]':
            assert isinstance(update_rule.target, StateTarget)
            assert update_rule.factor.is_equivalent_to(
                venn_from_str(expected_rules[str(update_rule.target)],
                              target_from_str))
            rules_found += 1
    assert rules_found == 2
Esempio n. 7
0
def test_matching_input_output() -> None:
    boolean_model = boolean_model_from_rxncon(
        Quick("""A_p+_B_[(a)]; ! [global]
                                                        [global]; ! B_[(a)]-{p}"""
              ).rxncon_system)

    # Component expressions.
    A = 'A'
    B = '( B_[(a)]-{0} | B_[(a)]-{p} )'

    expected_rules = {
        'A_p+_B_[(a)]': '{0} & {1} & [global]'.format(A, B),
        '[global]': 'B_[(a)]-{p}'
    }

    rules_found = 0
    for update_rule in boolean_model.update_rules:
        if str(update_rule.target) == 'A_p+_B_[(a)]':
            assert update_rule.factor.is_equivalent_to(
                venn_from_str(expected_rules[str(update_rule.target)],
                              target_from_str))
            rules_found += 1
        elif str(update_rule.target) == '[global]':
            assert isinstance(update_rule.target, StateTarget)
            assert update_rule.factor.is_equivalent_to(
                venn_from_str(expected_rules[str(update_rule.target)],
                              target_from_str))
            rules_found += 1

    assert rules_found == 2
Esempio n. 8
0
def test_homodimer_degradation() -> None:
    """The degradation of homodimers should not lead to the production of the partner, but to the complete degradation
    of the complex."""
    boolean_model = boolean_model_from_rxncon(
        Quick("""UC132_deg_Ste5
             Ste5_[Ste7]_ppi+_Ste7_[Ste5]
             Ste4_[Ste5]_ppi+_Ste5_[Ste4]
             Ste5_[Ste5]_ppi+_Ste5_[Ste5]
             """).rxncon_system)

    num_degs = 0

    for rule in (x for x in boolean_model.update_rules
                 if isinstance(x.target, ReactionTarget)):
        assert isinstance(rule.target, ReactionTarget)
        if rule.target.degraded_targets:
            assert target_from_str(
                'Ste5_[Ste5]--Ste5_[Ste5]') in rule.target.degraded_targets
            num_degs += 1
            if target_from_str('Ste5_[Ste7]--Ste7_[Ste5]'
                               ) in rule.target.consumed_targets:
                assert target_from_str(
                    'Ste7_[Ste5]--0') in rule.target.produced_targets
            elif target_from_str('Ste4_[Ste5]--Ste5_[Ste4]'
                                 ) in rule.target.consumed_targets:
                assert target_from_str(
                    'Ste4_[Ste5]--0') in rule.target.produced_targets
            else:
                assert False

    assert num_degs == 2
Esempio n. 9
0
def test_deg_with_interaction() -> None:
    boolean_model = boolean_model_from_rxncon(
        Quick("""A_[x]_ppi+_B_[y]
                                                       D_p+_A_[(r)]
                                                       C_deg_A""").
        rxncon_system)
    target_to_factor = {
        rule.target: rule.factor
        for rule in boolean_model.update_rules
    }

    A = '( ( A_[x]--B_[y] | A_[x]--0 ) & ( A_[(r)]-{p} | A_[(r)]-{0} ) )'

    expected_rules = {
        'A_[x]--0':
        '( A_[x]--0 & ( A_[x]--B_[y] | A_[x]--0 ) & ( A_[(r)]-{p} | A_[(r)]-{0} ) & '
        '~(( A_[x]_ppi+_B_[y] & A_[x]--0 & B_[y]--0 )) & ~( C_deg_A ))',
        'B_[y]--0':
        '(( C_deg_A & A_[x]--B_[y] & ( B_[y]--0 | A_[x]--B_[y] )) | ( B_[y]--0 & '
        '( B_[y]--0 | A_[x]--B_[y] ) & ~(( A_[x]--0 & B_[y]--0 & A_[x]_ppi+_B_[y] & ~( C_deg_A )))))',
        'A_[x]--B_[y]':
        '{} & ~( C_deg_A ) & (( A_[x]_ppi+_B_[y] & A_[x]--0 & B_[y]--0 ) | '
        '( A_[x]--B_[y] & ~( C_deg_A & A_[x]--B_[y] ) ) )'.format(A)
    }

    for target_str, factor_str in expected_rules.items():
        assert target_to_factor[target_from_str(target_str)].is_equivalent_to(
            venn_from_str(factor_str, target_from_str))
Esempio n. 10
0
def test_deg_with_boolean_NOT() -> None:
    boolean_model = boolean_model_from_rxncon(
        Quick("""A_[x]_ppi+_B_[y]
                                                       D_p+_A_[(r)]
                                                       C_deg_A; ! <x>
                                                       <x>; AND A_[x]--B_[y]; AND <NOT>
                                                       <NOT>; NOT A_[(r)]-{p}"""
              ).rxncon_system)
    target_to_factor = {
        rule.target: rule.factor
        for rule in boolean_model.update_rules
    }

    expected_rules = {
        'C_deg_A':
        '( C & A_[x]--B_[y] & ~( A_[(r)]-{p} ) & '
        '( A_[x]--0 | A_[x]--B_[y] ) & ( A_[(r)]-{0} | A_[(r)]-{p} ))',
        'B_[y]--0':
        '(( A_[x]--B_[y] & C_deg_A & ( B_[y]--0 | A_[x]--B_[y] )) | '
        '( B_[y]--0 & ( B_[y]--0 | A_[x]--B_[y] ) & ~(( B_[y]--0 & A_[x]_ppi+_B_[y] & A_[x]--0 ))))',
        'A_[(r)]-{p}':
        '(( A_[(r)]-{0} & ~( C_deg_A ) & D_p+_A_[(r)] & ( A_[x]--0 | A_[x]--B_[y] ) & ( A_[(r)]-{0} | '
        'A_[(r)]-{p} )) | ( A_[(r)]-{p} & ( A_[x]--0 | A_[x]--B_[y] ) & ( A_[(r)]-{0} | A_[(r)]-{p} )))',
    }

    for target_str, factor_str in expected_rules.items():
        assert target_to_factor[target_from_str(target_str)].is_equivalent_to(
            venn_from_str(factor_str, target_from_str))
Esempio n. 11
0
def test_layout_remains_correct_when_removing_node() -> None:
    """
    Testing if the new graph gets tie correct layout of the old graph if we remove a node.

    Returns:
        None

    Raises:
        AssertionError: If the node coordinates of the new graph differ from expected coordinates.

    """
    test_case = Quick("""A_[b]_ppi+_B_[a]""")

    reg_graph = SpeciesReactionGraph(test_case.rxncon_system)
    gml_system = XGMML(reg_graph.to_graph(), "remove_node")
    mapped_layout = map_layout2xgmml(gml_system.to_string(),
                                     NODE_LAYOUT_MANIPULATION)
    xmldoc_no_layout = minidom.parseString(mapped_layout)
    xmldoc_no_layout_info = _get_labels_and_coordinates_dict(xmldoc_no_layout)
    xmldoc_expected_layout = minidom.parse(NODE_LAYOUT_MANIPULATION)
    xmldoc_expected_layout_info = _get_labels_and_coordinates_dict(
        xmldoc_expected_layout)

    assert all(xmldoc_no_layout_info[no_layout_node] ==
               xmldoc_expected_layout_info[no_layout_node]
               for no_layout_node in xmldoc_no_layout_info)
Esempio n. 12
0
def test_trslprocat() -> None:
    procatdef = reaction.ReactionDef(
        'pro-cat-translation',
        '$x_trslprocat_$y',
        {
            '$x': (Spec, LocusResolution.component),
            '$y': (MRNASpec, LocusResolution.component)
        },
        '$x%# + $y%# -> $x%# + $y%# + $y.to_protein_component_spec().with_name_suffix(\'PRO\')%!$y.to_protein_component_spec().with_name_suffix(\'CAT\')%#'  # pylint: disable=line-too-long
        '$y.to_protein_component_spec().with_name_suffix(\'PRO\').with_domain(\'PROCAT\')%--$y.to_protein_component_spec().with_name_suffix(\'CAT\').with_domain(\'CATPRO\')%!0'
    )

    reaction.REACTION_DEFS = reaction.DEFAULT_REACTION_DEFS + [procatdef]

    rxn_system = Quick("""Ribo_trslprocat_Ssy5mRNA
                          A_p+_Ssy5CAT
                          B_deg_Ssy5PRO""").rxncon_system

    rbm = rule_based_model_from_rxncon(rxn_system)

    expected_rules = [
        'Ribo() + Ssy5mRNA() -> Ribo() + Ssy5CAT(AR~0,CATPROD!1).Ssy5PRO(PROCATD!1) + Ssy5mRNA() k',
        'A() + Ssy5CAT(AR~0) -> A() + Ssy5CAT(AR~p) k',
        'B() + Ssy5PRO() -> B() k'
    ]

    assert len(rbm.rules) == len(expected_rules)

    for actual_rule in rbm.rules:
        assert any(rule_from_str(rule).is_equivalent_to(actual_rule) for rule in expected_rules)

    reaction.REACTION_DEFS = reaction.DEFAULT_REACTION_DEFS
Esempio n. 13
0
def test_structure_to_negative_interaction_states() -> None:
    rxncon_system = Quick("""Cdc28_P+_Bem2_[(cdc28)]; ! <Cdc28Cln13>
                        <Cdc28Cln13>; OR <Cdc28Cln1>; OR <Cdc28Cln3>
                        <Cdc28Cln1>; AND Cdc28_[cyclin]--Cln1_[cdc28]
                        <Cdc28Cln3>; AND Cdc28_[cyclin]--Cln3_[cdc28]; AND Cdc28_[whi3]--0
                        Cdc28_[cyclin]_ppi_Cln1_[cdc28]
                        Cdc28_[far1]_ppi_Far1_[cdc28]
                        Cdc28_[cks1]_ppi_Cks1_[cdc28]
                        Cak1_P+_Cdc28_[Tloop(T169)]
                        Cdc28_[cyclin]_ppi_Cln2_[cdc28]
                        Cdc28_[cyclin]_ppi_Cln3_[cdc28]
                        Cdc28_[whi3]_ppi_Whi3_[cdc28]""").rxncon_system

    rbm = rule_based_model_from_rxncon(rxncon_system)

    rules_of_interest = [
        rule_from_str(
            "Cdc28(whi3D) + Whi3(cdc28D) -> Cdc28(whi3D!1).Whi3(cdc28D!1) k_13 Cdc28_[whi3]_ppi+_Whi3_[cdc28]"),
        rule_from_str(
            "Cdc28(whi3D!1).Whi3(cdc28D!1) -> Cdc28(whi3D) + Whi3(cdc28D) k_14 Cdc28_[whi3]_ppi-_Whi3_[cdc28]")
    ]

    for rule_of_interest in rules_of_interest:
        identities = [rule.is_equivalent_to(rule_of_interest) for rule in rbm.rules]
        assert identities.count(True) == 1  # exactly once
Esempio n. 14
0
def test_single_inhibition_interaction() -> None:
    rbm = rule_based_model_from_rxncon(Quick("""A_[b]_ppi+_B_[a]; x A_[(r)]-{p}
                                             E_[x]_ppi+_B_[a]
                                             C_p+_A_[(r)]
                                             D_ub+_A_[(r)]""").rxncon_system)

    expected_rules = [
        'A(rR~ub,bD) + B(aD) -> A(rR~ub,bD!1).B(aD!1) k',
        'A(rR~0,bD) + B(aD) -> A(rR~0,bD!1).B(aD!1) k',
        'B(aD) + E(xD) -> B(aD!1).E(xD!1) k',
        'A(rR~0) + C() -> A(rR~p) + C() k',
        'A(rR~0) + D() -> A(rR~ub) + D() k'
    ]

    assert len(rbm.rules) == len(expected_rules)

    for actual_rule in rbm.rules:
        assert any(rule_from_str(rule).is_equivalent_to(actual_rule) for rule in expected_rules)

    expected_ics = [
        'A(bD,rR~0) NumA',
        'B(aD) NumB',
        'D() NumD',
        'C() NumC',
        'E(xD) NumE'
    ]

    for actual_ic in rbm.initial_conditions:
        assert any(initial_condition_from_str(ic).is_equivalent_to(actual_ic) for ic in expected_ics)
Esempio n. 15
0
def test_boolean_inhibition_interaction() -> None:
    rbm = rule_based_model_from_rxncon(Quick('''A_ppi+_C
                                             C_ppi+_D
                                             B_ppi+_E
                                             B_ppi+_F
                                             A_ppi+_B; x <comp1>
                                             <comp1>; OR <comp1C1>
                                             <comp1>; OR <comp2C1>
                                             <comp1C1>; AND A--C
                                             <comp1C1>; AND C--D
                                             <comp2C1>; AND B--F
                                             <comp2C1>; AND B--E''').rxncon_system)

    expected_rules = [
        'A(CD) + C(AD) -> A(CD!1).C(AD!1) k',
        'C(DD) + D(CD) -> C(DD!1).D(CD!1) k',
        'B(ED) + E(BD) -> B(ED!1).E(BD!1) k',
        'B(FD) + F(BD) -> B(FD!1).F(BD!1) k',
        'A(BD,CD) + B(AD,FD) -> A(BD!1,CD).B(AD!1,FD) k',
        'A(BD,CD) + B(AD,ED,FD!1).F(BD!1) -> A(BD!2,CD).B(AD!2,ED,FD!1).F(BD!1) k',
        'A(BD,CD!1).C(AD!1,DD) + B(AD,FD) -> A(BD!2,CD!1).B(AD!2,FD).C(AD!1,DD) k',
        'A(BD,CD!1).C(AD!1,DD) + B(AD,ED,FD!2).F(BD!2) -> A(BD!3,CD!1).B(AD!3,ED,FD!2).C(AD!1,DD).F(BD!2) k',
    ]

    assert len(rbm.rules) == len(expected_rules)

    for actual_rule in rbm.rules:
        assert any(rule_from_str(rule).is_equivalent_to(actual_rule) for rule in expected_rules)
Esempio n. 16
0
def test_deg_of_component_without_states() -> None:
    """
    Testing degradation of component without states.

    Returns:
        None

    Raises:
        AssertionError if the expected rule is not e
    """
    boolean_model = boolean_model_from_rxncon(
        Quick("""C_deg_A""").rxncon_system)

    target_to_factor = {
        rule.target: rule.factor
        for rule in boolean_model.update_rules
    }

    expected_rules = {
        'C_deg_A': '( C & A )',
        'A': '( A & ~( C_deg_A ))',
        'C': 'C'
    }
    for target_str, factor_str in expected_rules.items():
        assert target_to_factor[target_from_str(target_str)].is_equivalent_to(
            venn_from_str(factor_str, target_from_str))
Esempio n. 17
0
def test_single_requirement_modification() -> None:
    rbm = rule_based_model_from_rxncon(Quick("""A_[b]_ppi+_B_[a]; ! A_[(r)]-{p}
                                             A_[b]_ppi-_B_[a]
                                             C_p+_A_[(r)]
                                             D_p-_A_[(r)]""").rxncon_system)

    expected_rules = [
        'A(rR~p,bD) + B(aD) -> A(rR~p,bD!1).B(aD!1) k',
        'A(bD!1).B(aD!1) -> A(bD) + B(aD) k',
        'C() + A(rR~0) -> C() + A(rR~p) k',
        'A(rR~p) + D() -> A(rR~0) + D() k'
    ]

    assert len(rbm.rules) == len(expected_rules)

    for actual_rule in rbm.rules:
        print(actual_rule)
        # assert any(rule_from_str(rule).is_equivalent_to(actual_rule) for rule in expected_rules)

    expected_ics = [
        'A(bD,rR~0) NumA',
        'B(aD) NumB',
        'D() NumD',
        'C() NumC'
    ]

    for actual_ic in rbm.initial_conditions:
        assert any(initial_condition_from_str(ic).is_equivalent_to(actual_ic) for ic in expected_ics)
Esempio n. 18
0
def test_smooth_production_sources() -> None:
    """
    Testing smoothing function.

    Note:
        Only the update rule for A_[b]--0 is tested.

    Returns:
        None

    Raises:
        AssertionError: If update rule for A_[b]--0 is not as expected.

    """
    boolean_model = boolean_model_from_rxncon(
        Quick("""A_[b]_ppi+_B_[a]; ! A_[(r)]-{p}
                                                    A_[b]_ppi-_B_[a]
                                                    C_p+_A_[(r)]
                                                    D_p-_A_[(r)]""").
        rxncon_system, SmoothingStrategy.smooth_production_sources)

    expected = '(( A_[(r)]-{p} | A_[(r)]-{0} ) & ( A_[b]--0 | A_[b]--B_[a] )) & ' \
               '( A_[b]_ppi-_B_[a] & ( A_[b]--B_[a] | ( A_[b]_ppi+_B_[a] & A_[b]--0 & B_[a]--0 )) | ' \
               '( A_[b]--0 & ~( A_[b]_ppi+_B_[a] & A_[b]--0 & B_[a]--0 )))'

    for rule in boolean_model.update_rules:
        if rule.target == target_from_str('A_[b]--0'):
            assert rule.factor.is_equivalent_to(
                venn_from_str(expected, target_from_str))
Esempio n. 19
0
def test_state_target_properties() -> None:
    """
    Testing the relation between states and reactions not tested before.

    Returns:
        None

    """
    boolean_model = boolean_model_from_rxncon(
        Quick("""C_deg_A
                                                    C_syn_A
                                                    C_p+_A_[(x)]
                                                    C_p-_A_[(x)]""").
        rxncon_system)

    neutral_state = target_from_str('A_[(x)]-{0}')

    assert isinstance(neutral_state, StateTarget)
    assert boolean_model.state_target_by_name('A_[(x)]-{p}').is_produced_by(
        boolean_model.reaction_target_by_name('C_p+_A_[(x)]'))
    assert boolean_model.state_target_by_name('A_[(x)]-{p}').is_consumed_by(
        boolean_model.reaction_target_by_name('C_p-_A_[(x)]'))
    assert boolean_model.state_target_by_name('A_[(x)]-{p}').is_degraded_by(
        boolean_model.reaction_target_by_name('C_deg_A'))
    assert boolean_model.reaction_target_by_name(
        'C_syn_A').synthesises_component(neutral_state.components[0])
    assert boolean_model.state_target_by_name('A_[(x)]-{0}').is_synthesised_by(
        boolean_model.reaction_target_by_name('C_syn_A'))
Esempio n. 20
0
def test_trsl_trsc_deg() -> None:
    boolean_model = boolean_model_from_rxncon(
        Quick("""PolII_trsc_TargetGene
                                                       Ribo_trsl_TargetmRNA
                                                       Nuclease_deg_TargetmRNA
                                                       Protease_deg_Target""").
        rxncon_system)

    expected_rules = {
        'PolII_trsc_TargetGene': '( PolII & TargetGene )',
        'Ribo_trsl_TargetmRNA': '( Ribo & TargetmRNA )',
        'Nuclease_deg_TargetmRNA': '( Nuclease & TargetmRNA )',
        'Protease_deg_Target': '( Protease & Target )',
        'PolII': '( PolII )',
        'TargetGene': '( TargetGene )',
        'Ribo': '( Ribo )',
        'TargetmRNA':
        '( PolII_trsc_TargetGene | ( TargetmRNA & ~( Nuclease_deg_TargetmRNA )))',
        'Nuclease': '( Nuclease )',
        'Protease': '( Protease )',
        'Target':
        '( Ribo_trsl_TargetmRNA | ( Target & ~( Protease_deg_Target )))'
    }

    assert len(boolean_model.update_rules) == len(expected_rules)

    for update_rule in boolean_model.update_rules:
        assert update_rule.factor.is_equivalent_to(
            venn_from_str(expected_rules[str(update_rule.target)],
                          target_from_str))
Esempio n. 21
0
def test_deg_with_boolean_NOT() -> None:
    """
    Testing degradation with NOT Boolean.

    Returns:
        None

    Raises:
        AssertionError if a rule is not equivalent to an expected rule.

    """
    boolean_model = boolean_model_from_rxncon(
        Quick("""A_[x]_ppi+_B_[y]
                                                       D_p+_A_[(r)]
                                                       C_deg_A; ! <x>
                                                       <x>; AND A_[x]--B_[y]; AND <NOT>
                                                       <NOT>; NOT A_[(r)]-{p}"""
              ).rxncon_system)
    target_to_factor = {
        rule.target: rule.factor
        for rule in boolean_model.update_rules
    }

    expected_rules = {
        'C_deg_A':
        '( C & A_[x]--B_[y] & ~( A_[(r)]-{p} ) & ( A_[x]--0 | A_[x]--B_[y] ) & ( A_[(r)]-{0} | A_[(r)]-{p} ))',
        'B_[y]--0':
        '(( A_[x]--B_[y] & C_deg_A & ( B_[y]--0 | A_[x]--B_[y] )) | ( B_[y]--0 & ( B_[y]--0 | A_[x]--B_[y] ) & ~(( B_[y]--0 & A_[x]_ppi+_B_[y] & A_[x]--0 ))))',
        'A_[(r)]-{p}':
        '(( A_[(r)]-{0} & D_p+_A_[(r)] & ( A_[x]--0 | A_[x]--B_[y] ) & ( A_[(r)]-{0} | A_[(r)]-{p} )) | ( A_[(r)]-{p} & ( A_[x]--0 | A_[x]--B_[y] ) & ( A_[(r)]-{0} | A_[(r)]-{p} )))',
    }

    for target_str, factor_str in expected_rules.items():
        assert target_to_factor[target_from_str(target_str)].is_equivalent_to(
            venn_from_str(factor_str, target_from_str))
Esempio n. 22
0
def test_layout_remains_correct_when_adding_node() -> None:
    """
    Testing if the new graph gets the correct layout of the old graph if we add an additional node.

    Returns:
        None

    Raises:
        AssertionError: If the node coordinates of the new graph differ from expected coordinates.

    """
    test_case = Quick("""A_[b]_ppi+_B_[a]; ! A_[(c)]-{p}
                         C_p+_A_[(c)]; ! C_[d]--D_[c]
                         C_[d]_ppi+_D_[c]""")

    reg_graph = RegulatoryGraph(test_case.rxncon_system)
    gml_system = XGMML(reg_graph.to_graph(), "add_node")
    mapped_layout = map_layout2xgmml(gml_system.to_string(), NODE_LAYOUT_MANIPULATION)
    xmldoc_no_layout = minidom.parseString(mapped_layout)
    xmldoc_no_layout_info = _get_labels_and_coordinates_dict(xmldoc_no_layout)
    xmldoc_expected_layout = minidom.parse(NODE_LAYOUT_MANIPULATION)
    xmldoc_expected_layout_info = _get_labels_and_coordinates_dict(xmldoc_expected_layout)

    assert all(xmldoc_no_layout_info[no_layout_node] == xmldoc_expected_layout_info[no_layout_node]
               for no_layout_node in xmldoc_no_layout_info)
    assert all(xmldoc_no_layout_info[expected_layout_node] == xmldoc_expected_layout_info[expected_layout_node]
               for expected_layout_node in xmldoc_expected_layout_info)
Esempio n. 23
0
def test_single_contingency() -> None:
    rxncon_sys = Quick('''A_p+_B_[(r)]; ! A_[(x)]-{p}
                       C_p+_A_[(x)]''').rxncon_system
    assert state_from_str('A_[(x)]-{0}') in rxncon_sys.consumed_states
    assert state_from_str('B_[(r)]-{0}') in rxncon_sys.consumed_states
    assert state_from_str('A_[(x)]-{p}') in rxncon_sys.produced_states
    assert state_from_str('B_[(r)]-{p}') in rxncon_sys.produced_states

    assert state_from_str('A_[(x)]-{0}') in rxncon_sys.states_for_component(spec_from_str('A'))
    assert state_from_str('B_[(r)]-{0}') in rxncon_sys.states_for_component(spec_from_str('B'))
    assert state_from_str('A_[(x)]-{p}') in rxncon_sys.states_for_component(spec_from_str('A'))
    assert state_from_str('B_[(r)]-{p}') in rxncon_sys.states_for_component(spec_from_str('B'))

    contingencies = rxncon_sys.contingencies_for_reaction(reaction_from_str('A_p+_B_[(r)]'))
    assert len(contingencies) == 1
    assert contingencies[0].effector.states == [state_from_str('A@0_[(x)]-{p}')]
    assert contingencies[0].contingency_type == ContingencyType.requirement
Esempio n. 24
0
def test_boolnet_export() -> None:
    model = boolean_model_from_rxncon(Quick("""C_deg_A""").rxncon_system)
    boolnet_str, mapping, init_values = boolnet_from_boolean_model(model)
    assert 'targets, factors' in boolnet_str
    assert all(target in mapping.values()
               for target in list(model._reaction_targets.keys()) +
               list(model._state_targets.keys()))
    assert len(mapping) == len(init_values)
    assert all(init_values[key] == model.initial_conditions.target_to_value[
        target_from_str(value)] for key, value in mapping.items())
Esempio n. 25
0
def test_matching_non_matching_input_one_output() -> None:
    """
    Testing if output reactions with one matching and one non matching input states.

    Returns:
        None

    Raises:
        Assertion error if the update rules are not as expected.

    """
    boolean_model = boolean_model_from_rxncon(
        Quick("""A_p+_B_[(a)]; ! [global]
                                                        A_p+_B_[(a1)]; ! [global_diff]
                                                        [global]; ! B_[(a)]-{p}"""
              ).rxncon_system)

    # Component expressions.
    A = 'A'
    B = '( B_[(a)]-{0} | B_[(a)]-{p} ) & ( B_[(a1)]-{0} | B_[(a1)]-{p} )'

    expected_rules = {
        'A_p+_B_[(a)]': '{0} & {1} & [global]'.format(A, B),
        'A_p+_B_[(a1)]': '{0} & {1} & [global_diff]'.format(A, B),
        '[global]': 'B_[(a)]-{p}',
        '[global_diff]': '[global_diff]'
    }

    rules_found = 0

    for update_rule in boolean_model.update_rules:
        if str(update_rule.target) == 'A_p+_B_[(a)]':
            assert update_rule.factor.is_equivalent_to(
                venn_from_str(expected_rules[str(update_rule.target)],
                              target_from_str))
            rules_found += 1
        elif str(update_rule.target) == 'A_p+_B_[(a1)]':
            assert update_rule.factor.is_equivalent_to(
                venn_from_str(expected_rules[str(update_rule.target)],
                              target_from_str))
            rules_found += 1
        elif str(update_rule.target) == '[global]':
            assert isinstance(update_rule.target, StateTarget)
            assert update_rule.factor.is_equivalent_to(
                venn_from_str(expected_rules[str(update_rule.target)],
                              target_from_str))
            rules_found += 1
        elif str(update_rule.target) == '[global_diff]':
            assert isinstance(update_rule.target, StateTarget)
            assert update_rule.factor.is_equivalent_to(
                venn_from_str(expected_rules[str(update_rule.target)],
                              target_from_str))
            rules_found += 1
    assert rules_found == 4
Esempio n. 26
0
def test_set_initial_condition() -> None:
    boolean_model = boolean_model_from_rxncon(
        Quick("""C_p+_A_[(x)]""").rxncon_system)

    neutral_state = target_from_str('A_[(x)]-{0}')
    assert boolean_model.initial_conditions.target_to_value[
        neutral_state] == True

    boolean_model.set_initial_condition(neutral_state, False)
    assert boolean_model.initial_conditions.target_to_value[
        neutral_state] == False
Esempio n. 27
0
def test_kplus_overlaps_with_reaction() -> None:
    rxncon_system = Quick("""A_p+_B_[(s)]; ! <Aphos> ; k+ A_[(r1)]-{p} ; k+ A_[(r2)]-{p}
                          <Aphos>; OR A_[(r1)]-{p}
                          <Aphos>; OR A_[(r2)]-{p}
                          C_p+_A_[(r1)]
                          D_p+_A_[(r2)]""").rxncon_system

    rbm = rule_based_model_from_rxncon(rxncon_system)

    for rule in rbm.rules:
        print(rule)
Esempio n. 28
0
def test_simple_system_with_input_state() -> None:
    boolean_model = boolean_model_from_rxncon(
        Quick("""A_[b]_ppi+_B_[a]; ! A_[(r)]-{p} ; ! [BLAAT]
                                                        A_[b]_ppi-_B_[a]
                                                        C_p+_A_[(r)]
                                                        D_p-_A_[(r)]""").
        rxncon_system)

    # Component expressions.
    A = '(( A_[b]--0 | A_[b]--B_[a] ) & ( A_[(r)]-{0} | A_[(r)]-{p} ))'
    B = '( B_[a]--0 | A_[b]--B_[a] )'
    C = 'C'
    D = 'D'

    expected_rules = {
        'A_[b]_ppi+_B_[a]':
        '{0} & {1} & A_[(r)]-{{p}} & [BLAAT]'.format(A, B),
        'A_[b]_ppi-_B_[a]':
        '{0} & {1}'.format(A, B),
        'C_p+_A_[(r)]':
        '{0} & {1}'.format(A, C),
        'D_p-_A_[(r)]':
        '{0} & {1}'.format(A, D),
        'A_[(r)]-{p}':
        '{0} & (( C_p+_A_[(r)] & A_[(r)]-{{0}} ) | '
        '( A_[(r)]-{{p}} & ~( D_p-_A_[(r)] & A_[(r)]-{{p}} )))'.format(A),
        'A_[(r)]-{0}':
        '{0} & (( D_p-_A_[(r)] & A_[(r)]-{{p}} ) | '
        '( A_[(r)]-{{0}} & ~( C_p+_A_[(r)] & A_[(r)]-{{0}} )))'.format(A),
        'A_[b]--0':
        '{0} & (( A_[b]_ppi-_B_[a] & A_[b]--B_[a] ) | '
        '( A_[b]--0 & ~( A_[b]_ppi+_B_[a] & A_[b]--0 & B_[a]--0 )))'.format(A),
        'A_[b]--B_[a]':
        '{0} & {1} & (( A_[b]_ppi+_B_[a] & A_[b]--0 & B_[a]--0 ) | '
        '( A_[b]--B_[a] & ~( A_[b]_ppi-_B_[a] & A_[b]--B_[a] )))'.format(A, B),
        'B_[a]--0':
        '{0} & (( A_[b]_ppi-_B_[a] & A_[b]--B_[a] ) | '
        '( B_[a]--0 & ~( A_[b]_ppi+_B_[a] & A_[b]--0 & B_[a]--0 )))'.format(B),
        'C':
        '{0}'.format(C),
        'D':
        '{0}'.format(D),
        '[BLAAT]':
        '[BLAAT]'
    }

    assert len(boolean_model.update_rules) == len(expected_rules)

    for update_rule in boolean_model.update_rules:
        assert update_rule.factor.is_equivalent_to(
            venn_from_str(expected_rules[str(update_rule.target)],
                          target_from_str))
Esempio n. 29
0
def test_degradation_bond_to_homodimer() -> None:
    rxncon_sys = Quick("""A_[b]_ppi_B_[a]
                          B_[b]_ppi_B_[b]
                          C_deg_A; ! <x>
                          <x>; AND A@1--B@2
                          <x>; AND B@2--B@3""").rxncon_system

    boolean_model = boolean_model_from_rxncon(rxncon_sys)

    assert boolean_model.reaction_target_by_name(
        'C_deg_A').consumed_targets == [target_from_str('A_[b]--B_[a]')]
    assert boolean_model.reaction_target_by_name(
        'C_deg_A').produced_targets == [target_from_str('B_[a]--0')]
def test_simple_system() -> None:
    rbm = rule_based_model_from_rxncon(Quick("""A_[b]_ppi+_B_[a]; ! A_[(r)]-{p}
                                             A_[b]_ppi-_B_[a]
                                             C_p+_A_[(r)]
                                             D_p-_A_[(r)]""").rxncon_system)

    expected_bngl = '''begin model
begin parameters
NumA		100
NumB		100
NumC		100
NumD		100
k		1.0
end parameters

begin molecule types
A(bD,rR~0~p)
B(aD)
C()
D()
end molecule types

begin seed species
A(bD,rR~0)	NumA
B(aD)	NumB
C()	NumC
D()	NumD
end seed species

begin observables

end observables

begin reaction rules
# A_[b]_ppi+_B_[a]
A(bD,rR~p) + B(aD) -> A(bD!1,rR~p).B(aD!1)   k
# A_[b]_ppi-_B_[a]
A(bD!1).B(aD!1) -> A(bD) + B(aD)   k
# C_p+_A_[(r)]
A(rR~0) + C() -> A(rR~p) + C()   k
# D_p-_A_[(r)]
A(rR~p) + D() -> A(rR~0) + D()   k
end reaction rules

end model

simulate_nf({t_end=>100,n_steps=>10});
'''

    assert bngl_from_rule_based_model(rbm) == expected_bngl