示例#1
0
    def test_read_sample_one(self):
        """Read the third extra_data sample (i.e. having index = 2). """
        filename = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                "..", "tests", "testdata",
                                "bidsmap_example_new.yaml")
        bidsmap_yaml = read_yaml_as_string(filename)
        bidsmap = read_bidsmap(bidsmap_yaml)

        index = 2
        modality = 'extra_data'

        yaml = ruamel.yaml.YAML()
        sample = read_sample(bidsmap, modality, index)
        sample_yaml = yaml.dump(sample, sys.stdout)

        yaml = ruamel.yaml.YAML()
        filename = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                "..", "tests", "testdata",
                                "bidsmap_example_new_sample2.yaml")
        with open(filename) as fp:
            test_sample_yaml = fp.read()
            test_sample = yaml.load(test_sample_yaml)
        test_sample_yaml = yaml.dump(test_sample, sys.stdout)

        self.assertEqual(test_sample_yaml, sample_yaml)
示例#2
0
    def test_get_list_summary(self):
        test_list_summary = [{
            "modality":
            "extra_data",
            "provenance_file":
            "M109.MR.WUR_BRAIN_ADHD.0002.0001.2018.03.01.13.05.10.140625.104357083.IMA",
            "provenance_path":
            "M:\\bidscoin\\raw\\sub-P002\\ses-mri01\\02_localizer AANGEPAST 11 SLICES",
            "bids_name":
            "sub-*_ses-*_acq-localizerAANGEPAST11SLICES_run-<<1>>"
        }, {
            "modality":
            "extra_data",
            "provenance_file":
            "M109.MR.WUR_BRAIN_ADHD.0003.0001.2018.03.01.13.05.10.140625.104359017.IMA",
            "provenance_path":
            "M:\\bidscoin\\raw\\sub-P002\\ses-mri01\\03_Stoptaak_ep2d_bold_nomoco",
            "bids_name":
            "sub-*_ses-*_acq-Stoptaakep2dboldnomoco_run-<<1>>"
        }, {
            "modality":
            "extra_data",
            "provenance_file":
            "M109.MR.WUR_BRAIN_ADHD.0004.0001.2018.03.01.13.05.10.140625.104364139.IMA",
            "provenance_path":
            "M:\\bidscoin\\raw\\sub-P002\\ses-mri01\\04_t1_mpr_sag_p2_iso_1",
            "bids_name":
            "sub-*_ses-*_acq-t1mprsagp2iso1_run-<<1>>"
        }, {
            "modality":
            "extra_data",
            "provenance_file":
            "M109.MR.WUR_BRAIN_ADHD.0005.0001.2018.03.01.13.05.10.140625.104368237.IMA",
            "provenance_path":
            "M:\\bidscoin\\raw\\sub-P002\\ses-mri01\\05_Flanker_ep2d_bold_nomoco",
            "bids_name":
            "sub-*_ses-*_acq-Flankerep2dboldnomoco_run-<<1>>"
        }, {
            "modality":
            "extra_data",
            "provenance_file":
            "M005.MR.WUR_BRAIN_ADHD.0007.0001.2018.04.12.13.00.48.734375.108749947.IMA",
            "provenance_path":
            "M:\\bidscoin\\raw\\sub-P002\\ses-mri02\\07_t1_fl3d_sag_p3_iso_1",
            "bids_name":
            "sub-*_ses-*_acq-t1fl3dsagp3iso1_run-<<1>>"
        }]

        filename = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                "..", "tests", "testdata",
                                "bidsmap_example_new.yaml")
        bidsmap_yaml = read_yaml_as_string(filename)
        bidsmap = read_bidsmap(bidsmap_yaml)
        list_summary = get_list_summary(bidsmap)

        self.assertEqual(list_summary, test_list_summary)
示例#3
0
    def test_get_num_samples(self):
        """Determine the number of extra_data samples."""
        filename = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                "..", "tests", "testdata",
                                "bidsmap_example_new.yaml")
        bidsmap_yaml = read_yaml_as_string(filename)
        bidsmap = read_bidsmap(bidsmap_yaml)

        modality = 'extra_data'
        num_samples = get_num_samples(bidsmap, modality)
        self.assertEqual(num_samples, 5)
