def btnConvert_click(self):

        msgBox = QMessageBox()

        InFFile = ui.txtInFFile.text()
        if not len(InFFile):
            msgBox.setText("Please select the first input file!")
            msgBox.setIcon(QMessageBox.Critical)
            msgBox.setStandardButtons(QMessageBox.Ok)
            msgBox.exec_()
            return False
        elif not os.path.isfile(InFFile):
            msgBox.setText("The first input file not found!")
            msgBox.setIcon(QMessageBox.Critical)
            msgBox.setStandardButtons(QMessageBox.Ok)
            msgBox.exec_()
            return False

        InSFile = ui.txtInSFile.text()
        if not len(InSFile):
            msgBox.setText("Please select the second input file!")
            msgBox.setIcon(QMessageBox.Critical)
            msgBox.setStandardButtons(QMessageBox.Ok)
            msgBox.exec_()
            return False
        elif not os.path.isfile(InSFile):
            msgBox.setText("The second input file not found!")
            msgBox.setIcon(QMessageBox.Critical)
            msgBox.setStandardButtons(QMessageBox.Ok)
            msgBox.exec_()
            return False

        OutFile = ui.txtOutFile.text()
        if not len(OutFile):
            msgBox.setText("Please select the output file!")
            msgBox.setIcon(QMessageBox.Critical)
            msgBox.setStandardButtons(QMessageBox.Ok)
            msgBox.exec_()
            return False

        if not ui.cbCondUnion.isChecked():
            if not len(ui.txtFCondPre.text()):
                msgBox.setText("Please enter the condition prefix!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False
            # if not len(ui.txtSCondPre.text()):
            #     msgBox.setText("Please enter the condition prefix!")
            #     msgBox.setIcon(QMessageBox.Critical)
            #     msgBox.setStandardButtons(QMessageBox.Ok)
            #     msgBox.exec_()
            #     return False
            # if not len(ui.txtOCondPre.text()):
            #     msgBox.setText("Please enter the condition prefix!")
            #     msgBox.setIcon(QMessageBox.Critical)
            #     msgBox.setStandardButtons(QMessageBox.Ok)
            #     msgBox.exec_()
            #     return False

        InFData = io.loadmat(InFFile)
        InSData = io.loadmat(InSFile)
        OutData = dict()

        # Data
        if not len(ui.txtFData.currentText()):
            msgBox.setText("Please enter First Data variable name!")
            msgBox.setIcon(QMessageBox.Critical)
            msgBox.setStandardButtons(QMessageBox.Ok)
            msgBox.exec_()
            return False
        if not len(ui.txtSData.currentText()):
            msgBox.setText("Please enter Second Data variable name!")
            msgBox.setIcon(QMessageBox.Critical)
            msgBox.setStandardButtons(QMessageBox.Ok)
            msgBox.exec_()
            return False
        if not len(ui.txtOData.text()):
            msgBox.setText("Please enter Out Data variable name!")
            msgBox.setIcon(QMessageBox.Critical)
            msgBox.setStandardButtons(QMessageBox.Ok)
            msgBox.exec_()
            return False
        try:
            InFX = InFData[ui.txtFData.currentText()]
        except:
            print("Cannot load data from the first file!")
            return

        try:
            InSX = InSData[ui.txtSData.currentText()]
        except:
            print("Cannot load data from the second file!")
            return

        if np.shape(InFX)[1] != np.shape(InSX)[1]:
            print("Both data files must have the same size!")
            return

        # fMRI Size
        InterfMRISize = InFData["imgShape"][0] - InSData["imgShape"][0]
        if (np.max(InterfMRISize) != 0) or (np.min(InterfMRISize) != 0):
            print(
                "Both data files must extract from the same size fMRI images!")
            return

        OutData["imgShape"] = InFData["imgShape"]

        # Coordinate
        if ui.cbCol.isChecked():
            if not len(ui.txtFCol.currentText()):
                msgBox.setText("Please enter First Coordinator variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False
            if not len(ui.txtSCol.currentText()):
                msgBox.setText(
                    "Please enter Second Coordinator variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False
            if not len(ui.txtOCoI.text()):
                msgBox.setText("Please enter Out Coordinator variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False
            try:
                InFCol = np.array(InFData[ui.txtFCol.currentText()])
            except:
                print("Cannot load coordinate in the first file!")
                return
            try:
                InSCol = np.array(InSData[ui.txtSCol.currentText()])
            except:
                print("Cannot load coordinate in the second file!")
                return

            SubCol = InFCol - InSCol
            if (np.max(SubCol) != 0) or (np.min(SubCol) != 0):
                msgBox.setText("Coordinates are not matched!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False

            OutData[ui.txtOCoI.text()] = InFData[ui.txtFCol.currentText()]

        OutData[ui.txtOData.text()] = np.concatenate((InFX, InSX))

        # Label
        if not len(ui.txtFLabel.currentText()):
            msgBox.setText("Please enter First Label variable name!")
            msgBox.setIcon(QMessageBox.Critical)
            msgBox.setStandardButtons(QMessageBox.Ok)
            msgBox.exec_()
            return False
        if not len(ui.txtSLabel.currentText()):
            msgBox.setText("Please enter Second Label variable name!")
            msgBox.setIcon(QMessageBox.Critical)
            msgBox.setStandardButtons(QMessageBox.Ok)
            msgBox.exec_()
            return False
        if not len(ui.txtOLabel.text()):
            msgBox.setText("Please enter Out Label variable name!")
            msgBox.setIcon(QMessageBox.Critical)
            msgBox.setStandardButtons(QMessageBox.Ok)
            msgBox.exec_()
            return False
        try:
            InFL = InFData[ui.txtFLabel.currentText()]
            InSL = InSData[ui.txtSLabel.currentText()]

            InFLUniq = np.unique(InFL)
            InSLUniq = np.unique(InSL)
            if not ui.cbRelabeling.isChecked():
                OutData[ui.txtOLabel.text()] = np.concatenate((InFL, InSL),
                                                              1)[0]
                InSLUniqNew = InSLUniq.copy()
            else:

                InSLUniqNew = InSLUniq + np.max(InFLUniq) + 1

                InSLNew = InSL.copy()
                for lblinx, lbl in enumerate(InSLUniq):
                    InSLNew[np.where(InSL == lbl)] = InSLUniqNew[lblinx]

                OutData[ui.txtOLabel.text()] = np.concatenate((InFL, InSLNew),
                                                              1)[0]

        except:
            print("Cannot combine Labels!")
            return

        # Matrix Label
        if ui.cbmLabel.isChecked():
            if not len(ui.txtOmLabel.text()):
                msgBox.setText("Please enter Out Matrix Label variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False
            OutData[ui.txtOmLabel.text()] = label_binarize(
                OutData[ui.txtOLabel.text()],
                np.unique(OutData[ui.txtOLabel.text()]))

        # Condition
        if ui.cbCond.isChecked():
            if not len(ui.txtFCond.currentText()):
                msgBox.setText("Please enter First Condition variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False
            if not len(ui.txtSCond.currentText()):
                msgBox.setText("Please enter Second Condition variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False
            if not len(ui.txtOCond.text()):
                msgBox.setText("Please enter Out Condition variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False

            if ui.cbCondUnion.isChecked():
                OutData[ui.txtOCond.text()] = np.concatenate(
                    (InFData[ui.txtFCond.currentText()],
                     InSData[ui.txtSCond.currentText()]))
            else:
                NewCond = Conditions()
                InFCond = InFData[ui.txtFCond.currentText()]
                for cond in InFCond:
                    NewCond.add_cond(
                        str.replace(cond[0][0], ui.txtFCondPre.text(),
                                    ui.txtOCondPre.text()), cond[1][0])

                InSCond = InSData[ui.txtSCond.currentText()]
                for cond in InSCond:
                    condID = np.int32(
                        str.replace(cond[0][0],
                                    ui.txtSCondPre.text() + "_", ""))
                    condIDNew = InSLUniqNew[np.where(InSLUniq == condID)][0]
                    NewCond.add_cond(
                        ui.txtOCondPre.text() + "_" + str(condIDNew),
                        cond[1][0])

                OutData[ui.txtOCond.text()] = np.array(NewCond.get_cond(),
                                                       dtype=object)

        # Subject
        if ui.cbSubject.isChecked():
            if not len(ui.txtFSubject.currentText()):
                msgBox.setText("Please enter First Subject variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False
            if not len(ui.txtSSubject.currentText()):
                msgBox.setText("Please enter Second Subject variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False
            if not len(ui.txtOSubject.text()):
                msgBox.setText("Please enter Out Subject variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False
            try:
                OutData[ui.txtOSubject.text()] = np.concatenate(
                    (InFData[ui.txtFSubject.currentText()],
                     InSData[ui.txtSSubject.currentText()]), 1)[0]
            except:
                print("Cannot combine Subject IDs!")
                return

        # Task
        if ui.cbTask.isChecked():
            if not len(ui.txtFTask.currentText()):
                msgBox.setText("Please enter First Task variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False
            if not len(ui.txtSTask.currentText()):
                msgBox.setText("Please enter Second Task variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False
            if not len(ui.txtOTask.text()):
                msgBox.setText("Please enter Out Task variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False
            try:
                OutData[ui.txtOTask.text()] = np.concatenate(
                    (InFData[ui.txtFTask.currentText()],
                     InSData[ui.txtSTask.currentText()]), 1)[0]
            except:
                print("Cannot combine Task IDs!")
                return

        # Run
        if ui.cbRun.isChecked():
            if not len(ui.txtFRun.currentText()):
                msgBox.setText("Please enter First Run variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False
            if not len(ui.txtSRun.currentText()):
                msgBox.setText("Please enter Second Run variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False
            if not len(ui.txtORun.text()):
                msgBox.setText("Please enter Out Run variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False
            try:
                OutData[ui.txtORun.text()] = np.concatenate(
                    (InFData[ui.txtFRun.currentText()],
                     InSData[ui.txtSRun.currentText()]), 1)[0]
            except:
                print("Cannot combine Run IDs!")
                return

        # Counter
        if ui.cbCounter.isChecked():
            if not len(ui.txtFCounter.currentText()):
                msgBox.setText("Please enter First Counter variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False
            if not len(ui.txtSCounter.currentText()):
                msgBox.setText("Please enter Second Counter variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False
            if not len(ui.txtOCounter.text()):
                msgBox.setText("Please enter Out Counter variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False
            try:
                OutData[ui.txtOCounter.text()] = np.concatenate(
                    (InFData[ui.txtFCounter.currentText()],
                     InSData[ui.txtSCounter.currentText()]), 1)[0]
            except:
                print("Cannot combine Counter IDs!")
                return

        # Number of Scan
        if ui.cbNScan.isChecked():
            if not len(ui.txtFScan.currentText()):
                msgBox.setText("Please enter First NScan variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False
        if ui.cbNScan.isChecked():
            if not len(ui.txtSScan.currentText()):
                msgBox.setText("Please enter Second NScan variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False
        if ui.cbNScan.isChecked():
            if not len(ui.txtOScan.text()):
                msgBox.setText("Please enter Out NScan variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False
        try:
            OutData[ui.txtOScan.text()] = np.concatenate(
                (InFData[ui.txtFScan.currentText()],
                 InSData[ui.txtSScan.currentText()]), 1)[0]
        except:
            print("Cannot combine Counter IDs!")
            return

        # Design
        if ui.cbDM.isChecked():
            if not len(ui.txtFDM.currentText()):
                msgBox.setText(
                    "Please enter First Design Matrix variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False
            if not len(ui.txtSDM.currentText()):
                msgBox.setText(
                    "Please enter Second Design Matrix variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False
            if not len(ui.txtODM.text()):
                msgBox.setText("Please enter Out Design Matrix variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False
            try:
                OutData[ui.txtODM.text()] = np.concatenate(
                    (InFData[ui.txtFDM.currentText()],
                     InSData[ui.txtSDM.currentText()]))
            except:
                print("Cannot combine Design Matrices!")
                return

        print("Saving ...")
        io.savemat(ui.txtOutFile.text(), mdict=OutData)
        print("DONE.")
        msgBox.setText("Datasets are combined.")
        msgBox.setIcon(QMessageBox.Information)
        msgBox.setStandardButtons(QMessageBox.Ok)
        msgBox.exec_()
Exemple #2
0
    def btnConvert_click(self):

        msgBox = QMessageBox()

        # Subject
        if ui.cbSubject.isChecked():
            if not len(ui.txtSubject.currentText()):
                msgBox.setText("Please enter Train Subject variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False
            if not len(ui.txtTSubject.currentText()):
                msgBox.setText("Please enter Test Subject variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False

        # Task
        if ui.cbTask.isChecked():
            if not len(ui.txtTask.currentText()):
                msgBox.setText("Please enter Train Task variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False
            if not len(ui.txtTTask.currentText()):
                msgBox.setText("Please enter Test Task variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False

        # Run
        if ui.cbRun.isChecked():
            if not len(ui.txtRun.currentText()):
                msgBox.setText("Please enter Train Run variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False
            if not len(ui.txtTRun.currentText()):
                msgBox.setText("Please enter Test Run variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False

        # Counter
        if ui.cbCounter.isChecked():
            if not len(ui.txtCounter.currentText()):
                msgBox.setText("Please enter Train Counter variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False
            if not len(ui.txtTCounter.currentText()):
                msgBox.setText("Please enter Test Counter variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False

        # Label
        if not len(ui.txtLabel.currentText()):
            msgBox.setText("Please enter Train Label variable name!")
            msgBox.setIcon(QMessageBox.Critical)
            msgBox.setStandardButtons(QMessageBox.Ok)
            msgBox.exec_()
            return False
        if not len(ui.txtTLabel.currentText()):
            msgBox.setText("Please enter Test Label variable name!")
            msgBox.setIcon(QMessageBox.Critical)
            msgBox.setStandardButtons(QMessageBox.Ok)
            msgBox.exec_()
            return False

        # Matrix Label
        if ui.cbmLabel.isChecked():
            if not len(ui.txtmLabel.currentText()):
                msgBox.setText(
                    "Please enter Train Matrix Label variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False
            if not len(ui.txtTmLabel.currentText()):
                msgBox.setText("Please enter Test Matrix Label variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False

        # Data
        if not len(ui.txtData.currentText()):
            msgBox.setText("Please enter Train Data variable name!")
            msgBox.setIcon(QMessageBox.Critical)
            msgBox.setStandardButtons(QMessageBox.Ok)
            msgBox.exec_()
            return False
        if not len(ui.txtTData.currentText()):
            msgBox.setText("Please enter Test Data variable name!")
            msgBox.setIcon(QMessageBox.Critical)
            msgBox.setStandardButtons(QMessageBox.Ok)
            msgBox.exec_()
            return False

        # Design
        if ui.cbDM.isChecked():
            if not len(ui.txtDM.currentText()):
                msgBox.setText(
                    "Please enter Train Design Matrix variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False
            if not len(ui.txtTDM.currentText()):
                msgBox.setText(
                    "Please enter Test Design Matrix variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False

        # Coordinate
        if ui.cbCol.isChecked():
            if not len(ui.txtCol.currentText()):
                msgBox.setText("Please enter Coordinator variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False

        # Condition
        if ui.cbCond.isChecked():
            if not len(ui.txtCond.currentText()):
                msgBox.setText("Please enter Condition variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False

        # Number of Scan
        if ui.cbNScan.isChecked():
            if not len(ui.txtNScan.currentText()):
                msgBox.setText(
                    "Please enter Train Number of Scan variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False
            if not len(ui.txtTNScan.currentText()):
                msgBox.setText(
                    "Please enter Test Number of Scan variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False

        if ui.cbFoldID.isChecked():
            if not len(ui.txtFoldID.currentText()):
                msgBox.setText("Please enter Fold ID variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False

        if ui.cbFoldInfo.isChecked():
            if not len(ui.txtFoldInfo.currentText()):
                msgBox.setText("Please enter Fold Info variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False

        # OutFile
        OutFile = ui.txtOutFile.text()
        if not len(OutFile):
            msgBox.setText("Please enter out file!")
            msgBox.setIcon(QMessageBox.Critical)
            msgBox.setStandardButtons(QMessageBox.Ok)
            msgBox.exec_()
            return False

        try:
            ClassID = np.int32(ui.txtClassID.text())
        except:
            msgBox.setText("Class ID is wrong!")
            msgBox.setIcon(QMessageBox.Critical)
            msgBox.setStandardButtons(QMessageBox.Ok)
            msgBox.exec_()
            return False

        # InFile
        InFile = ui.txtInFile.text()
        if not len(InFile):
            msgBox.setText("Please enter input file!")
            msgBox.setIcon(QMessageBox.Critical)
            msgBox.setStandardButtons(QMessageBox.Ok)
            msgBox.exec_()
            return False

        if not os.path.isfile(InFile):
            msgBox.setText("Input file not found!")
            msgBox.setIcon(QMessageBox.Critical)
            msgBox.setStandardButtons(QMessageBox.Ok)
            msgBox.exec_()
            return False

        InData = io.loadmat(InFile)
        OutData = dict()
        OutData["imgShape"] = InData["imgShape"]

        if ui.cbFoldID.isChecked():
            OutData[ui.txtFoldID.currentText()] = InData[
                ui.txtFoldID.currentText()]

        if ui.cbFoldInfo.isChecked():
            OutData[ui.txtFoldInfo.currentText()] = InData[
                ui.txtFoldInfo.currentText()]

        # Condition
        if ui.cbCond.isChecked():
            try:
                Cond = InData[ui.txtCond.currentText()]
                New_Condition = Conditions()
                for condition in Cond:
                    if condition[0][0] != ui.txtClassName.currentText():
                        New_Condition.add_cond(condition[0][0],
                                               condition[1][0])

                OutData[ui.txtCond.currentText()] = np.array(
                    New_Condition.get_cond(), dtype=object)
            except Exception as e:
                print(e)
                print("Cannot load Condition ID!")
                return

        try:
            Y = InData[ui.txtLabel.currentText()]
            YT = InData[ui.txtTLabel.currentText()]
        except:
            print("Cannot load class labels!")
            return

        if not len(np.where(Y == ClassID)[0]):
            msgBox.setText("Train Data: There is no label with this Class ID!")
            msgBox.setIcon(QMessageBox.Critical)
            msgBox.setStandardButtons(QMessageBox.Ok)
            msgBox.exec_()
            return False

        if not len(np.where(YT == ClassID)[0]):
            msgBox.setText("Test Data: There is no label with this Class ID!")
            msgBox.setIcon(QMessageBox.Critical)
            msgBox.setStandardButtons(QMessageBox.Ok)
            msgBox.exec_()
            return False

        NoneZeroArea = np.where(Y != ClassID)
        New_Y = Y[NoneZeroArea]
        OutData[ui.txtLabel.currentText()] = New_Y

        NoneZeroAreaT = np.where(YT != ClassID)
        New_YT = YT[NoneZeroAreaT]
        OutData[ui.txtTLabel.currentText()] = New_YT

        try:
            X = InData[ui.txtData.currentText()]
            XT = InData[ui.txtTData.currentText()]
        except:
            print("Cannot load data")
            return
        OutData[ui.txtData.currentText()] = X[NoneZeroArea[1]]
        OutData[ui.txtTData.currentText()] = XT[NoneZeroAreaT[1]]

        # Subject
        if ui.cbSubject.isChecked():
            try:
                Subject = InData[ui.txtSubject.currentText()]
                OutData[ui.txtSubject.currentText()] = Subject[NoneZeroArea]

                SubjectT = InData[ui.txtTSubject.currentText()]
                OutData[ui.txtTSubject.currentText()] = SubjectT[NoneZeroAreaT]

            except:
                print("Cannot load Subject ID!")
                return

        # Task
        if ui.cbTask.isChecked():
            try:
                Task = InData[ui.txtTask.currentText()]
                OutData[ui.txtTask.currentText()] = np.array(
                    Task[NoneZeroArea], dtype=object)

                TaskT = InData[ui.txtTTask.currentText()]
                OutData[ui.txtTTask.currentText()] = np.array(
                    TaskT[NoneZeroAreaT], dtype=object)
            except:
                print("Cannot load Task ID!")
                return

        # Run
        if ui.cbRun.isChecked():
            try:
                Run = InData[ui.txtRun.currentText()]
                OutData[ui.txtRun.currentText()] = Run[NoneZeroArea]

                RunT = InData[ui.txtTRun.currentText()]
                OutData[ui.txtTRun.currentText()] = RunT[NoneZeroAreaT]
            except:
                print("Cannot load Run ID!")
                return

        # Counter
        if ui.cbCounter.isChecked():
            try:
                Counter = InData[ui.txtCounter.currentText()]
                OutData[ui.txtCounter.currentText()] = Counter[NoneZeroArea]

                CounterT = InData[ui.txtTCounter.currentText()]
                OutData[ui.txtTCounter.currentText()] = CounterT[NoneZeroAreaT]
            except:
                print("Cannot load Counter ID!")
                return

        # Matrix Label
        if ui.cbmLabel.isChecked():
            try:
                OutData[ui.txtmLabel.currentText()] = label_binarize(
                    New_Y, np.unique(New_Y))
                OutData[ui.txtTmLabel.currentText()] = label_binarize(
                    New_YT, np.unique(New_YT))
            except:
                print("Cannot load Matrix Label ID!")
                return

        # Design
        if ui.cbDM.isChecked():
            try:
                DM = InData[ui.txtDM.currentText()]
                OutData[ui.txtDM.currentText()] = DM[NoneZeroArea[1]]

                DMT = InData[ui.txtTDM.currentText()]
                OutData[ui.txtTDM.currentText()] = DMT[NoneZeroAreaT[1]]
            except:
                print("Cannot load Design Matrix ID!")
                return

        # Coordinate
        if ui.cbCol.isChecked():
            try:
                OutData[ui.txtCol.currentText()] = InData[
                    ui.txtCol.currentText()]
            except:
                print("Cannot load Coordinate ID!")
                return

        # NScan
        if ui.cbNScan.isChecked():
            try:
                NScan = InData[ui.txtNScan.currentText()]
                OutData[ui.txtNScan.currentText()] = NScan[NoneZeroArea]
                NScanT = InData[ui.txtTNScan.currentText()]
                OutData[ui.txtTNScan.currentText()] = NScanT[NoneZeroAreaT]
            except:
                print("Cannot load NScan ID!")
                return

        print("Saving ...")
        io.savemat(ui.txtOutFile.text(), mdict=OutData)
        print("Train: Number of selected instances: ",
              np.shape(NoneZeroArea)[1])
        print("Train: Number of all instances: ", np.shape(Y)[1])
        print("Test: Number of selected instances: ",
              np.shape(NoneZeroAreaT)[1])
        print("Test: Number of all instances: ", np.shape(YT)[1])
        print("DONE.")
        msgBox.setText("Rest scans are removed.")
        msgBox.setIcon(QMessageBox.Information)
        msgBox.setStandardButtons(QMessageBox.Ok)
        msgBox.exec_()
    def btnConvert_click(self):

        msgBox = QMessageBox()

        # Subject
        if ui.cbSubject.isChecked():
            if not len(ui.txtSubject.currentText()):
                msgBox.setText("Please enter Subject variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False

        # Task
        if ui.cbTask.isChecked():
            if not len(ui.txtTask.currentText()):
                msgBox.setText("Please enter Task variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False

        # Run
        if ui.cbRun.isChecked():
            if not len(ui.txtRun.currentText()):
                msgBox.setText("Please enter Run variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False

        # Counter
        if ui.cbCounter.isChecked():
            if not len(ui.txtCounter.currentText()):
                msgBox.setText("Please enter Counter variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False

        # Label
        if not len(ui.txtLabel.currentText()):
            msgBox.setText("Please enter Label variable name!")
            msgBox.setIcon(QMessageBox.Critical)
            msgBox.setStandardButtons(QMessageBox.Ok)
            msgBox.exec_()
            return False

        # Matrix Label
        if ui.cbmLabel.isChecked():
            if not len(ui.txtmLabel.currentText()):
                msgBox.setText("Please enter Matrix Label variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False

        # Data
        if not len(ui.txtData.currentText()):
            msgBox.setText("Please enter Data variable name!")
            msgBox.setIcon(QMessageBox.Critical)
            msgBox.setStandardButtons(QMessageBox.Ok)
            msgBox.exec_()
            return False

        # Design
        if ui.cbDM.isChecked():
            if not len(ui.txtDM.currentText()):
                msgBox.setText("Please enter Design Matrix variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False

        # Coordinate
        if ui.cbCol.isChecked():
            if not len(ui.txtCol.currentText()):
                msgBox.setText("Please enter Coordinator variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False

        # Condition
        if ui.cbCond.isChecked():
            if not len(ui.txtCond.currentText()):
                msgBox.setText("Please enter Condition variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False

        # Number of Scan
        if ui.cbNScan.isChecked():
            if not len(ui.txtNScan.currentText()):
                msgBox.setText("Please enter Number of Scan variable name!")
                msgBox.setIcon(QMessageBox.Critical)
                msgBox.setStandardButtons(QMessageBox.Ok)
                msgBox.exec_()
                return False

        # OutFile
        OutFile = ui.txtOutFile.text()
        if not len(OutFile):
            msgBox.setText("Please enter out file!")
            msgBox.setIcon(QMessageBox.Critical)
            msgBox.setStandardButtons(QMessageBox.Ok)
            msgBox.exec_()
            return False

        try:
            ClassID = np.int32(ui.txtClassID.text())
        except:
            msgBox.setText("Class ID is wrong!")
            msgBox.setIcon(QMessageBox.Critical)
            msgBox.setStandardButtons(QMessageBox.Ok)
            msgBox.exec_()
            return False

        # InFile
        InFile = ui.txtInFile.text()
        if not len(InFile):
            msgBox.setText("Please enter input file!")
            msgBox.setIcon(QMessageBox.Critical)
            msgBox.setStandardButtons(QMessageBox.Ok)
            msgBox.exec_()
            return False

        if not os.path.isfile(InFile):
            msgBox.setText("Input file not found!")
            msgBox.setIcon(QMessageBox.Critical)
            msgBox.setStandardButtons(QMessageBox.Ok)
            msgBox.exec_()
            return False

        InData = mainIO_load(InFile)
        OutData = dict()
        OutData["imgShape"] = reshape_1Dvector(InData["imgShape"])

        # Condition
        if ui.cbCond.isChecked():
            try:
                Cond = InData[ui.txtCond.currentText()]
                New_Condition = Conditions()
                for condition in Cond:
                    if reshape_condition_cell(
                            condition[0]) != ui.txtClassName.currentText():
                        New_Condition.add_cond(
                            reshape_condition_cell(condition[0]),
                            reshape_condition_cell(condition[1]))

                OutData[ui.txtCond.currentText()] = np.array(
                    New_Condition.get_cond(), dtype=object)
            except Exception as e:
                print(e)
                print("Cannot load Condition ID!")
                return
        # Label
        try:
            Y = InData[ui.txtLabel.currentText()]
        except:
            print("Cannot load class labels!")
            return
        if not len(np.where(Y == ClassID)[0]):
            msgBox.setText("There is no label  with this Class ID!")
            msgBox.setIcon(QMessageBox.Critical)
            msgBox.setStandardButtons(QMessageBox.Ok)
            msgBox.exec_()
            return False
        NoneZeroArea = np.where(Y != ClassID)
        New_Y = Y[NoneZeroArea]
        OutData[ui.txtLabel.currentText()] = reshape_1Dvector(New_Y)
        # Data
        try:
            X = InData[ui.txtData.currentText()]
        except:
            print("Cannot load data")
            return
        OutData[ui.txtData.currentText()] = X[NoneZeroArea[1]]
        # Subject
        if ui.cbSubject.isChecked():
            try:
                Subject = InData[ui.txtSubject.currentText()]
                OutData[ui.txtSubject.currentText()] = reshape_1Dvector(
                    Subject[NoneZeroArea])
            except:
                print("Cannot load Subject ID!")
                return
        # Task
        if ui.cbTask.isChecked():
            try:
                Task = np.array(InData[ui.txtTask.currentText()])
                OutData[ui.txtTask.currentText()] = reshape_1Dvector(
                    np.array(Task[NoneZeroArea], dtype=object))
            except:
                print("Cannot load Task ID!")
                return

        # Run
        if ui.cbRun.isChecked():
            try:
                Run = InData[ui.txtRun.currentText()]
                OutData[ui.txtRun.currentText()] = reshape_1Dvector(
                    Run[NoneZeroArea])
            except:
                print("Cannot load Run ID!")
                return

        # Counter
        if ui.cbCounter.isChecked():
            try:
                Counter = InData[ui.txtCounter.currentText()]
                OutData[ui.txtCounter.currentText()] = reshape_1Dvector(
                    Counter[NoneZeroArea])
            except:
                print("Cannot load Counter ID!")
                return

        # Matrix Label
        if ui.cbmLabel.isChecked():
            try:
                OutData[ui.txtmLabel.currentText()] = label_binarize(
                    New_Y, np.unique(New_Y))
            except:
                print("Cannot load Matrix Label ID!")
                return

        # Design
        if ui.cbDM.isChecked():
            try:
                DM = InData[ui.txtDM.currentText()]
                OutData[ui.txtDM.currentText()] = DM[NoneZeroArea[1]]
            except:
                print("Cannot load Design Matrix ID!")
                return

        # Coordinate
        if ui.cbCol.isChecked():
            try:
                OutData[ui.txtCol.currentText()] = InData[
                    ui.txtCol.currentText()]
            except:
                print("Cannot load Coordinate ID!")
                return

        # NScan
        if ui.cbNScan.isChecked():
            try:
                NScan = InData[ui.txtNScan.currentText()]
                OutData[ui.txtNScan.currentText()] = reshape_1Dvector(
                    NScan[NoneZeroArea])
            except:
                print("Cannot load NScan ID!")
                return

        print("Saving ...")
        mainIO_save(OutData, ui.txtOutFile.text())
        print("Number of selected instances: ", np.shape(NoneZeroArea)[1])
        print("Number of all instances: ", np.shape(Y)[1])
        print("DONE.")
        msgBox.setText("Rest scans are removed.")
        msgBox.setIcon(QMessageBox.Information)
        msgBox.setStandardButtons(QMessageBox.Ok)
        msgBox.exec_()