Пример #1
0
def test_run_T1VolumeTissueSegmentation(cmdopt):
    import os
    from clinica.pipelines.t1_volume_tissue_segmentation.t1_volume_tissue_segmentation_pipeline import T1VolumeTissueSegmentation
    from os.path import dirname, join, abspath

    working_dir = cmdopt
    root = dirname(abspath(join(abspath(__file__), pardir)))
    root = join(root, 'data', 'T1VolumeTissueSegmentation')
    clean_folder(join(working_dir, 'T1VolumeTissueSegmentation'))
    clean_folder(join(root, 'out', 'caps'))

    pipeline = T1VolumeTissueSegmentation(
        bids_directory=join(root, 'in', 'bids'),
        caps_directory=join(root, 'out', 'caps'),
        tsv_file=join(root, 'in', 'subjects.tsv'))
    pipeline.base_dir = join(working_dir, 'T1VolumeTissueSegmentation')
    pipeline.build()
    pipeline.run(bypass_check=True)

    out_file = join(
        root,
        'out/caps/subjects/sub-ADNI011S4105/ses-M00/t1/spm/segmentation/dartel_input/'
        + 'sub-ADNI011S4105_ses-M00_T1w_segm-graymatter_dartelinput.nii.gz')
    if not os.path.exists(out_file):
        raise IOError(
            'Pipeline did not produce file : ' + out_file +
            '. Consider rerunning test_run_T1VolumeTissueSegmentation')

    ref_file = join(
        root,
        'ref/caps/subjects/sub-ADNI011S4105/ses-M00/t1/spm/segmentation/dartel_input/'
        + 'sub-ADNI011S4105_ses-M00_T1w_segm-graymatter_dartelinput.nii.gz')

    assert likeliness_measure(out_file, ref_file, (1e-1, 0.02), (0.4, 0.01))
    clean_folder(join(root, 'out', 'caps'), recreate=False)
def test_instantiate_T1VolumeTissueSegmentation():
    from clinica.pipelines.t1_volume_tissue_segmentation.t1_volume_tissue_segmentation_pipeline import T1VolumeTissueSegmentation
    from os.path import dirname, join, abspath

    root = dirname(abspath(join(abspath(__file__), pardir)))
    root = join(root, 'data', 'T1VolumeTissueSegmentation')
    pipeline = T1VolumeTissueSegmentation(
        bids_directory=join(root, 'in', 'bids'),
        caps_directory=join(root, 'in', 'caps'),
        tsv_file=join(root, 'in', 'subjects.tsv'))
    pipeline.build()
Пример #3
0
def test_instantiate_T1VolumeTissueSegmentation():
    from os.path import abspath, dirname, join

    from clinica.pipelines.t1_volume_tissue_segmentation.t1_volume_tissue_segmentation_pipeline import (
        T1VolumeTissueSegmentation, )

    root = dirname(abspath(join(abspath(__file__), pardir)))
    root = join(root, "data", "T1VolumeTissueSegmentation")

    pipeline = T1VolumeTissueSegmentation(
        bids_directory=join(root, "in", "bids"),
        caps_directory=join(root, "in", "caps"),
        tsv_file=join(root, "in", "subjects.tsv"),
    )
    pipeline.build()
Пример #4
0
def test_instantiate_T1VolumeTissueSegmentation(cmdopt):

    from clinica.pipelines.t1_volume_tissue_segmentation.t1_volume_tissue_segmentation_pipeline import (
        T1VolumeTissueSegmentation, )

    input_dir = Path(cmdopt["input"])
    root = input_dir / "T1VolumeTissueSegmentation"

    parameters = {"skip_question": True}
    pipeline = T1VolumeTissueSegmentation(
        bids_directory=fspath(root / "in" / "bids"),
        caps_directory=fspath(root / "in" / "caps"),
        tsv_file=fspath(root / "in" / "subjects.tsv"),
        parameters=parameters,
    )
    pipeline.build()
