def export_alleles(): msgBox = QMessageBox(QApplication.activeWindow()) msgBox.setText("Data export") msgBox.setInformativeText("What would you like to export?") exp_orig = msgBox.addButton("Original Data", QMessageBox.ActionRole) exp_renamed = msgBox.addButton("Renamed Alleles Data", QMessageBox.ActionRole) if len(Data.mod_alleles_dict) == 0: msgBox.removeButton(msgBox.buttons()[1]) msgBox.addButton(QMessageBox.Cancel) export = True msgBox.exec_() if msgBox.clickedButton() == exp_orig: data = Data.orig_alleles_dict print("Exporting renames alleles data...") elif msgBox.clickedButton() == exp_renamed: data = Data.mod_alleles_dict print("Exporting renamed alleles data...") else: export = False print("Cancel") if export: try: path, _ = QFileDialog().getSaveFileName( QApplication.activeWindow(), filter='*.csv') df = DataFrame.from_dict( data, orient='index', columns=['marker_id', 'allele', 'marker_name']) df = df.drop(labels="marker_id", axis=1) df = df.reindex(columns=["marker_name", "allele"]) df.to_csv(path_or_buf=path, sep="\t", header=False, index=False) #with ExcelWriter(path) as writer: # df.to_excel(writer) QMessageBox.information( GraphicalGenotypeController.ui, "Info", "Export Success\nAlleles data was " "exported successfully to path") except (): QMessageBox.information( GraphicalGenotypeController.ui, "Warning", "Export Failed\nAn error has occurred!")
def draw_pajek(): msgBox = QMessageBox(QApplication.activeWindow()) msgBox.setText("Plot network with Pajek") msgBox.setInformativeText("Which network would you like to plot?") net_plot = msgBox.addButton("Network", QMessageBox.ActionRole) mst_plot = msgBox.addButton("MST of Network", QMessageBox.ActionRole) plot = True if Data.network.mst == None: msgBox.removeButton(msgBox.buttons()[1]) msgBox.addButton(QMessageBox.Cancel) msgBox.exec_() if msgBox.clickedButton() == net_plot: to_plot = Data.network print("Plotting network with Pajek...") elif msgBox.clickedButton() == mst_plot: to_plot = Data.network.mst print("Plotting MST with Pajek...") else: plot = False print("Cancel") if plot: pajek_path = os.getcwd() + '\Pajek64\Pajek.exe' try: path, _ = QFileDialog().getSaveFileName( QApplication.activeWindow(), filter='*.net') Network.print_pajek_network(plot_net=to_plot, sFileName=path) QMessageBox.information( NetworkTabController.ui, "Info", "Save Success\nMap " "was successfully saved to path") except (): QMessageBox.information(NetworkTabController.ui, "Warning", "Save Failed\nAn error has occurred!") NetworkTabController.ui.log_plainTextEdit.appendPlainText( f"Network was exported to Pajek format successfully" f"\n\t#Nodes: {len(to_plot.nodes)}" f"\n\t#Edges: {len(to_plot.edges)}" f"\n\tNetwork save path: {path}\n") subprocess.Popen([pajek_path, path])