Exemple #1
0
    def openDetails(self):
        """opens details file which has additional information on subjects """
        import subprocess

        fileName = os.path.join(self.cfg["folders"]["nifti"],
                                'subjdetails.csv')
        if os.path.isfile(fileName):
            subprocess.Popen(["xdg-open", ''.join(fileName)])
        else:
            HF.msg_box(text='Subject details are not available!',
                       title='Detail file not found')
Exemple #2
0
    def run_ManualCorrection(self):
        """wrapper which starts the plotting routine for the detected lead which enables manual corrections"""

        if len(self.selected_subj_ANT) != 1:
            HF.msg_box(text="Please select one and only one subject",
                       title="Subjects selected")
            return
        else:
            msg = "Are you sure you want to process the following subject:\n\n" \
                  "{}".format(''.join(' -> {}\n'.format(c) for c in self.selected_subj_ANT))
            ret = QMessageBox.question(self, 'MessageBox', msg,
                                       QMessageBox.Yes | QMessageBox.No,
                                       QMessageBox.Yes)
            if ret == QMessageBox.Yes:
                plotElecModel.PlotRoutines(subject=self.selected_subj_ANT[0],
                                           inputfolder=os.path.join(
                                               self.niftidir,
                                               self.selected_subj_ANT[0]))
Exemple #3
0
    def run_LeadDetectionPaCER(self):
        """wrapper to start lead detection with PaCER routines translated to python; original data can be found at:
        https://github.com/adhusch/PaCER/"""

        if len(self.selected_subj_ANT) > 1:
            HF.msg_box(
                text=
                "Please select only one subject, as multiprocessing for lead detection is not intended",
                title="Too many subjects selected")
            return
        else:
            msg = "Are you sure you want to process the following subject:\n\n" \
                  "{}".format(''.join(' -> {}\n'.format(c) for c in self.selected_subj_ANT))
            ret = QMessageBox.question(self, 'MessageBox', msg,
                                       QMessageBox.Yes | QMessageBox.No,
                                       QMessageBox.Yes)
            if ret == QMessageBox.Yes:
                LeadDetectionRoutines.PaCER_script(
                    subjects=self.selected_subj_ANT)
Exemple #4
0
    def run_RegisterMRI2template(self):
        """Wrapper to run the coregistration routines for the MRI (moving image) to MRI templates (fixed image)
        specified in the config file using ANTs routines"""

        if not self.selected_subj_ANT:
            HF.msg_box(
                text=
                "No folder selected. To proceed, please indicate what folder to process. "
                "(For this option, numerous folders are possible for batch processing)",
                title="No subject selected")
        else:
            msg = "Are you sure you want to coregister the preoperative imaging in the following folders:\n\n" \
                  "{}".format(''.join(' -> {}\n'.format(c) for c in self.selected_subj_ANT))
            ret = QMessageBox.question(self, 'MessageBox', msg,
                                       QMessageBox.Yes | QMessageBox.No,
                                       QMessageBox.Yes)
            if ret == QMessageBox.Yes:
                ANTspyRoutines.RegistrationANTs().CoregisterMRI2template(
                    subjects=self.selected_subj_ANT)
Exemple #5
0
    def run_n4Bias_corr(self):
        """wrapper to start the preprocessing, that is the GUI in which the different options for ANTs routines
        are displayed"""

        if not self.selected_subj_ANT:
            HF.msg_box(
                text=
                "No folder selected. To proceed, please indicate what folder to process. "
                "(For this option, numerous folders are possible for batch processing)",
                title="No subject selected")
        else:
            msg = "Are you sure you want to process all NIFTI-files in the following folders:\n\n" \
                  "{}".format(''.join(' -> {}\n'.format(c) for c in self.selected_subj_ANT))
            ret = QMessageBox.question(self, 'MessageBox', msg,
                                       QMessageBox.Yes | QMessageBox.No,
                                       QMessageBox.Yes)
            if ret == QMessageBox.Yes:
                ANTspyRoutines.RegistrationANTs().N4BiasCorrection(
                    subjects=self.selected_subj_ANT)
Exemple #6
0
    def run_RegisterCT2MRI(self):
        """Wrapper to run the coregistration routines for the CT (moving image) to the T1-sequence of the MRI
        (fixed image) using ANTs routines"""

        if not self.selected_subj_ANT:
            HF.msg_box(
                text=
                "No folder selected. To proceed, please indicate what folder to process. "
                "(For this option, numerous folders are possible for batch processing)",
                title="No subject selected")
        else:
            msg = "Are you sure you want to coregister the postoperative CT imaging in the following folders:\n\n" \
                  "{}".format(''.join(' -> {}\n'.format(c) for c in self.selected_subj_ANT))
            ret = QMessageBox.question(self, 'MessageBox', msg,
                                       QMessageBox.Yes | QMessageBox.No,
                                       QMessageBox.Yes)
            if ret == QMessageBox.Yes:
                ANTspyRoutines.RegistrationANTs().CoregisterCT2MRI(
                    subjects=self.selected_subj_ANT,
                    input_folder=self.cfg["folders"]["nifti"])
