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!")
Example #2
0
    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])
Example #3
0
 def toggleFullscreen(cls, widget: QtWidgets.QWidget):
     if not hasattr(cls, "__fullscreen"):
         setattr(cls, "__fullscreen", dict())
     jd = getattr(cls, "__fullscreen")
     if not widget.isFullScreen():
         parent = widget.parentWidget()
         window = QApplication.activeWindow()
         assert isinstance(parent, QtWidgets.QSplitter)
         jd[id(widget)] = [
             parent,
             parent.indexOf(widget),
             parent.sizes(),
             QApplication.activeWindow()
         ]
         widget.setParent(gg(None))
         widget.showFullScreen()
         window.hide()
     else:
         parent, index, sizes, window = jd[id(widget)]
         assert isinstance(parent, QtWidgets.QSplitter)
         window.show()
         parent.insertWidget(index, widget)
         parent.setSizes(sizes)
         del jd[id(widget)]
Example #4
0
def getMousePos():
    # When the main window doesn' t have focus getting the activeWindow throws
    # and error that we use in our advantage.

    try:
        qNuke = QApplication.activeWindow()
        #qNuke.setWindowTitle('NUKE 7 | QT Window')
        tlw = qNuke.topLevelWidget()

        mouse_cursor = tlw.cursor()
        mouse_pos = [mouse_cursor.pos().x(), mouse_cursor.pos().y()]
        return mouse_pos

    except:
        return None
Example #5
0
 def import_file(self):
     path, _ = QFileDialog().getOpenFileName(QApplication.activeWindow(), "Select a file to open", filter="Map data (*.txt *.csv)")
     if path is not None:
         FileBrowserController.load_file(path)
     else:
         QMessageBox().warning(self.ui, "Warning", "No File Has Been Chosen!")
Example #6
0
 def import_map2(self):
     path, _ = QFileDialog().getOpenFileName(QApplication.activeWindow(), "Select a file to open", filter="Map data (*.txt *.csv)")
     MapComparisonController.compare_maps(path) if path else print("a")
Example #7
0
    def subdivide_network():
        val, ok = QInputDialog.getDouble(
            QApplication.activeWindow(),
            "Parallel cutoff",
            "Input cutoff value for unproven parallel linkages",
            0.25,
            0.0,
            1.0,
            decimals=3,
            step=0.01)
        if ok:
            NetworkTabController.ui.log_plainTextEdit.appendPlainText(
                f"Testing network for linear structure...")

            linear_net, excluded = Data.network.makeLinearContigClusters(
                bExcludeNodesCausingNonLinearClusters=True,
                cutoff=float(
                    NetworkTabController.ui.cutoff_textfield.toPlainText()),
                cutoffParallel=float(val))

            if len(excluded) != 0:
                NetworkTabController.ui.log_plainTextEdit.appendPlainText(
                    f"{len(Data.network.nodes) - len(linear_net.nodes)} nodes were removed:"
                )

                excluded = [
                    str(str(id) + "\t" + Data.network.nodes[id].caption)
                    for id in excluded
                ]
                for ex in excluded:
                    NetworkTabController.ui.log_plainTextEdit.appendPlainText(
                        ex)

                pajek_path = os.getcwd() + '\Pajek64\Pajek.exe'
                try:
                    path, _ = QFileDialog().getSaveFileName(
                        QApplication.activeWindow(), filter='*.net')
                    Network.print_pajek_network(plot_net=linear_net,
                                                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"Linear structure network was built successfully!"
                    f"\n\t#Nodes: {len(linear_net.nodes)}"
                    f"\n\t#Edges: {len(linear_net.edges)}\n")

                QMessageBox.information(
                    NetworkTabController.ui, "Notice",
                    "Network was subdivided into linear components successfully!"
                )
                subprocess.Popen([pajek_path, path])
            else:
                QMessageBox.information(
                    NetworkTabController.ui, "Notice",
                    "Network is already linearly structured!")
                NetworkTabController.ui.log_plainTextEdit.appendPlainText(
                    "\tNetwork is already linearly structured!\n")