def test_instantiate_StatisticsSurface():
    from os.path import dirname, join, abspath
    from clinica.pipelines.statistics_surface.statistics_surface_pipeline import StatisticsSurface

    root = dirname(abspath(join(abspath(__file__), pardir)))
    root = join(root, 'data', 'StatisticsSurface')
    parameters = {
        'design_matrix': '1 + group + age + sex',
        'contrast': 'group',
        'str_format': '%s %s %s %f %s',
        'group_label': 'UnitTest',
        'glm_type': 'group_comparison',
        'custom_file':
        '@subject/@session/t1/freesurfer_cross_sectional/@subject_@session/surf/@[email protected]',
        'feature_label': 'cortical_thickness',
        'full_width_at_half_maximum': 20,
        'threshold_uncorrected_pvalue': 0.001,
        'threshold_corrected_pvalue': 0.05,
        'cluster_threshold': 0.001
    }
    pipeline = StatisticsSurface(caps_directory=join(root, 'in', 'caps'),
                                 tsv_file=join(root, 'in', 'subjects.tsv'),
                                 parameters=parameters)

    pipeline.build()
Example #2
0
def test_instantiate_StatisticsSurface():
    from os.path import abspath, dirname, join

    from clinica.pipelines.statistics_surface.statistics_surface_pipeline import (
        StatisticsSurface, )

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

    parameters = {
        # Clinica compulsory parameters
        "group_label": "UnitTest",
        "orig_input_data": "t1-freesurfer",
        "glm_type": "group_comparison",
        "contrast": "group",
        # Optional parameters
        "covariates": "age sex",
    }
    pipeline = StatisticsSurface(
        caps_directory=join(root, "in", "caps"),
        tsv_file=join(root, "in", "subjects.tsv"),
        parameters=parameters,
    )

    pipeline.build()
def test_run_StatisticsSurface(cmdopt):
    import shutil
    from os.path import abspath, dirname, join

    import numpy as np
    from scipy.io import loadmat

    from clinica.pipelines.statistics_surface.statistics_surface_pipeline import (
        StatisticsSurface,
    )

    working_dir = cmdopt
    root = dirname(abspath(join(abspath(__file__), pardir, pardir)))
    root = join(root, "data", "StatisticsSurface")

    clean_folder(join(root, "out", "caps"), recreate=False)
    clean_folder(join(working_dir, "StatisticsSurface"))
    shutil.copytree(join(root, "in", "caps"), join(root, "out", "caps"))

    parameters = {
        # Clinica compulsory parameters
        "group_label": "UnitTest",
        "orig_input_data": "t1-freesurfer",
        "glm_type": "group_comparison",
        "contrast": "group",
        # Optional parameters
        "covariates": "age sex",
    }
    pipeline = StatisticsSurface(
        caps_directory=join(root, "out", "caps"),
        tsv_file=join(root, "in", "subjects.tsv"),
        base_dir=join(working_dir, "StatisticsSurface"),
        parameters=parameters,
    )
    pipeline.build()
    pipeline.run(plugin="MultiProc", plugin_args={"n_procs": 1}, bypass_check=True)

    # Check files
    filename = "group-UnitTest_AD-lt-CN_measure-ct_fwhm-20_correctedPValue.mat"
    out_file = join(
        root,
        "out",
        "caps",
        "groups",
        "group-UnitTest",
        "statistics",
        "surfstat_group_comparison",
        filename,
    )
    ref_file = join(root, "ref", filename)

    out_file_mat = loadmat(out_file)["correctedpvaluesstruct"]
    ref_file_mat = loadmat(ref_file)["correctedpvaluesstruct"]
    for i in range(4):
        assert np.allclose(
            out_file_mat[0][0][i], ref_file_mat[0][0][i], rtol=1e-8, equal_nan=True
        )
    clean_folder(join(root, "out", "caps"), recreate=False)
    clean_folder(join(working_dir, "StatisticsSurface"), recreate=False)
