class TestCompartment: @pytest.fixture(autouse=True) def init_objects(self): self.compartment1 = Compartment("test_abbrev", "name") self.compartment2 = Compartment("test_abbrev", "name") self.empty_compartment = Compartment() def test__init_(self): """ Test that compartment is initialized to None """ assert self.empty_compartment.id is None assert self.empty_compartment.name is None assert self.compartment1.id == "test_abbrev" assert self.compartment1.name == "name" def test_get_values(self): """ Test that get values returns a tuple (abbreviation, name) """ assert self.empty_compartment.get_values() == (None, None) assert self.compartment1.get_values() == ("test_abbrev", "name") def test__eq__(self): """ Test equality function """ assert self.compartment1 == self.compartment2 assert self.compartment1 != self.empty_compartment assert self.compartment1 is not self.compartment2 assert ("test_abbrev", "name") == self.compartment1
def setup_items(self): self.model = Model("Test") self.c1 = Compartment(id="c", name="Cytoplasm") self.c2 = Compartment(id="e", name="Extracellular") self.model.gem_compartments[self.c1.id] = self.c1 self.compartment_table = CompartmentTable() self.compartment_table.populate_table(self.model.gem_compartments.values()) self.wrong_format_abbreviation = "ca"
def test_parse_compartments(): parent_node = ET.fromstring(valid_compartment_list) model = Model() parse_compartments(parent_node, model) assert model.gem_compartments["p"] == Compartment("p", "Periplasm") assert model.gem_compartments["c"] == Compartment("c", "Cytoplasm") assert model.gem_compartments["e"] == Compartment("e", "Extracellular")
def setup_items(self): self.test_id = "Test_id" self.test_name = "Test_name" self.model = Model(self.test_id, self.test_name) self.parent = QWidget() self.comp1_name = "Cytoplasm" self.comp1_id = "c" self.new_comp_id = "n" self.new_comp_name = "Nucleus" self.new_comp = Compartment(self.new_comp_id, self.new_comp_name) self.comp1 = Compartment(self.comp1_id, self.comp1_name) self.model.gem_compartments[self.comp1_id] = self.comp1 self.metabolite = Metabolite("test", compartment=self.comp1_id) self.model.add_metabolites([self.metabolite]) self.model.setup_tables() self.dialog = EditModelDialog(model=self.model)
def test_consistency_write_read(): model1 = Model() model1.gem_compartments["c"] = Compartment("c", "Cytoplasm") root = Element("Root") add_compartments(root, model1) model2 = Model() parse_compartments(root, model2) assert model2.gem_compartments == model1.gem_compartments
def test_change_in_name_enables_button(self): model = Model() model.gem_compartments["c"] = Compartment("c", "Cytoplasm") dialog = EditModelDialog(model=model) save_button = dialog.buttonBox.button(QDialogButtonBox.Save) # Change id assert save_button.isEnabled() is False QtTest.QTest.keyClicks(dialog.input_name, "M") assert save_button.isEnabled() is True # Undo change QtTest.QTest.keyClick(dialog.input_name, QtCore.Qt.Key_Backspace) assert save_button.isEnabled() is False
def test_add_compartments(): model = Model() model.gem_compartments["c"] = Compartment("c", "Cytoplasm") root = Element("Root") add_compartments(root, model) compartment_list = root.find(sbml3_listOfCompartments) assert compartment_list is not None compartment = compartment_list.find(sbml3_compartment) assert compartment is not None assert compartment.get("id") == "c" assert compartment.get("name") == "Cytoplasm"
def read_sbml3_model(path, progress): """ Read SBML model Parameters ---------- path: str Path to model file progress: QProgressDialog Progress dialog """ # Read file with open(path, "r", encoding="UTF-8") as open_file: tree = ET.parse(open_file) # Get SBML node sbml_node = tree.getroot() if sbml_node.tag is None or sbml_node.tag != sbml3_sbml: raise IOError("The file does not contain a sbml3 model") returned_values = parse_sbml3_model(sbml_node) if returned_values is None: raise IOError("No model node found!") model_node, model = returned_values # Parse GEM Editor related stuff parsing_functions = [ parse_references, parse_compartments, parse_metabolites, parse_genes, parse_reaction, parse_test_from_xml, parse_evidences_from_xml ] for parse_function in parsing_functions: if progress is None: parse_function(model_node, model) elif not progress.wasCanceled(): parse_function(model_node, model, progress) else: return # Add compartments from metabolites if not saved for x in model.metabolites: if x.compartment not in model.gem_compartments: model.gem_compartments[x.compartment] = Compartment( x.compartment, None) model.setup_tables() return model
def setup_items(self): self.gene = Gene("g1") self.compartment = Compartment("c") self.metabolite1 = Metabolite("m1") self.metabolite2 = Metabolite("m2") self.reaction = Reaction("r1") self.reaction.add_metabolites({ self.metabolite1: -1, self.metabolite2: 1 }) self.reaction.add_child(self.gene) self.evidence = Evidence(entity=self.gene, assertion="Localization", target=self.compartment)
def parse_compartments(model_node, model=None, progress=None): """ Parse the compartment list if found and add all compartments to the model.gem_compartments dictionary """ compartment_list_node = model_node.find(sbml3_listOfCompartments) compartments = {} if compartment_list_node is not None: for compartment_node in compartment_list_node.iterfind( sbml3_compartment): compartment = Compartment(id=compartment_node.get("id"), name=compartment_node.get("name")) if model is not None: model.gem_compartments[compartment.id] = compartment else: compartments[compartment.id] = compartment return compartments
def setup_items(self): self.parent = QWidget() self.widget = ModelDisplayWidget(self.parent) self.test_id = "Test_model" self.test_name = "Test name" self.model = Model(self.test_id, name=self.test_name) self.comp1_abbrev = "c" self.comp1_name = "Cytoplasm" self.comp1 = Compartment(self.comp1_abbrev, self.comp1_name) self.model.gem_compartments[self.comp1_abbrev] = self.comp1 self.gene = Gene(id="test_id", name="test_name") self.metabolite = Metabolite(id="test_id", compartment="c") self.reaction = Reaction(id="test_id") self.model.add_metabolites([self.metabolite]) self.model.add_reactions([self.reaction]) self.model.genes.append(self.gene)
def test_item_from_row(self): self.table.appendRow( self.table.row_from_item(Compartment("c", "cytoplasm"))) assert self.table.rowCount() == 1 assert self.table.item_from_row(0) == Compartment("c", "cytoplasm") assert self.table.get_items() == [Compartment("c", "cytoplasm")]
def test_row_from_item(self): return_value = self.table.row_from_item(Compartment("c", "cytoplasm")) assert return_value[0].text() == "c" assert return_value[1].text() == "cytoplasm"
def test_getting_compartment(self): dialog = AddCompartmentDialog(self.compartment_table) QtTest.QTest.keyClicks(dialog.input_id, self.c2.id) QtTest.QTest.keyClicks(dialog.input_name, self.c2.name) assert dialog.get_compartment == Compartment(self.c2.id, self.c2.name)
def init_objects(self): self.compartment1 = Compartment("test_abbrev", "name") self.compartment2 = Compartment("test_abbrev", "name") self.empty_compartment = Compartment()
def get_compartment(self): return Compartment(id=self.input_id.text(), name=self.input_name.text())