def setup_items(self): self.table = ReferenceTable() self.author1 = Author(lastname="FirstLast", firstname="FirstFirst", initials="FirstInitials") self.author2 = Author(lastname="SecondLast", firstname="SecondFirst", initials="SecondInitials") self.pmid = "123456" self.pmc = "PMC12345" self.url = "http://www.google.com" self.journal = "Test journal" self.year = "1987" self.title = "Test title" self.doi = "Test doi" self.reference = Reference(pmid=self.pmid, pmc=self.pmc, doi=self.doi, url=self.url, year=self.year, title=self.title, journal=self.journal, authors=[self.author1, self.author2])
def test_annotation_property(self): reference = Reference() reference.pmc = "1234" reference.pmid = "54321" reference.doi = "5555" assert Annotation("pubmed", reference.pmid) in reference.annotation assert Annotation("pmc", reference.pmc) in reference.annotation assert Annotation("doi", reference.doi) in reference.annotation
def test_saving_changes(self): reaction = Reaction() reference = Reference() model = Model() evidence = Evidence(entity=reaction) evidence.add_reference(reference) widget = EvidenceDisplayWidget() model.all_evidences[evidence.internal_id] = evidence assert evidence in reaction.evidences assert evidence.internal_id in model.all_evidences assert reference in evidence.references # Set reaction and model to widget widget.set_item(reaction, model) assert widget.dataTable.rowCount() == 1 # Remove evidence copy from data table widget.dataTable.setRowCount(0) # Setup new evidence item new_evidence = Evidence() new_evidence.assertion = "Catalyzed by" new_evidence.entity = reaction reference = Reference() new_evidence.add_reference(reference, reciprocal=False) # Test the setup i.e. that items are only linked in a one way (evidence -> item) fashion assert new_evidence not in reaction.evidences assert new_evidence not in reference.linked_items # Add new reference to widget table widget.dataTable.update_row_from_item(new_evidence) assert widget.dataTable.rowCount() == 1 assert widget.dataTable.item(0).link is new_evidence # Action - Save evidences widget.save_state() # Check that old instance is detached from all links assert evidence not in reaction.evidences assert len(evidence.references) == 0 # Old evidence still kept alive by this test old_id = evidence.internal_id assert old_id in model.all_evidences evidence = None gc.collect() assert old_id not in model.all_evidences # Check that new evidence is linked properly assert new_evidence in reaction.evidences assert new_evidence.internal_id in model.all_evidences
def test_full_example(self): """ Test that a minimal evidence example is parsed correctly """ xml_tree = ET.fromstring(full_evidence) model = Model() reaction = Reaction("Test") target_item = Gene("target_id") reference = Reference("ref_id") model.add_reaction(reaction) model.add_gene(target_item) model.add_reference(reference) assert len(model.all_evidences) == 0 assert len(reaction.evidences) == 0 parse_evidences_from_xml(xml_tree, model) assert len(model.all_evidences) == 1 assert len(reaction.evidences) == 1 evidence = list(reaction.evidences)[0] assert evidence.entity is reaction assert evidence.target is target_item assert evidence.assertion == "Catalyzed by" assert evidence.eco == "ECO:0000000" assert len(evidence.references) == 1 assert list(evidence.references)[0] is reference assert evidence.comment == "test comment"
def addItemSlot(self): reference = Reference() dialog = ReferenceEditDialog(reference) status = dialog.exec_() if status: self.dataTable.update_row_from_item(reference) self.model.add_reference(reference)
def get_reference(self): if self.information is None: return None try: doi = self.information.ids["doi"] except KeyError: doi = None try: pmc = self.information.ids["pmc"] except KeyError: pmc = None if self.information.journal.pubdate is not None: year = str(self.information.journal.pubdate.year) else: year = None return Reference(authors=self.information.authors, title=self.information.title, journal=self.information.journal.name, abstract="", pmid=self.pmid, doi=doi, pmc=pmc, year=year)
def test_copy_evidence(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) # Create copy copy = evidence.copy() # Check the correctness of the copy assert evidence.entity is copy.entity assert evidence.target is copy.target assert evidence.eco == copy.eco assert evidence.assertion == copy.assertion assert evidence.comment == copy.comment assert evidence.references == copy.references assert evidence.references is not copy.references # Check that the copy is not linked assert copy not in entity.evidences assert copy not in reference.linked_items assert copy not in target.evidences
def setup_items(self): self.first_author = Author(lastname="FirstLastname", firstname="FirstFirstname", initials="FirstInitials") self.second_author = Author(lastname="SecondLastname", firstname="SecondFirstname", initials="SecondInitials") self.authors = [self.first_author, self.second_author] self.test_pmid = "123456" self.test_pmc = "PMC12345" self.test_doi = "10.1016/j.chemosphere.2016.03.102" self.test_url = "http://google.com" self.test_year = "1999" self.test_title = "Test title" self.test_journal = "Test journal" self.test_ref_id = "Test_id" self.reference = Reference(id=self.test_ref_id, pmid=self.test_pmid, pmc=self.test_pmc, doi=self.test_doi, url=self.test_url, year=self.test_year, title=self.test_title, journal=self.test_journal, authors=self.authors) self.model = Model("Test") self.model.references[self.reference.id] = self.reference
def test_evidence_init(self): entity = Reaction() target = Gene("id2") 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) # Check proper linking assert evidence.entity is entity assert evidence in entity.evidences assert evidence.target is target assert evidence in target.evidences # Check attributes assert evidence.assertion == assertion assert evidence.eco == eco assert evidence.comment == comment # Check id is set assert type(evidence.internal_id) is str assert evidence.internal_id != "" # Check the references assert reference in evidence.references assert evidence in reference.linked_items
def setup_items(self): self.model = Model() self.testcase = ModelTest(description="test_description") self.reaction1 = Reaction(id="r1") self.testsetting1 = ReactionSetting(self.reaction1, upper_bound=1000., lower_bound=0., objective_coefficient=0.) self.testcase.add_setting(self.testsetting1) self.reaction3 = Reaction(id="r3") self.outcome = Outcome(self.reaction3, value=100., operator="greater") self.testcase.add_outcome(self.outcome) self.reference = Reference(id="test_refid") self.testcase.add_reference(self.reference) self.model.add_reactions([self.reaction1, self.reaction3]) self.model.references[self.reference.id] = self.reference self.model.tests.append(self.testcase) self.model.setup_tests_table() self.root = Element("root", nsmap={None: ge_ns}) add_tests_to_xml(self.root, self.model)
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 setup_empty_dialog(self): self.model = Model() self.evidence = Evidence() self.entity = Gene("g1") self.assertion = "Catalyzing reaction" self.target = Reaction("r1") self.eco = "ECO:0000250" self.comment = "Similarity to XY" self.reference = Reference() self.dialog = EditEvidenceDialog()
def parse_references(model_node, model=None, progress=None): reference_list_node = model_node.find(ge_listOfReferences) if reference_list_node is None: return elif progress is None: pass elif not progress.wasCanceled(): progress.setLabelText("Reading references...") progress.setRange(0, len(reference_list_node)) elif progress.wasCanceled(): return references = [] for i, reference_node in enumerate( reference_list_node.iterfind(ge_reference)): if progress is None: pass elif not progress.wasCanceled(): progress.setValue(i) QApplication.processEvents() else: return new_reference = Reference(id=reference_node.get("id"), year=reference_node.get("year"), title=reference_node.get("title"), journal=reference_node.get("journal"), url=reference_node.get("url")) author_list_node = reference_node.find(ge_listOfAuthors) if author_list_node is not None: authors = [] for child in author_list_node.iterfind(ge_author): authors.append( Author(firstname=child.get("firstname"), lastname=child.get("lastname"), initials=child.get("initials"))) new_reference.authors = authors annotation = annotate_element_from_xml(reference_node) if annotation: for x in annotation: if x.collection == "pubmed": new_reference.pmid = x.identifier elif x.collection == "pmc": new_reference.pmc = x.identifier elif x.collection == "doi": new_reference.doi = x.identifier if model is None: references.append(new_reference) else: model.add_reference(new_reference) return references
def test_equality(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) assert evidence.copy() == evidence
def test_addition_of_optional_attributes_only_when_set(self): root = Element("root") reference = Reference() model = Model("Testmodel") model.references[reference.id] = reference add_references(root, model) reference_node = root.find("/".join([ge_listOfReferences, ge_reference])) assert reference_node is not None assert reference_node.get("url") is None assert reference_node.find(ge_listOfAuthors) is None assert reference_node.get("year") is None assert reference_node.get("title") is None assert reference_node.get("journal") is None assert reference_node.get("id") == reference.id assert reference_node.find(sbml3_annotation) is None
def test_override_entity(self): entity = Reaction() eco = "ECO:000000" assertion = "Presence" comment = "test comment" reference = Reference() evidence = Evidence(entity=entity, eco=eco, assertion=assertion, comment=comment) evidence.add_reference(reference) new_reaction = Reaction() evidence.set_entity(new_reaction) # Check disconnection of old reaction assert evidence.entity is new_reaction assert evidence not in entity.evidences
def test_inequality(self, attribute, new_value): 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_copy = evidence.copy() setattr(new_copy, attribute, new_value) assert new_copy != evidence assert not new_copy == evidence
def test_inequality_reference(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_copy = evidence.copy() new_copy.remove_all_references() assert new_copy != evidence assert not new_copy == evidence
def test_delete_links(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) evidence.delete_links() assert evidence.entity is None assert len(evidence.references) == 0 assert evidence not in entity.evidences assert evidence not in target.evidences
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
def setup_evidence(self): self.reaction = Reaction("r_id") self.gene = Gene("g_id") self.target = Gene("g_id2") self.model = Model("test id") self.reference = Reference() self.model.add_gene(self.gene) self.model.add_gene(self.target) self.model.add_reactions([self.reaction]) self.model.add_reference(self.reference) # Set type self.assertion = "Catalyzed by" self.eco = "ECO:0000000" self.comment = "test" self.evidence = Evidence(entity=self.reaction, eco=self.eco, assertion=self.assertion, comment=self.comment, target=self.target) self.evidence.add_reference(self.reference) self.model.all_evidences[self.evidence.internal_id] = self.evidence self.root = Element("root", nsmap={None: ge_ns})
def test_setup_links(self): entity = Reaction() target = Gene() eco = "ECO:000000" assertion = "Presence" comment = "test comment" reference = Reference() evidence = Evidence() evidence.entity = entity evidence.target = target evidence.eco = eco evidence.assertion = assertion evidence.comment = comment evidence.add_reference(reference, reciprocal=False) assert evidence not in entity.evidences assert evidence not in reference.linked_items assert evidence not in target.evidences evidence.setup_links() assert evidence in entity.evidences assert evidence in reference.linked_items assert evidence in target.evidences
class TestReferenceTable: @pytest.fixture(autouse=True) def setup_items(self): self.table = ReferenceTable() self.author1 = Author(lastname="FirstLast", firstname="FirstFirst", initials="FirstInitials") self.author2 = Author(lastname="SecondLast", firstname="SecondFirst", initials="SecondInitials") self.pmid = "123456" self.pmc = "PMC12345" self.url = "http://www.google.com" self.journal = "Test journal" self.year = "1987" self.title = "Test title" self.doi = "Test doi" self.reference = Reference(pmid=self.pmid, pmc=self.pmc, doi=self.doi, url=self.url, year=self.year, title=self.title, journal=self.journal, authors=[self.author1, self.author2]) def test_setup(self): assert issubclass(ReferenceTable, ElementTable) assert self.table.rowCount() == 0 assert self.reference.pmid == self.pmid assert self.reference.pmc == self.pmc assert self.reference.doi == self.doi assert self.reference.url == self.url assert self.reference.year == self.year assert self.reference.title == self.title assert self.reference.journal == self.journal assert self.reference.authors[0] is self.author1 assert self.reference.authors[1] is self.author2 def test_row_from_item(self): return_value = self.table.row_from_item(self.reference) assert len(return_value) == len(self.table.header) for x in return_value: assert isinstance(x, LinkedItem) assert x.link is self.reference assert return_value[0].text() == self.reference.reference_string() assert return_value[1].text() == self.title assert return_value[2].text() == self.journal assert return_value[3].text() == self.year assert return_value[4].text() == self.pmid assert return_value[5].text() == self.pmc assert return_value[6].text() == self.doi assert return_value[7].text() == self.url def test_update_row_from_item(self): assert self.table.rowCount() == 0 self.table.update_row_from_item(self.reference) assert self.table.rowCount() == 1 assert self.table.item(0, 0).text() == self.reference.reference_string() assert self.table.item(0, 1).text() == self.title assert self.table.item(0, 2).text() == self.journal assert self.table.item(0, 3).text() == self.year assert self.table.item(0, 4).text() == self.pmid assert self.table.item(0, 5).text() == self.pmc assert self.table.item(0, 6).text() == self.doi assert self.table.item(0, 7).text() == self.url def test_get_item_from_row(self): self.table.update_row_from_item(self.reference) assert self.table.item_from_row(0) is self.reference def test_get_items(self): self.table.update_row_from_item(self.reference) assert self.table.get_items() == [self.reference]
def setup_items(self): self.test = ModelTest() self.outcome1 = Outcome() self.reaction_setting = ReactionSetting() self.gene_setting = GeneSetting() self.reference1 = Reference()
def init_objects(self): self.reference1 = Reference("test_abbrev", "name") self.reference2 = Reference("test_abbrev", "name") self.empty_reference = Reference()
class TestReference: @pytest.fixture(autouse=True) def init_objects(self): self.reference1 = Reference("test_abbrev", "name") self.reference2 = Reference("test_abbrev", "name") self.empty_reference = Reference() def test___init__(self): """ Test the default values of empty reference """ assert self.empty_reference.authors == [] assert self.empty_reference.pmid == "" assert self.empty_reference.pmc == "" assert self.empty_reference.abstract == "" assert self.empty_reference.doi == "" assert self.empty_reference.title == "" assert self.empty_reference.year == "" assert self.empty_reference.url == "" assert self.empty_reference.journal == "" def test_author_string1(self): """ Check that empty string is returned if no author is set """ assert self.empty_reference.reference_string() == "" def test_author_string2(self): """ Test correct string for single author """ self.empty_reference.authors = [Author("Family", "First", "Initials")] self.empty_reference.year = "2015" assert self.empty_reference.reference_string( ) == "Family Initials, 2015" def test_author_string3(self): """ Test correct string for two authors """ self.empty_reference.authors = [ Author("FamilyFirst", "", "InitialsFirst"), Author("FamilySecond", "", "InitialsSecond") ] self.empty_reference.year = "2015" expected = "FamilyFirst InitialsFirst and FamilySecond InitialsSecond, 2015" assert self.empty_reference.reference_string() == expected def test_author_string4(self): """ Test correct string for 3 authors """ self.empty_reference.authors = [ Author("Family1", "", "Initials1"), Author("Family2", "", "Initials2"), Author("Family3", "", "Initials3") ] self.empty_reference.year = "2015" expected = "Family1 Initials1 et al., 2015" assert self.empty_reference.reference_string() == expected def test_annotation_property(self): reference = Reference() reference.pmc = "1234" reference.pmid = "54321" reference.doi = "5555" assert Annotation("pubmed", reference.pmid) in reference.annotation assert Annotation("pmc", reference.pmc) in reference.annotation assert Annotation("doi", reference.doi) in reference.annotation