예제 #1
0
    def test_get_bids_name(self):
        bids_name = get_bids_name([])
        self.assertEqual(bids_name, "")

        bids_name_array = get_bids_name_array("", "", "extra_data", {}, "")
        bids_name = get_bids_name(bids_name_array)
        self.assertEqual(bids_name, "sub-_acq-")
예제 #2
0
    def selection_dropdown_change(self, i):
        """Update the BIDS values and BIDS name section when the dropdown selection has been taking place. """
        self.target_modality = self.view_dropdown.currentText()

        # Given the input BIDS attributes, derive the target BIDS attributes (i.e map them to the target attributes)
        bids_values, data = self.get_bids_values_data()

        # Update the BIDS values
        table = self.view_bids
        num_rows = bidsutils.MAX_NUM_BIDS_ATTRIBUTES
        for i, row in enumerate(data):
            key = row[0]["value"]
            if self.target_modality in ['anat', 'extra_data'
                                        ] and key == 'modality_label':
                self.modality_label_dropdown = QComboBox()
                self.modality_label_dropdown.addItems(
                    bidsutils.MODALITY_LABELS)
                self.modality_label_dropdown.setCurrentIndex(
                    self.modality_label_dropdown.findText(
                        self.target_modality_label))
                self.modality_label_dropdown.currentIndexChanged.connect(
                    self.selection_modality_label_dropdown_change)
                item = self.set_cell("modality_label", is_editable=False)
                table.setItem(i, 0, QTableWidgetItem(item))
                table.setCellWidget(i, 1, self.modality_label_dropdown)
                continue
            for j, element in enumerate(row):
                value = element.get("value", "")
                if value == "None":
                    value = ""
                is_editable = element.get("is_editable", False)
                table.removeCellWidget(i, j)
                item = self.set_cell(value, is_editable=is_editable)
                table.setItem(i, j, QTableWidgetItem(item))
        for i in range(len(data), num_rows):
            for j, element in enumerate(row):
                table.removeCellWidget(i, j)
                item = self.set_cell('', is_editable=False)
                table.setItem(i, j, QTableWidgetItem(item))

        self.view_bids = table

        bids_values['modality_label'] = self.target_modality_label

        # Update the BIDS name
        subid = '*'
        sesid = '*'
        run = bids_values.get('run_index', '*')
        bids_name_array = bidsutils.get_bids_name_array(
            subid, sesid, self.target_modality, bids_values, run)
        bids_name = bidsutils.get_bids_name(bids_name_array)

        self.view_bids_name.clear()
        self.view_bids_name.textCursor().insertText(bids_name)
예제 #3
0
    def selection_modality_label_dropdown_change(self, i):
        """Update the BIDS values and BIDS name section when the dropdown selection has been taking place. """
        self.target_modality_label = self.modality_label_dropdown.currentText()

        bids_values, data = self.get_bids_values_data()
        bids_values['modality_label'] = self.target_modality_label

        # Update the BIDS name
        subid = '*'
        sesid = '*'
        run = bids_values.get('run_index', '*')
        bids_name_array = bidsutils.get_bids_name_array(
            subid, sesid, self.target_modality, bids_values, run)
        bids_name = bidsutils.get_bids_name(bids_name_array)

        self.view_bids_name.clear()
        self.view_bids_name.textCursor().insertText(bids_name)
예제 #4
0
    def cell_was_clicked(self, row, column):
        """BIDS attribute value has been changed. """
        if column == 1:
            item_key = self.view_bids.item(row, 0)
            item_value = self.view_bids.item(row, 1)
            key = item_key.text()
            value = item_value.text()

            self.target_sample['bids'][key] = value

            bids_values = self.target_sample['bids']
            subid = '*'
            sesid = '*'
            run = bids_values.get('run_index', '*')
            bids_name_array = bidsutils.get_bids_name_array(
                subid, sesid, self.target_modality, bids_values, run)
            bids_name = bidsutils.get_bids_name(bids_name_array)
            self.bids_name = bids_name

            self.view_bids_name.clear()
            self.view_bids_name.textCursor().insertText(self.bids_name)
예제 #5
0
    def set_bids_name_section(self):
        """Set non-editable BIDS name section. """
        bids_values, _ = self.get_bids_values_data()

        subid = '*'
        sesid = '*'
        run = bids_values.get('run_index', '*')
        bids_name_array = bidsutils.get_bids_name_array(
            subid, sesid, self.target_modality, bids_values, run)
        bids_name = bidsutils.get_bids_name(bids_name_array)

        self.bids_name = bids_name

        self.label_bids_name = QLabel()
        self.label_bids_name.setText("BIDS name")

        self.view_bids_name = QTextEdit()
        self.view_bids_name.setReadOnly(True)
        self.view_bids_name.textCursor().insertText(self.bids_name)
        height = 24
        extra_space = 6
        self.view_bids_name.setFixedHeight(height + extra_space)