Пример #1
0
    def test_entity_needed(self):
        evidence = Evidence(assertion="Localization")

        assert evidence.is_valid() is None

        evidence.set_entity(self.gene)

        assert evidence.is_valid() is None

        evidence.set_target(self.compartment)

        assert evidence.is_valid() is not None
Пример #2
0
def parse_evidences_from_xml(model_node, model, progress=None):

    list_of_evidences_node = model_node.find(ge_listOfEvidences)

    if list_of_evidences_node is None:
        return
    elif progress is None:
        pass
    elif not progress.wasCanceled():
        progress.setLabelText("Reading evidences...")
        progress.setRange(0, len(list_of_evidences_node))
    else:
        return

    for i, evidence_node in enumerate(
            list_of_evidences_node.iterfind(ge_evidence)):

        if progress is None:
            pass
        elif not progress.wasCanceled():
            progress.setValue(i)
            QApplication.processEvents()
        else:
            return

        new_evidence = Evidence(internal_id=evidence_node.get("id"),
                                assertion=evidence_node.get("assertion"),
                                comment=evidence_node.get("comment"),
                                eco=evidence_node.get("eco"))

        entity_id = evidence_node.get("entity_id")
        entity_type = evidence_node.get("entity_type")

        entity = get_item_from_model(entity_type, entity_id, model)
        new_evidence.set_entity(entity)

        # Add target item if present
        target_id = evidence_node.get("target_id")
        target_type = evidence_node.get("target_type")
        if target_id and target_type:
            target = get_item_from_model(target_type, target_id, model)
            new_evidence.set_target(target)

        # Add all references if present
        reference_list_node = evidence_node.find(ge_listOfReferenceLinks)
        if reference_list_node is not None:
            for refLink_node in reference_list_node.iterfind(ge_referenceLink):
                new_evidence.add_reference(
                    model.references[refLink_node.get("id")])

        model.all_evidences[new_evidence.internal_id] = new_evidence
Пример #3
0
    def test_override_target(self):
        entity = Reaction()
        target = Gene()
        eco = "ECO:000000"
        assertion = "Presence"
        comment = "test comment"
        reference = Reference()
        evidence = Evidence(entity=entity,
                            eco=eco,
                            assertion=assertion,
                            comment=comment,
                            target=target)
        evidence.add_reference(reference)

        new_gene = Gene()
        evidence.set_target(new_gene)

        # Check disconnection of old reaction
        assert evidence.target is new_gene
        assert evidence not in target.evidences