Пример #5
0
def run_T1VolumeTissueSegmentation(
    input_dir: Path, output_dir: Path, ref_dir: Path, working_dir: Path
) -> None:

    from clinica.pipelines.t1_volume_tissue_segmentation.t1_volume_tissue_segmentation_pipeline import (
        T1VolumeTissueSegmentation,
    )

    parameters = {"skip_question": False}
    pipeline = T1VolumeTissueSegmentation(
        bids_directory=fspath(input_dir / "bids"),
        caps_directory=fspath(output_dir / "caps"),
        tsv_file=fspath(input_dir / "subjects.tsv"),
        parameters=parameters,
        base_dir=fspath(working_dir),
    )
    pipeline.build()
    pipeline.run(bypass_check=True)

    out_file = fspath(
        output_dir
        / "caps"
        / "subjects"
        / "sub-ADNI011S4105"
        / "ses-M00"
        / "t1"
        / "spm"
        / "segmentation"
        / "dartel_input"
        / "sub-ADNI011S4105_ses-M00_T1w_segm-graymatter_dartelinput.nii.gz",
    )

    ref_file = fspath(
        ref_dir
        / "caps"
        / "subjects"
        / "sub-ADNI011S4105"
        / "ses-M00"
        / "t1"
        / "spm"
        / "segmentation"
        / "dartel_input"
        / "sub-ADNI011S4105_ses-M00_T1w_segm-graymatter_dartelinput.nii.gz",
    )

    assert likeliness_measure(out_file, ref_file, (1e-1, 0.02), (0.4, 0.01))
Пример #6
0
def test_run_T1VolumeTissueSegmentation(cmdopt):
    import os
    from os.path import abspath, dirname, join

    from clinica.pipelines.t1_volume_tissue_segmentation.t1_volume_tissue_segmentation_pipeline import (
        T1VolumeTissueSegmentation, )

    working_dir = cmdopt
    root = dirname(abspath(join(abspath(__file__), pardir, pardir)))
    root = join(root, "data", "T1VolumeTissueSegmentation")
    clean_folder(join(working_dir, "T1VolumeTissueSegmentation"))
    clean_folder(join(root, "out", "caps"))

    pipeline = T1VolumeTissueSegmentation(
        bids_directory=join(root, "in", "bids"),
        caps_directory=join(root, "out", "caps"),
        tsv_file=join(root, "in", "subjects.tsv"),
        base_dir=join(working_dir, "T1VolumeTissueSegmentation"),
    )
    pipeline.build()
    pipeline.run(bypass_check=True)

    out_file = join(
        root,
        "out/caps/subjects/sub-ADNI011S4105/ses-M00/t1/spm/segmentation/dartel_input/"
        + "sub-ADNI011S4105_ses-M00_T1w_segm-graymatter_dartelinput.nii.gz",
    )
    if not os.path.exists(out_file):
        raise IOError(
            "Pipeline did not produce file: " + out_file +
            ". Consider rerunning test_run_T1VolumeTissueSegmentation")

    ref_file = join(
        root,
        "ref/caps/subjects/sub-ADNI011S4105/ses-M00/t1/spm/segmentation/dartel_input/"
        + "sub-ADNI011S4105_ses-M00_T1w_segm-graymatter_dartelinput.nii.gz",
    )

    assert likeliness_measure(out_file, ref_file, (1e-1, 0.02), (0.4, 0.01))

    clean_folder(join(root, "out", "caps"), recreate=False)
    clean_folder(join(working_dir, "T1VolumeTissueSegmentation"),
                 recreate=False)
Пример #7
0
    def run_command(self, args):
        """
        """
        from tempfile import mkdtemp
        from clinica.utils.stream import cprint
        from clinica.pipelines.t1_volume_tissue_segmentation.t1_volume_tissue_segmentation_pipeline import T1VolumeTissueSegmentation

        pipeline = T1VolumeTissueSegmentation(
            bids_directory=self.absolute_path(args.bids_directory),
            caps_directory=self.absolute_path(args.caps_directory),
            tsv_file=self.absolute_path(args.subjects_sessions_tsv))

        pipeline.parameters.update({
            'tissue_classes': args.tissue_classes,
            'dartel_tissues': args.dartel_tissues,
            'tpm': args.tissue_probability_maps,
            'save_warped_unmodulated': args.save_warped_unmodulated,
            'save_warped_modulated': args.save_warped_modulated,
            'write_deformation_fields':
            [True, True],  # args.write_deformation_fields
            'save_t1_mni': True
        })

        if args.working_directory is None:
            args.working_directory = mkdtemp()
        pipeline.base_dir = self.absolute_path(args.working_directory)

        if args.n_procs:
            pipeline.run(plugin='MultiProc',
                         plugin_args={'n_procs': args.n_procs})
        else:
            pipeline.run()

        cprint(
            "The " + self._name +
            " pipeline has completed. You can now delete the working directory ("
            + args.working_directory + ").")