def add_button_clicked(self): reaction_name = self.transcription_reactions_combo.currentText() regulators = [] for i in range(0, self.regulators_list.count()): item = self.regulators_list.item(i) if item.checkState() == Qt.Checked: regulators.append(item.text()) reg_types = [] if self.activation_check.isChecked(): reg_types.append(RegType.ACTIVATION) if self.repression_check.isChecked(): reg_types.append(RegType.REPRESSION) k_lb = float(self.lb_edit.text()) k_ub = float(self.ub_edit.text()) k_step = float(self.step_edit.text()) hill_coeff = float(self.hill_edit.text()) reg_mut = RegulationMutable(reaction_name, regulators, VariableMutable("k", k_lb, k_ub, k_step), reg_types, False, hill_coeff) GenePresenter.get_instance().mutables.append(reg_mut) # Climb up the hierarchy to find the window and close that. self.parent().parent().parent().close()
def _ok_button_clicked_handler(self): index = self.reaction_types_list.currentRow() if index == 0: # Transcription GenePresenter.get_instance().add_reaction(self.transcription_fields.get_transcription_reaction()) elif index == 1: # Translation name = str(self.reaction_name2.text()) rate = float(self.translation_rate.text()) translated_mrna = str(self.translated_mrna.currentText()) produced_protein = str(self.produced_protein.currentText()) formula = TranslationFormula(rate, translated_mrna) GenePresenter.get_instance().add_reaction(Reaction(name, [translated_mrna], [produced_protein], formula)) elif index == 2: # Degradation name = str(self.reaction_name3.text()) rate = float(self.decay_rate.text()) decaying_species = str(self.decaying_species.currentText()) formula = DegradationFormula(rate, decaying_species) GenePresenter.get_instance().add_reaction(Reaction(name, [decaying_species], [], formula)) else: # Custom name = str(self.reaction_name4.text()) reactant = str(self.reactant.currentText()) product = str(self.product.currentText()) equation = str(self.equation.text()) formula = CustomFormula(equation, {}, {}) GenePresenter.get_instance().add_reaction(Reaction(name, [reactant], [product], formula)) self.close()
def _add_species_click_handler(self): (text, ok) = QInputDialog.getText( self, "Add Species", "Write species and initial " "concentration in this format: \n" "species1: 20.0, species2: 30.0") if ok: for pair in text.split(','): split = pair.strip().split(':') species_name = split[0].strip() species_concent = float(split[1].strip()) GenePresenter.get_instance().add_species( species_name, species_concent) self.update_ui() self.parent.reactions_tab.update_ui()
def _save_file_as_sbml_clicked(self): net = GenePresenter.get_instance().network d = QFileDialog() filename = d.getSaveFileName(self, "Save file", ".", "XML Files (*.xml)") if filename: SbmlSaver.save_network_to_file(net, filename[0] + ".xml")
def _make_transcription_reactions_combo(): c = QComboBox() for r in GenePresenter.get_instance().network.reactions: if isinstance(r.rate_function, TranscriptionFormula): c.addItem(r.name) return c
def _constraint_satisfaction_handler(self, s): g = GenePresenter.get_instance() if self.method_combo.currentIndex() == 0: give_up_time = int(self.give_up_edit.text()) t = ConstraintSatisfaction.find_network(g.network, s, g.get_mutables(), g.get_constraints(), give_up_time) else: temperature = int(self.temperature_edit.text()) schedule = ConstraintSatisfaction.generate_schedule(temperature) t = ConstraintSatisfaction.find_closest_network( g.network, s, g.get_mutables(), g.get_constraints(), schedule) if t: variables_dialog = QDialog() scroll = QScrollArea() scroll.setWidget(QLabel(t.str_variables())) layout = QVBoxLayout() layout.addWidget(scroll) ok_button = QPushButton("OK") ok_button.clicked.connect(lambda _: variables_dialog.close()) layout.addWidget(ok_button) variables_dialog.setLayout(layout) variables_dialog.setMinimumWidth(300) variables_dialog.exec_() def draw_simulation(): results = OdeSimulator.simulate(t, s) values = StructuredResults.label_results(results, t.species) for species in s.plotted_species: plt.plot(s.generate_time_space(), values[species], label=species) plt.xlabel("Time (s)") plt.ylabel("Concentration") plt.legend(loc=0) plt.title("Results") plt.draw() plt.figure() plt.subplot(2, 1, 1) draw_simulation() plt.subplot(2, 1, 2) im = NetworkVisualiser.visualise_as_image(t, "gene") plt.imshow(im) plt.show() else: helper.show_error_message( "No matching network found within the given parameters.")
def _make_regulators_list(): t = QListWidget() for s in GenePresenter.get_instance().network.species: i = QListWidgetItem() i.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled) i.setCheckState(Qt.Unchecked) i.setText(s) t.addItem(i) return t
def _add_clicked_handler(self): combo_index = self.mutables_combo.currentIndex() mutable_title = self.mutable_combo_values[combo_index][0] mutable_reaction = self.mutable_combo_values[combo_index][1] is_custom = self.mutable_combo_values[combo_index][2] lo = self.lb.text().strip() lo = float(lo) if lo != "" else 0.0 u = self.ub.text().strip() u = float(u) if u != "" else 0.0 i = self.inc.text().strip() i = float(i) if i != "" else 0.0 if mutable_reaction == "": if is_custom: GenePresenter.get_instance().mutables.append( GlobalParameterMutable(mutable_title, lo, u, i)) else: GenePresenter.get_instance().mutables.append( VariableMutable(mutable_title, lo, u, i)) else: GenePresenter.get_instance().mutables.append( ReactionMutable(mutable_title, lo, u, i, mutable_reaction)) # Climb up the hierarchy to find the window and close that. self.parent().parent().parent().close()
def _make_mutables_combo(): combo_items = [] item_values = [] for s in GenePresenter.get_instance().get_species(): combo_items.append("Species ⟹ {}".format(s)) item_values.append((s, "", False)) for r in GenePresenter.get_instance().get_reactions(): for p in r.rate_function.get_params(): combo_items.append("{} ⟹ {}".format(r.name, p)) item_values.append((p, r.name, False)) net = GenePresenter.get_instance().network for symbol in net.symbols: combo_items.append("Global parameter ⟹ {}".format(symbol)) item_values.append((symbol, "", True)) combo = QComboBox() combo.addItems(combo_items) return combo, item_values
def _button_clicked(self): sign = self.sign_combo.currentText() species = self.lhs.currentText() value = float(self.rhs.text()) t0 = float(self.time_lb.text()) t1 = float(self.time_ub.text()) if sign == "<=": cons = lambda v: v - value elif sign == ">=": cons = lambda v: value - v else: helper.show_error_message( "Constraint syntax error: Unrecognised sign") self.close() return c = Constraint(species, cons, (t0, t1)) c.pretty_print = species + sign + str(value) + " for time: " + str( t0) + "s - " + str(t1) + "s" GenePresenter.get_instance().add_constraint(c) self.close()
def make_species_checkboxes_layout(): row = 0 # Row number to place the next species left = True # Indicates that the next species must be placed to the left g = QGridLayout() for x in GenePresenter.get_instance().get_species(): col = 1 if left else 2 # Column number depending on variable "left" g.addWidget(QCheckBox(x), row, col) # Switch to next row after adding species to right if not left: row += 1 # Switch sides each time left = not left return g
def __init__(self, parent): super().__init__() self.setFileMode(QFileDialog.AnyFile) filename = self.getOpenFileName(self, "Open file", ".", "XML Files (*.xml);; All Files (*.*)") if filename: net = SbmlParser.parse(filename[0]) if not net: helper.show_error_message( "An error occurred while opening the SBML file.") GenePresenter.get_instance().network = net message = QMessageBox() message.setText("SBML file has been opened") message.exec_() parent.species_tab.update_ui() parent.reactions_tab.update_ui()
def _ok_button_clicked(self): time_text = self.time_field.text().strip() end_time = int(time_text) if time_text else 1 species = list() for x in range(0, self.species_checkboxes.count()): checkbox = self.species_checkboxes.itemAt(x).widget() if checkbox.isChecked(): species.append(checkbox.text()) self.close() # Precision field does not apply to stochastic simulation! s = SimulationSettings(0, end_time, 0, [s.strip() for s in species]) sim_net = copy.deepcopy(GenePresenter.get_instance().network) def do_simulation(): GillespieSimulator.visualise( GillespieSimulator.simulate(sim_net, s), s) # t = threading.Thread(target=do_simulation) # t.start() do_simulation()
def handler(s): net = GenePresenter.get_instance().network OdeSimulator.visualise(net, s, OdeSimulator.simulate(net, s))
def make_species_combo(): combo = QComboBox() for x in GenePresenter.get_instance().get_species(): combo.addItem(x) return combo
def _remove_species_click_handler(self): text = self.species_list.item(self.species_list.currentRow()).text() species = text.split(':')[0] GenePresenter.get_instance().remove_species(species) self.update_ui() self.parent.reactions_tab.update_ui()
def update_ui(self): self.species_list.clear() for s in GenePresenter.get_instance().get_species(): self.species_list.addItem( s + ": " + str(GenePresenter.get_instance().get_species()[s]))
def _remove_constraint_clicked(self): i = self.constraints_list.currentRow() GenePresenter.get_instance().remove_constraint(i) self._update_constraints_list()
def _update_constraints_list(self): self.constraints_list.clear() for c in GenePresenter.get_instance().get_constraints(): self.constraints_list.addItem(str(c))
def _remove_mutable_clicked(self): i = self.mutables_list.currentRow() GenePresenter.get_instance().remove_mutable(i) self._update_mutables_list()
def _update_mutables_list(self): self.mutables_list.clear() for m in GenePresenter.get_instance().get_mutables(): self.mutables_list.addItem(str(m))