Exemple #7
0
    def VisualiseLeadDetection(self):
        """wrapper to start comparisons between pre- and post-processed images after N4BiasCorrection"""

        if not self.selected_subj_ANT:
            HF.msg_box(
                text=
                "No folder selected. To proceed, please select at least one.",
                title="No subject selected")
            return
        elif len(self.selected_subj_ANT) > 1:
            HF.msg_box(text="Please select only one subj.",
                       title="Too many subjects selected")
            return
        else:
            image_folder = os.path.join(
                self.cfg["folders"]["nifti"],
                self.selected_subj_ANT[0])  # Is the index necessary

        self.SelectFiles = TwoListGUI(working_directory=image_folder,
                                      option_gui="displayNiftiFiles")
        self.SelectFiles.show()
Exemple #8
0
    def show_nifti_files(self):
        """this function opens a list dialog and enables selecting NIFTI files for e.g. check the content (identical
        function as in GUITabPreprocessANTs.py."""

        if not self.selected_subj_Gen:
            HF.msg_box(
                text=
                "No folder selected. To proceed, please indicate what folder to process.",
                title="No subject selected")
            return
        elif len(self.selected_subj_Gen) > 1:
            HF.msg_box(
                text=
                "Please select only one folder to avoid loading too many images",
                title="Too many subjects selected")
            return
        else:
            image_folder = os.path.join(self.cfg["folders"]["nifti"],
                                        self.selected_subj_Gen[0])

        self.SelectFiles = TwoListGUI(working_directory=image_folder,
                                      option_gui="displayNiftiFiles")
        self.SelectFiles.show()
Exemple #9
0
    def compare_n4Bias_results(self):
        """this function enables to select NIFTI files and e.g. compare the results obtained at this step."""

        if not self.selected_subj_ANT:
            HF.msg_box(
                text=
                "No folder selected. To proceed, please indicate what folder to process.",
                title="No subject selected")
            return
        elif len(self.selected_subj_ANT) > 1:
            HF.LittleHelpers.msg_box(
                text=
                "Please select only one folder to avoid loading too many images",
                title="Too many subjects selected")
            return
        else:
            image_folder = os.path.join(
                self.cfg["folders"]["nifti"],
                self.selected_subj_ANT[0])  # Is the index necessary

        self.SelectFiles = TwoListGUI(working_directory=image_folder,
                                      option_gui="displayNiftiFiles")
        self.SelectFiles.show()