Пример #4
0
class TestModelDeleteItems:

    @pytest.fixture(autouse=True)
    def setup_complete_model(self):
        self.model = Model("model")

        # Setup reaction1
        self.metabolite = Metabolite("m1")
        self.reaction = Reaction("r1")
        self.gene = Gene("g1")
        self.reaction.add_child(self.gene)
        self.model.add_genes((self.gene,))
        self.reaction.add_metabolites({self.metabolite: -1})
        self.model.add_reactions((self.reaction,))

        # Setup reaction2
        self.metabolite2 = Metabolite("m2")
        self.reaction2 = Reaction("r2")
        self.gene2 = Gene("g2")
        self.genegroup = GeneGroup()
        self.genegroup.add_child(self.gene2)
        self.reaction2.add_child(self.genegroup)
        self.model.add_genes((self.gene2,))
        self.reaction2.add_metabolites({self.metabolite2: 1})
        self.model.add_reactions((self.reaction2,))

        # Setup evidences
        self.evidence = Evidence(assertion="Catalyzes")
        self.evidence.set_entity(self.gene)
        self.evidence.set_target(self.reaction)
        self.reference = Reference()
        self.model.add_reference(self.reference)
        self.evidence.add_reference(self.reference)
        self.model.add_evidence(self.evidence)

        # Setup test case
        self.testcase = ModelTest()
        reaction_setting = ReactionSetting(self.reaction, 1000., -1000., 0.)
        gene_setting = GeneSetting(gene=self.gene2, activity=False)
        outcome = Outcome(self.reaction2, 0., "greater")
        self.testcase.add_outcome(outcome)
        self.testcase.add_setting(gene_setting)
        self.testcase.add_setting(reaction_setting)
        self.model.add_test(self.testcase)
        self.reference2 = Reference()
        self.model.add_reference(self.reference2)
        self.testcase.add_reference(self.reference2)

        self.model.setup_tables()

    def test_setup(self):
        # Test genes
        gene_in_model(self.gene, self.model)
        gene_in_model(self.gene2, self.model)

        # Test reactions
        reaction_in_model(self.reaction, self.model)
        reaction_in_model(self.reaction2, self.model)

        # Test metabolites
        metabolite_in_model(self.metabolite, self.model)
        metabolite_in_model(self.metabolite2, self.model)

        # Test evidences
        evidence_in_model(self.evidence, self.model)

        # Test model test
        case_in_model(self.testcase, self.model)

        # Test references
        reference_in_model(self.reference, self.model)
        reference_in_model(self.reference2, self.model)

        # Test connections
        # Reference <-> Evidence
        reference_in_item(self.reference, self.evidence)
        # Reference2 <-> Testcase
        reference_in_item(self.reference2, self.testcase)

        # Gene1 <-> Reaction1
        gene_in_reaction(self.gene, self.reaction)
        gene_in_reaction(self.gene2, self.reaction2)

        # Metabolite1 <-> Reaction1
        metabolite_in_reaction(self.metabolite, self.reaction)
        metabolite_in_reaction(self.metabolite2, self.reaction2)

        # Evidence <-> Gene1/Reaction
        item_in_evidence(self.gene, self.evidence)
        item_in_evidence(self.reaction, self.evidence)

    def test_deletion_metabolite(self):
        # Action
        self.model.gem_remove_metabolites((self.metabolite,))

        # Test gene
        gene_in_model(self.gene, self.model)
        gene_in_model(self.gene2, self.model)

        # Test reactions
        reaction_in_model(self.reaction, self.model)
        reaction_in_model(self.reaction2, self.model)

        # Test metabolites
        metabolite_in_model(self.metabolite, self.model, valid=False)
        metabolite_in_model(self.metabolite2, self.model)

        # Test evidences
        evidence_in_model(self.evidence, self.model)

        # Test model test
        case_in_model(self.testcase, self.model)

        # Test references
        reference_in_model(self.reference, self.model)
        reference_in_model(self.reference2, self.model)

        # Test connections
        # Reference <-> Evidence
        reference_in_item(self.reference, self.evidence)
        # Reference2 <-> Testcase
        reference_in_item(self.reference2, self.testcase)

        # Gene1 <-> Reaction1
        gene_in_reaction(self.gene, self.reaction)
        gene_in_reaction(self.gene2, self.reaction2)

        # Metabolite1 <-> Reaction1
        metabolite_in_reaction(self.metabolite, self.reaction, valid=False)
        metabolite_in_reaction(self.metabolite2, self.reaction2)

        # Evidence <-> Gene1/Reaction
        item_in_evidence(self.gene, self.evidence)
        item_in_evidence(self.reaction, self.evidence)

    def test_deletion_metabolite2(self):
        # Action
        self.model.gem_remove_metabolites((self.metabolite2,))

        # Test genes
        gene_in_model(self.gene, self.model)
        gene_in_model(self.gene2, self.model)

        # Test reactions
        reaction_in_model(self.reaction, self.model)
        reaction_in_model(self.reaction2, self.model)

        # Test metabolites
        metabolite_in_model(self.metabolite, self.model)
        metabolite_in_model(self.metabolite2, self.model, valid=False)

        # Test evidences
        evidence_in_model(self.evidence, self.model)

        # Test model test
        case_in_model(self.testcase, self.model)

        # Test references
        reference_in_model(self.reference, self.model)
        reference_in_model(self.reference2, self.model)

        # Test connections
        # Reference <-> Evidence
        reference_in_item(self.reference, self.evidence)
        # Reference2 <-> Testcase
        reference_in_item(self.reference2, self.testcase)

        # Gene1 <-> Reaction1
        gene_in_reaction(self.gene, self.reaction)
        gene_in_reaction(self.gene2, self.reaction2)

        # Metabolite1 <-> Reaction1
        metabolite_in_reaction(self.metabolite, self.reaction)
        metabolite_in_reaction(self.metabolite2, self.reaction2, valid=False)

        # Evidence <-> Gene1/Reaction
        item_in_evidence(self.gene, self.evidence)
        item_in_evidence(self.reaction, self.evidence)

    def test_delete_reaction1(self):
        ####
        # Delete reaction
        # Check:
        #   - gene present but removed from reaction1
        #   - metabolite present but removed from reaction1
        #   - reaction deleted
        #   - evidence deleted
        #   - testcase deleted
        #   - reference present but removed from evidence
        #   - reference2 present but removed from testcase
        ####

        # Action
        self.model.gem_remove_reactions((self.reaction,))

        # Test genes
        gene_in_model(self.gene, self.model)
        gene_in_model(self.gene2, self.model)

        # Test reactions
        reaction_in_model(self.reaction, self.model, valid=False)
        reaction_in_model(self.reaction2, self.model)

        # Test metabolites
        metabolite_in_model(self.metabolite, self.model)
        metabolite_in_model(self.metabolite2, self.model)

        # Test model test
        case_in_model(self.testcase, self.model, valid=False)

        # Test references
        reference_in_model(self.reference, self.model)
        reference_in_model(self.reference2, self.model)

        # Test connections
        # Reference <-> Evidence
        reference_in_item(self.reference, self.evidence, valid=False)
        reference_in_item(self.reference2, self.testcase, valid=False)

        # Gene1 <-> Reaction1
        gene_in_reaction(self.gene, self.reaction, valid=False)
        gene_in_reaction(self.gene2, self.reaction2)

        # Metabolite1 <-> Reaction1
        # Check metabolite is still in reaction, but reaction not in metabolite
        assert self.metabolite in self.reaction.metabolites
        assert self.reaction not in self.metabolite.reactions
        metabolite_in_reaction(self.metabolite2, self.reaction2)

        # Evidence <-> Gene1/Reaction
        item_in_evidence(self.gene, self.evidence, valid=False)
        item_in_evidence(self.reaction, self.evidence, valid=False)

        # Check evidence is removed when reference deleted
        del self.evidence
        gc.collect()
        assert len(self.model.all_evidences) == 0

    def test_deletion_reaction2(self):
        # Check:
        #   - reaction2 removed
        #   - test case removed
        #   - reference removed from testcase
        #   - gene2 removed from reaction

        # Action
        self.model.gem_remove_reactions((self.reaction2,))

        # Test genes
        gene_in_model(self.gene, self.model)
        gene_in_model(self.gene2, self.model)

        # Test reactions
        reaction_in_model(self.reaction, self.model)
        reaction_in_model(self.reaction2, self.model, valid=False)

        # Test metabolites
        metabolite_in_model(self.metabolite, self.model)
        metabolite_in_model(self.metabolite2, self.model)

        # Test evidences
        evidence_in_model(self.evidence, self.model)

        # Test model test
        case_in_model(self.testcase, self.model, valid=False)

        # Test references
        reference_in_model(self.reference, self.model)
        reference_in_model(self.reference2, self.model)

        # Test connections
        # Reference <-> Evidence
        reference_in_item(self.reference, self.evidence)
        # Reference2 <-> Testcase
        reference_in_item(self.reference2, self.testcase, valid=False)

        # Gene1 <-> Reaction1
        gene_in_reaction(self.gene, self.reaction)
        gene_in_reaction(self.gene2, self.reaction2, valid=False)

        # Metabolite1 <-> Reaction1
        metabolite_in_reaction(self.metabolite, self.reaction)
        # Check metabolite still in reaction, but reaction not in metabolite
        assert self.metabolite2 in self.reaction2.metabolites
        assert self.reaction2 not in self.metabolite2.reactions

        # Evidence <-> Gene1/Reaction
        item_in_evidence(self.gene, self.evidence)
        item_in_evidence(self.reaction, self.evidence)

    def test_delete_gene1(self):
        # Test gene deletion
        # Check:
        #   - Gene removed from model
        #   - Evidence removed from model

        # Action
        self.model.gem_remove_genes((self.gene,))

        # Test genes
        gene_in_model(self.gene, self.model, valid=False)
        gene_in_model(self.gene2, self.model)

        # Test reactions
        reaction_in_model(self.reaction, self.model)
        reaction_in_model(self.reaction2, self.model)

        # Test metabolites
        metabolite_in_model(self.metabolite, self.model)
        metabolite_in_model(self.metabolite2, self.model)

        # Test model test
        case_in_model(self.testcase, self.model)

        # Test references
        reference_in_model(self.reference, self.model)
        reference_in_model(self.reference2, self.model)

        # Test connections
        # Reference <-> Evidence
        reference_in_item(self.reference, self.evidence, valid=False)
        # Reference2 <-> Testcase
        reference_in_item(self.reference2, self.testcase)

        # Gene1 <-> Reaction1
        gene_in_reaction(self.gene, self.reaction, valid=False)
        gene_in_reaction(self.gene2, self.reaction2)

        # Metabolite1 <-> Reaction1
        metabolite_in_reaction(self.metabolite, self.reaction)
        metabolite_in_reaction(self.metabolite2, self.reaction2)

        # Evidence <-> Gene1/Reaction
        item_in_evidence(self.gene, self.evidence, valid=False)
        item_in_evidence(self.reaction, self.evidence, valid=False)

        # Check evidence is removed when reference deleted
        del self.evidence
        gc.collect()
        assert len(self.model.all_evidences) == 0

    def test_delete_gene2(self):
        # Test removal of gene2
        # Check:
        #   - Gene2 removed from model
        #   - Gene2 removed from reaction2
        #   - Testcase deleted from model
        #   - Reference2 removed from testcase

        # Action
        self.model.gem_remove_genes((self.gene2,))

        # Test genes
        gene_in_model(self.gene, self.model)
        gene_in_model(self.gene2, self.model, valid=False)

        # Test reactions
        reaction_in_model(self.reaction, self.model)
        reaction_in_model(self.reaction2, self.model)

        # Test metabolites
        metabolite_in_model(self.metabolite, self.model)
        metabolite_in_model(self.metabolite2, self.model)

        # Test evidences
        evidence_in_model(self.evidence, self.model)

        # Test model test
        case_in_model(self.testcase, self.model, valid=False)

        # Test references
        reference_in_model(self.reference, self.model)
        reference_in_model(self.reference2, self.model)

        # Test connections
        # Reference <-> Evidence
        reference_in_item(self.reference, self.evidence)
        # Reference2 <-> Testcase
        reference_in_item(self.reference2, self.testcase, valid=False)

        # Gene1 <-> Reaction1
        gene_in_reaction(self.gene, self.reaction)
        gene_in_reaction(self.gene2, self.reaction2, valid=False)

        # Metabolite1 <-> Reaction1
        metabolite_in_reaction(self.metabolite, self.reaction)
        metabolite_in_reaction(self.metabolite2, self.reaction2)

        # Evidence <-> Gene1/Reaction
        item_in_evidence(self.gene, self.evidence)
        item_in_evidence(self.reaction, self.evidence)

    def test_delete_testcase(self):
        # Action
        self.model.gem_remove_tests((self.testcase,))

        # Test genes
        gene_in_model(self.gene, self.model)
        gene_in_model(self.gene2, self.model)

        # Test reactions
        reaction_in_model(self.reaction, self.model)
        reaction_in_model(self.reaction2, self.model)

        # Test metabolites
        metabolite_in_model(self.metabolite, self.model)
        metabolite_in_model(self.metabolite2, self.model)

        # Test evidences
        evidence_in_model(self.evidence, self.model)

        # Test model test
        case_in_model(self.testcase, self.model, valid=False)

        # Test references
        reference_in_model(self.reference, self.model)
        reference_in_model(self.reference2, self.model)

        # Test connections
        # Reference <-> Evidence
        reference_in_item(self.reference, self.evidence)
        # Reference2 <-> Testcase
        reference_in_item(self.reference2, self.testcase, valid=False)

        # Gene1 <-> Reaction1
        gene_in_reaction(self.gene, self.reaction)
        gene_in_reaction(self.gene2, self.reaction2)

        # Metabolite1 <-> Reaction1
        metabolite_in_reaction(self.metabolite, self.reaction)
        metabolite_in_reaction(self.metabolite2, self.reaction2)

        # Evidence <-> Gene1/Reaction
        item_in_evidence(self.gene, self.evidence)
        item_in_evidence(self.reaction, self.evidence)

    def test_delete_referenec(self):
        # Action
        self.model.gem_remove_references((self.reference,))

        # Test genes
        gene_in_model(self.gene, self.model)
        gene_in_model(self.gene2, self.model)

        # Test reactions
        reaction_in_model(self.reaction, self.model)
        reaction_in_model(self.reaction2, self.model)

        # Test metabolites
        metabolite_in_model(self.metabolite, self.model)
        metabolite_in_model(self.metabolite2, self.model)

        # Test evidences
        evidence_in_model(self.evidence, self.model)

        # Test model test
        case_in_model(self.testcase, self.model)

        # Test references
        reference_in_model(self.reference, self.model, valid=False)
        reference_in_model(self.reference2, self.model)

        # Test connections
        # Reference <-> Evidence
        reference_in_item(self.reference, self.evidence, valid=False)
        # Reference2 <-> Testcase
        reference_in_item(self.reference2, self.testcase)

        # Gene1 <-> Reaction1
        gene_in_reaction(self.gene, self.reaction)
        gene_in_reaction(self.gene2, self.reaction2)

        # Metabolite1 <-> Reaction1
        metabolite_in_reaction(self.metabolite, self.reaction)
        metabolite_in_reaction(self.metabolite2, self.reaction2)

        # Evidence <-> Gene1/Reaction
        item_in_evidence(self.gene, self.evidence)
        item_in_evidence(self.reaction, self.evidence)

    def test_delete_reference2(self):
        # Action
        self.model.gem_remove_references((self.reference2,))

        # Test genes
        gene_in_model(self.gene, self.model)
        gene_in_model(self.gene2, self.model)

        # Test reactions
        reaction_in_model(self.reaction, self.model)
        reaction_in_model(self.reaction2, self.model)

        # Test metabolites
        metabolite_in_model(self.metabolite, self.model)
        metabolite_in_model(self.metabolite2, self.model)

        # Test evidences
        evidence_in_model(self.evidence, self.model)

        # Test model test
        case_in_model(self.testcase, self.model)

        # Test references
        reference_in_model(self.reference, self.model)
        reference_in_model(self.reference2, self.model, valid=False)

        # Test connections
        # Reference <-> Evidence
        reference_in_item(self.reference, self.evidence)
        # Reference2 <-> Testcase
        reference_in_item(self.reference2, self.testcase, valid=False)

        # Gene1 <-> Reaction1
        gene_in_reaction(self.gene, self.reaction)
        gene_in_reaction(self.gene2, self.reaction2)

        # Metabolite1 <-> Reaction1
        metabolite_in_reaction(self.metabolite, self.reaction)
        metabolite_in_reaction(self.metabolite2, self.reaction2)

        # Evidence <-> Gene1/Reaction
        item_in_evidence(self.gene, self.evidence)
        item_in_evidence(self.reaction, self.evidence)