def test_get_reaction_set_with_directionality(self): reaction = Reaction("React1") metabolite1 = Metabolite("Met1") metabolite2 = Metabolite("Met2") stoichiometry = {metabolite1: -1, metabolite2: 1} reaction.add_metabolites(stoichiometry) assert get_reaction_set(reaction, remove_directionality=False) == \ frozenset([frozenset([(metabolite1, -1)]), frozenset([(metabolite2, 1)])])
def test_merging_metabolites(self): met1 = Metabolite("m1") met2 = Metabolite("m2") met3 = Metabolite("m3") reaction = Reaction() original_metabolites = {met1: -1, met2: 1} reaction.add_metabolites(original_metabolites) merged = merge_metabolites([met1, met3], met3) # Check that met1 has been substituted with met3 assert merged == [met1] assert reaction.metabolites == {met3: -1, met2: 1}
def test_passes_custom_filter(self): """ Should raise not implemented error a number outside of options is chosen""" self.proxyModel.custom_filter = len(self.proxyModel.options) with pytest.raises(NotImplementedError): self.proxyModel.passes_custom_filter(Reaction())
def test_assigned_gene(self): custom_proxy = GeneProxyFilter() gene = Gene() reaction = Reaction() reaction.add_child(gene) # Test all genes custom_proxy.custom_filter = 0 assert custom_proxy.passes_custom_filter(gene) is True # Test unassigned custom_proxy.custom_filter = 1 assert custom_proxy.passes_custom_filter(gene) is False # Test all filters checked custom_proxy.custom_filter = 2 with pytest.raises(NotImplementedError): assert custom_proxy.passes_custom_filter(gene)
def test_add_coefficients_in_overlapping_reactions1(self): """ If merged metabolites are involved in the same reaction make sure the coefficients are added when merging. """ met1 = Metabolite("met1") met2 = Metabolite("met2") met3 = Metabolite("met3") react = Reaction("r1") react.add_metabolites({met1: -1, met2: -1, met3: 1}) merged = merge_metabolites([met1, met2], met1) assert merged == [met2] assert react.metabolites[met1] == -2 assert react.metabolites[met3] == 1
def test_group_duplicate_reactions(self): reaction1 = Reaction("React1") reaction2 = Reaction("React2") metabolite1 = Metabolite("Met1") metabolite2 = Metabolite("Met2") reaction1.add_metabolites({metabolite1: -1, metabolite2: 1}) reaction2.add_metabolites({metabolite1: 1, metabolite2: -1}) result = group_duplicate_reactions([reaction1, reaction2]) assert len(result) == 1 assert reaction1 in list(result.values())[0] assert reaction2 in list(result.values())[0]
def test_match_for_different_directionality(self): r1 = Reaction("r1") r2 = Reaction("r2") m1 = Metabolite("m1") m2 = Metabolite("m2") r1.add_metabolites({m1: -1, m2: 1}) r2.add_metabolites({m1: 1, m2: -1}) assert get_reaction_set(r1, remove_directionality=True) == \ get_reaction_set(r2, remove_directionality=True) assert get_reaction_set(r1, remove_directionality=False) != \ get_reaction_set(r2, remove_directionality=False)
def test_group_duplicates_reactions_different_reactions(self): reaction1 = Reaction("React1") reaction2 = Reaction("React2") metabolite1 = Metabolite("Met1") metabolite2 = Metabolite("Met2") reaction1.add_metabolites({metabolite1: -1, metabolite2: 1}) reaction2.add_metabolites({metabolite1: 1, metabolite2: -2}) result = group_duplicate_reactions([reaction1, reaction2]) assert len(result) == 2 assert all(len(x) == 1 for x in itertools.chain(result.values())) assert reaction1 in itertools.chain(*result.values()) assert reaction2 in itertools.chain(*result.values())
def test_get_gene_statistics(self): model = Model() reaction = Reaction("r1") annotation = Annotation("chebi", "CHEBI:1233") gene1 = Gene("g1") gene1.annotation.add(annotation) gene2 = Gene("g2") gene2.annotation.add(annotation) reaction.add_child(gene2) gene3 = Gene("g3") reaction.add_child(gene3) for x in [gene1, gene2, gene3]: model.add_gene(x) # Action gene_stats = gene_statistics(model) # Return value # ("Total", num_genes), # ("Unassigned", num_unassigned), # ("Verified location", num_exp_verified_localization), # ("Predicted location", num_predicted_localization), # ("Known function", num_known_function) # Check Total assert gene_stats["Total"] == 3 # Check Unassigned assert gene_stats["Unassigned"] == 1 # Check Verified location # Todo: Implement test assert True # Check Predicted location # Todo: Implement test assert True # Check Known function # Todo: Implement test assert True
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"
def transport_reaction(self): reaction = Reaction("r1") metabolite = Metabolite("m1", compartment="c") metabolite2 = Metabolite("m2", compartment="e") reaction.add_metabolites({metabolite: -1, metabolite2: 1}) return reaction
def normal_reaction(self): reaction = Reaction("r1") metabolite = Metabolite("m1") metabolite2 = Metabolite("m2") reaction.add_metabolites({metabolite: -1, metabolite2: 1}) return reaction
def boundary_reaction(self): reaction = Reaction("r1") metabolite = Metabolite("m1") reaction.add_metabolites({metabolite: -1}) return reaction
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