コード例 #1
0
    def test_merging_reaction(self):
        model = Model("m1")

        react1 = Reaction("r1")
        anno1 = Annotation(collection="ec-code", identifier="2.1.7.0")
        react1.add_annotation(anno1)
        evidence1 = Evidence(entity=react1)
        gene1 = Gene("g1")
        react1.add_child(gene1)
        model.add_evidence(evidence1)

        react2 = Reaction("r2")
        anno2 = Annotation(collection="ec-code", identifier="2.1.7.1")
        react2.add_annotation(anno2)
        evidence2 = Evidence(entity=react2)
        gene2 = Gene("g2")
        react2.add_child(gene2)
        model.add_evidence(evidence2)

        react3 = Reaction("r3")
        anno3 = Annotation(collection="ec-code", identifier="2.1.7.1")
        react3.add_annotation(anno3)
        evidence3 = Evidence(entity=react3)
        gene3 = Gene("g3")
        react3.add_child(gene3)
        model.add_evidence(evidence3)

        model.add_genes((gene1, gene2, gene3))
        model.add_reactions((react1, react2, react3))
        model.setup_reaction_table()

        # Action
        merge_reactions([react1, react2, react3], react1)

        # Check annotation added
        assert anno1 in react1.annotation
        assert anno2 in react1.annotation
        assert anno3 in react3.annotation

        # Check evidences transferred during merge
        assert evidence2 not in react2.evidences
        assert evidence2 in react1.evidences
        assert react1 is evidence2.entity

        assert evidence3 not in react3.evidences
        assert evidence3 in react1.evidences
        assert react1 is evidence3.entity

        # Check merged reactions removed
        assert react2 not in model.reactions
        assert react3 not in model.reactions

        # Check genes transferred during merge
        assert react2 not in gene2.reactions
        assert react1 in gene2.reactions

        assert react3 not in gene3.reactions
        assert react1 in gene3.reactions

        # Check new genegroup is formed
        group = list(react1._children)[0]
        assert gene1 in group._children
        assert gene2 in group._children
        assert gene3 in group._children
        assert group.type == "or"
コード例 #2
0
    def test_get_reaction_statistics(self, progress):
        model = Model("model1")
        metabolite1 = Metabolite("m1")
        metabolite2 = Metabolite("m2")
        metabolite7 = Metabolite("m7")

        # Add inverted reactions
        reaction1 = Reaction("r1")
        reaction1.add_metabolites({metabolite1: -1, metabolite2: 1})
        reaction2 = Reaction("r2")
        reaction2.add_metabolites({metabolite1: 1, metabolite2: -1})

        # Add boundary reaction
        reaction3 = Reaction("r3")
        reaction3.add_metabolites({metabolite1: -1})

        # Add transport reaction
        metabolite3 = Metabolite("m3", compartment="c")
        metabolite4 = Metabolite("m4", compartment="e")
        reaction4 = Reaction("r4")
        reaction4.add_metabolites({metabolite3: -1, metabolite4: 1})

        # Add unbalanced reaction
        metabolite5 = Metabolite("m5", formula="H")
        metabolite6 = Metabolite("m6", formula="C")
        reaction5 = Reaction("r5")
        reaction5.add_metabolites({metabolite5: -1, metabolite6: 1})

        # Add reaction with gene
        reaction6 = Reaction("r6")
        reaction6.add_metabolites({metabolite1: -1, metabolite7: 1})
        gene = Gene()
        reaction6.add_child(gene)

        # Add reaction with annotation
        reaction7 = Reaction("r7")
        reaction7.add_metabolites({metabolite2: -1, metabolite7: 1})
        reaction7.add_annotation(Annotation("chebi", "CHEBI:1235"))

        model.add_reactions([
            reaction1, reaction2, reaction3, reaction4, reaction5, reaction6,
            reaction7
        ])

        # Action
        output_statistics = reaction_statistics(model)

        # Return value of reaction_statistics:
        #
        # ("Total", num_reactions),
        # ("Transport", num_transport),
        # ("Boundary", num_boundary),
        # ("Unbalanced", num_unbalanced),
        # ("Annotated", num_annotated),
        # ("No genes", num_no_genes),
        # ("Evidence for presence", num_has_presence_evidence),
        # ("Known gene", num_known_gene)

        # Check total state
        assert output_statistics["Total"] == 7

        # Check transport reactions
        assert output_statistics["Transport"] == 1

        # Check boundary reactions
        assert output_statistics["Boundary"] == 1

        # Check boundary reactions
        assert output_statistics["Unbalanced"] == 1

        # Check annotated
        assert output_statistics["Annotated"] == 1

        # Check no genes
        # Note: Boundary reactions are excluded from the counting
        assert output_statistics["No genes"] == 5

        # Check evidence for presence
        # Todo: Implement test
        assert True

        # Check known gene
        # Todo: Implement test
        assert True

        # Check that tests exist for all gathered statistics
        assert len(output_statistics) == 8  # Change to number of tests