Example #4
0
def test_run_StatisticsSurface(cmdopt):
    from clinica.pipelines.statistics_surface.statistics_surface_pipeline import StatisticsSurface
    from os.path import dirname, join, abspath
    import shutil
    import numpy as np
    from scipy.io import loadmat

    working_dir = cmdopt
    root = dirname(abspath(join(abspath(__file__), pardir)))
    root = join(root, 'data', 'StatisticsSurface')

    clean_folder(join(root, 'out', 'caps'), recreate=False)
    clean_folder(join(working_dir, 'StatisticsSurface'))
    shutil.copytree(join(root, 'in', 'caps'), join(root, 'out', 'caps'))

    parameters = {
        'design_matrix': '1 + group + age + sex',
        'contrast': 'group',
        'str_format': '%s %s %s %f %s',
        'group_label': 'UnitTest',
        'glm_type': 'group_comparison',
        'custom_file':
        '@subject/@session/t1/freesurfer_cross_sectional/@subject_@session/surf/@[email protected]',
        'feature_label': 'cortical_thickness',
        'full_width_at_half_maximum': 20,
        'threshold_uncorrected_pvalue': 0.001,
        'threshold_corrected_pvalue': 0.05,
        'cluster_threshold': 0.001
    }
    pipeline = StatisticsSurface(caps_directory=join(root, 'out', 'caps'),
                                 tsv_file=join(root, 'in', 'subjects.tsv'),
                                 base_dir=join(working_dir,
                                               'StatisticsSurface'),
                                 parameters=parameters)
    pipeline.build()
    pipeline.run(plugin='MultiProc',
                 plugin_args={'n_procs': 8},
                 bypass_check=True)

    # Check files
    out_file = join(
        root,
        'out/caps/groups/group-UnitTest/statistics/surfstat_group_comparison/group-UnitTest_AD-lt-CN_measure-cortical_thickness_fwhm-20_correctedPValue.mat'
    )
    ref_file = join(
        root,
        'ref/group-UnitTest_AD-lt-CN_measure-cortical_thickness_fwhm-20_correctedPValue.mat'
    )

    out_file_mat = loadmat(out_file)['correctedpvaluesstruct']
    ref_file_mat = loadmat(ref_file)['correctedpvaluesstruct']
    for i in range(4):
        assert np.allclose(out_file_mat[0][0][i],
                           ref_file_mat[0][0][i],
                           rtol=1e-8,
                           equal_nan=True)
    clean_folder(join(root, 'out', 'caps'), recreate=False)
    clean_folder(join(working_dir, 'StatisticsSurface'), recreate=False)
Example #5
0
def run_StatisticsSurface(input_dir: Path, output_dir: Path, ref_dir: Path,
                          working_dir: Path) -> None:
    import shutil

    import numpy as np
    from scipy.io import loadmat

    from clinica.pipelines.statistics_surface.statistics_surface_pipeline import (
        StatisticsSurface, )

    caps_dir = output_dir / "caps"
    tsv = input_dir / "subjects.tsv"

    # Copy necessary data from in to out
    shutil.copytree(input_dir / "caps", caps_dir, copy_function=shutil.copy)

    parameters = {
        # Clinica compulsory parameters
        "group_label": "UnitTest",
        "orig_input_data": "t1-freesurfer",
        "glm_type": "group_comparison",
        "contrast": "group",
        # Optional parameters
        "covariates": ["age", "sex"],
    }
    pipeline = StatisticsSurface(
        caps_directory=fspath(caps_dir),
        tsv_file=fspath(tsv),
        base_dir=fspath(working_dir),
        parameters=parameters,
    )
    pipeline.build()
    pipeline.run(plugin="MultiProc",
                 plugin_args={"n_procs": 1},
                 bypass_check=True)

    # Check files
    filename = "group-UnitTest_AD-lt-CN_measure-ct_fwhm-20_correctedPValue.mat"
    out_file = (caps_dir / "groups" / "group-UnitTest" / "statistics" /
                "surfstat_group_comparison" / filename)
    ref_file = ref_dir / filename

    out_file_mat = loadmat(fspath(out_file))["correctedpvaluesstruct"]
    ref_file_mat = loadmat(fspath(ref_file))["correctedpvaluesstruct"]
    for i in range(4):
        assert np.allclose(
            out_file_mat[0][0][i],
            ref_file_mat[0][0][i],
            rtol=1e-8,
            equal_nan=True,
        )