示例#4
0
    def test_read_bidsmap(self):
        filename = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                "..", "tests", "testdata",
                                "bidsmap_example_new.yaml")
        bidsmap_yaml = read_yaml_as_string(filename)
        bidsmap = read_bidsmap(bidsmap_yaml)

        yaml = ruamel.yaml.YAML()
        with open(filename) as fp:
            test_bidsmap_yaml = fp.read()
            test_bidsmap = yaml.load(test_bidsmap_yaml)

        self.assertEqual(bidsmap_yaml, test_bidsmap_yaml)
        self.assertEqual(bidsmap, test_bidsmap)
示例#5
0
    def test_read_sample_all(self):
        """Loop over all extra_data samples and read them. """
        filename = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                "..", "tests", "testdata",
                                "bidsmap_example_new.yaml")
        bidsmap_yaml = read_yaml_as_string(filename)
        bidsmap = read_bidsmap(bidsmap_yaml)

        modality = 'extra_data'
        num_samples = get_num_samples(bidsmap, modality)
        self.assertEqual(num_samples, 5)

        for i in range(num_samples):
            sample = read_sample(bidsmap, modality, i)
示例#6
0
    def test_update_bidsmap(self):
        filename = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                "..", "tests", "testdata",
                                "bidsmap_example_new.yaml")
        source_bidsmap_yaml = read_yaml_as_string(filename)
        source_bidsmap = read_bidsmap(source_bidsmap_yaml)

        source_modality = 'extra_data'
        source_index = 2
        yaml = ruamel.yaml.YAML()
        filename = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                "..", "tests", "testdata",
                                "bidsmap_example_new_sample2.yaml")
        with open(filename) as fp:
            test_sample_yaml = fp.read()
            test_sample = yaml.load(test_sample_yaml)

        target_modality = 'anat'
        target_sample = copy.deepcopy(test_sample)

        target_bidsmap = update_bidsmap(source_bidsmap, source_modality,
                                        source_index, target_modality,
                                        target_sample)

        self.assertNotEqual(target_bidsmap, source_bidsmap)
        self.assertNotEqual(target_bidsmap['DICOM'][target_modality],
                            source_bidsmap['DICOM'][target_modality])
        self.assertNotEqual(target_bidsmap['DICOM'][source_modality],
                            source_bidsmap['DICOM'][source_modality])
        self.assertEqual(len(target_bidsmap['DICOM'][target_modality]), 1)
        self.assertEqual(len(target_bidsmap['DICOM'][source_modality]), 4)

        target_filename = os.path.join(
            os.path.dirname(os.path.realpath(__file__)), "..", "tests",
            "testdata", "bidsmap_example_out.yaml")
        reference_filename = os.path.join(
            os.path.dirname(os.path.realpath(__file__)), "..", "tests",
            "testdata", "bidsmap_example_new_out.yaml")

        save_bidsmap(target_filename, target_bidsmap)
        text1 = open(target_filename).readlines()
        text2 = open(reference_filename).readlines()
        lines = list(difflib.unified_diff(text1, text2))
        logger.info(''.join(lines))
        self.assertEqual(len(lines), 0)  # Difference must be zero
示例#7
0
    logdir = os.path.dirname(os.path.abspath(args.logfile))
    if not os.path.exists(logdir):
        os.makedirs(logdir)

    setup_logging(args.logfile)
    logger.info('Started BIDS editor')

    # Validate the arguments
    if not os.path.exists(args.rawfolder):
        raise Exception("Raw folder not found: {}".format(args.rawfolder))
    if not os.path.exists(args.inputbidsmap):
        raise Exception("Input BIDS map not found: {}".format(
            args.inputbidsmap))

    # Obtain the initial bidsmap info
    input_bidsmap_yaml = bidsutils.read_yaml_as_string(args.inputbidsmap)
    input_bidsmap = bidsutils.read_bidsmap(input_bidsmap_yaml)

    output_bidsmap = copy.deepcopy(input_bidsmap)

    logger.info('Input raw data folder: {}'.format(args.rawfolder))
    logger.info('Input BIDS map: {}'.format(args.inputbidsmap))
    logger.info('Output log file: {}'.format(args.logfile))

    # Start the application
    app = QApplication(sys.argv)
    app.setApplicationName("BIDS editor")
    mainwin = QMainWindow()
    gui = Ui_MainWindow()
    gui.setupUi(mainwin, args.rawfolder, args.inputbidsmap, input_bidsmap,
                output_bidsmap)