Exemple #10
0
    def __init__(self, working_directory, _option_gui, parent=None):
        super(QWidget, self).__init__(parent)
        self.cfg = HF.LittleHelpers.load_config(ROOTDIR)
        self.option_gui = _option_gui

        # ============================    Different options available   ============================
        if self.option_gui == 'dcm2niix':
            if os.path.isdir(self.cfg["folders"]["dicom"]):
                self.working_dir = self.cfg["folders"]["dicom"]
            else:
                self.working_dir = os.getcwd()

            options = {
                'folderbox_title': "Directory (DICOM-files)",
                'str_labelDir': 'DICOM DIR: {}'.format(self.working_dir),
                'runBTN_label': 'Run processing'
            }

        elif self.option_gui == "displayNiftiFiles":
            if not working_directory:
                HF.msg_box(
                    text='Please provide a valid folder. Terminating this GUI.',
                    title='No folder provided')
                self.close()
                return
            else:
                self.working_dir = working_directory
            options = {
                'folderbox_title': "Directory (nifti-files)",
                'str_labelDir': 'subjects\' DIR: {}'.format(self.working_dir),
                'runBTN_label': 'View files'
            }
        else:
            HF.msg_box(
                text=
                'Please provide a valid option such as "dcm2niix" or "displayNiftiFiles". '
                'Terminating the GUI',
                title='Wrong input as option')
            self.close()
            return

        # Create general layout
        self.tot_layout = QVBoxLayout(self)
        self.mid_layout = QHBoxLayout(self)

        # ============================    Create upper of  GUI, i.e. working directory   ============================
        self.label_folderbox = QGroupBox(options["folderbox_title"])
        self.HBoxUpperTwoListGUI = QVBoxLayout(self.label_folderbox)
        self.label_workingdir = QLabel(options["str_labelDir"])
        self.HBoxUpperTwoListGUI.addWidget(self.label_workingdir)

        self.btn_workingdir = QPushButton('Change working \ndirectory')
        self.btn_workingdir.setFixedSize(150, 40)
        self.btn_workingdir.setDisabled(True)
        if self.option_gui == "dcm2niix":
            self.btn_workingdir.setEnabled(True)
        self.btn_workingdir.clicked.connect(self.change_workingdir)

        self.btn_savedir = QPushButton('Save directory \nto config file')
        self.btn_savedir.setFixedSize(150, 40)
        self.btn_savedir.setDisabled(True)
        if self.option_gui == "dcm2niix":
            self.btn_savedir.setEnabled(True)
            self.btn_savedir.setToolTip(
                HF.LittleHelpers.split_lines(setToolTips.saveDirButton()))
        self.btn_savedir.clicked.connect(self.save_cfg_dicomdir)

        hlay_upper = QHBoxLayout()
        hlay_upper.addWidget(self.btn_workingdir)
        hlay_upper.addWidget(self.btn_savedir)
        hlay_upper.addStretch(1)
        self.HBoxUpperTwoListGUI.addLayout(hlay_upper)

        # ====================    Create Content for Lists, i.e. input/output      ====================
        self.listboxInputGUITwoList = QGroupBox(
            'Available items in working directory')
        self.listboxInput = QVBoxLayout(self.listboxInputGUITwoList)
        self.mInput = QListWidget()
        self.listboxInput.addWidget(self.mInput)

        self.mButtonToAvailable = QPushButton("<<")
        self.mBtnMoveToAvailable = QPushButton(">")
        self.mBtnMoveToSelected = QPushButton("<")
        self.mButtonToSelected = QPushButton(">>")
        self.mBtnUp = QPushButton("Up")
        self.mBtnDown = QPushButton("Down")

        self.listboxOutputGUITwoLIst = QGroupBox('Items to process')
        self.listboxOutput = QVBoxLayout(self.listboxOutputGUITwoLIst)
        self.mOutput = QListWidget()
        self.listboxOutput.addWidget(self.mOutput)

        # First column (Left side)
        vlay = QVBoxLayout()
        vlay.addStretch()
        vlay.addWidget(self.mBtnMoveToAvailable)
        vlay.addWidget(self.mBtnMoveToSelected)
        vlay.addStretch()
        vlay.addWidget(self.mButtonToAvailable)
        vlay.addWidget(self.mButtonToSelected)
        vlay.addStretch()

        # Second column (Right side)
        vlay2 = QVBoxLayout()
        vlay2.addStretch()
        vlay2.addWidget(self.mBtnUp)
        vlay2.addWidget(self.mBtnDown)
        vlay2.addStretch()

        # ====================    Lower part of GUI, i.e. Preferences/Start estimation      ====================
        self.btn_preferences = QPushButton("Preferences")
        self.btn_preferences.setDisabled(True)
        self.btn_preferences.clicked.connect(self.settings_show)
        if self.option_gui == "dcm2niix":
            self.btn_preferences.setEnabled(True)

        self.btn_run_command = QPushButton(options["runBTN_label"])
        if self.option_gui == "dcm2niix":
            self.btn_run_command.setToolTip(setToolTips.run_dcm2niix())
        else:
            self.btn_run_command.setToolTip(
                setToolTips.run_CheckRegistration())
        self.btn_run_command.clicked.connect(self.start_process)

        hlay_bottom = QHBoxLayout()
        hlay_bottom.addStretch(1)
        hlay_bottom.addWidget(self.btn_preferences)
        hlay_bottom.addWidget(self.btn_run_command)
        hlay_bottom.addStretch()

        # ====================    Set all contents to general Layout     =======================
        self.mid_layout.addWidget(self.listboxInputGUITwoList)
        self.mid_layout.addLayout(vlay)
        self.mid_layout.addWidget(self.listboxOutputGUITwoLIst)
        self.mid_layout.addLayout(vlay2)

        self.tot_layout.addWidget(self.label_folderbox)
        self.tot_layout.addLayout(self.mid_layout)
        self.tot_layout.addLayout(hlay_bottom)

        try:
            self.mInput.clear()
            if self.option_gui == 'dcm2niix':
                items = HF.list_folders(self.working_dir, prefix='')
            else:
                items = HF.list_files_in_folder(inputdir=self.working_dir,
                                                contains='',
                                                suffix='nii')
            self.addAvailableItems(items)
        except FileExistsError:
            print('{} without any valid files/folders, continuing ...'.format(
                self.working_dir))

        self.update_buttons_status()
        self.connections()