Example #6
0
def test_run_StatisticsSurface(cmdopt):
    from clinica.pipelines.statistics_surface.statistics_surface_pipeline import StatisticsSurface
    from os.path import dirname, join, abspath
    import shutil
    import numpy as np
    from scipy.io import loadmat

    working_dir = cmdopt
    root = dirname(abspath(join(abspath(__file__), pardir)))
    root = join(root, 'data', 'StatisticsSurface')

    clean_folder(join(root, 'out', 'caps'), recreate=False)
    clean_folder(join(working_dir, 'StatisticsSurface'))
    shutil.copytree(join(root, 'in', 'caps'), join(root, 'out', 'caps'))

    parameters = {
        # Clinica compulsory parameters
        'group_label': 'UnitTest',
        'orig_input_data': 't1-freesurfer',
        'glm_type': 'group_comparison',
        'contrast': 'group',
        # Optional parameters
        'covariates': 'age sex',
    }
    pipeline = StatisticsSurface(caps_directory=join(root, 'out', 'caps'),
                                 tsv_file=join(root, 'in', 'subjects.tsv'),
                                 base_dir=join(working_dir,
                                               'StatisticsSurface'),
                                 parameters=parameters)
    pipeline.build()
    pipeline.run(plugin='MultiProc',
                 plugin_args={'n_procs': 1},
                 bypass_check=True)

    # Check files
    filename = 'group-UnitTest_AD-lt-CN_measure-ct_fwhm-20_correctedPValue.mat'
    out_file = join(root, 'out', 'caps', 'groups', 'group-UnitTest',
                    'statistics', 'surfstat_group_comparison', filename)
    ref_file = join(root, 'ref', filename)

    out_file_mat = loadmat(out_file)['correctedpvaluesstruct']
    ref_file_mat = loadmat(ref_file)['correctedpvaluesstruct']
    for i in range(4):
        assert np.allclose(out_file_mat[0][0][i],
                           ref_file_mat[0][0][i],
                           rtol=1e-8,
                           equal_nan=True)
    clean_folder(join(root, 'out', 'caps'), recreate=False)
    clean_folder(join(working_dir, 'StatisticsSurface'), recreate=False)
def test_instantiate_StatisticsSurface():
    from os.path import dirname, join, abspath
    from clinica.pipelines.statistics_surface.statistics_surface_pipeline import StatisticsSurface

    root = dirname(abspath(join(abspath(__file__), pardir)))
    root = join(root, 'data', 'StatisticsSurface')

    parameters = {
        # Clinica compulsory parameters
        'group_label': 'UnitTest',
        'orig_input_data': 't1-freesurfer',
        'glm_type': 'group_comparison',
        'contrast': 'group',
        # Optional parameters
        'covariates': 'age sex',
    }
    pipeline = StatisticsSurface(caps_directory=join(root, 'in', 'caps'),
                                 tsv_file=join(root, 'in', 'subjects.tsv'),
                                 parameters=parameters)

    pipeline.build()
Example #8
0
def test_instantiate_StatisticsSurface(cmdopt):

    from clinica.pipelines.statistics_surface.statistics_surface_pipeline import (
        StatisticsSurface, )

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

    parameters = {
        # Clinica compulsory parameters
        "group_label": "UnitTest",
        "orig_input_data": "t1-freesurfer",
        "glm_type": "group_comparison",
        "contrast": "group",
        # Optional parameters
        "covariates": "age sex",
    }
    pipeline = StatisticsSurface(
        caps_directory=fspath(root / "in" / "caps"),
        tsv_file=fspath(root / "in" / "subjects.tsv"),
        parameters=parameters,
    )

    pipeline.build()