Beispiel #1
0
def check_fsl(version_requirements=None):
    """Check FSL software."""
    import nipype.interfaces.fsl as fsl
    from colorama import Fore

    from clinica.utils.exceptions import ClinicaMissingDependencyError
    from clinica.utils.stream import cprint

    check_environment_variable("FSLDIR", "FSL")

    try:
        if fsl.Info.version().split(".") < ["5", "0", "5"]:
            raise ClinicaMissingDependencyError(
                f"{Fore.RED}FSL version must be greater than 5.0.5{Fore.RESET}"
            )
    except Exception as e:
        cprint(str(e))

    list_binaries = ["bet", "flirt", "fast", "first"]
    for binary in list_binaries:
        if not is_binary_present(binary):
            raise ClinicaMissingDependencyError(
                f"{Fore.RED}\n[Error] Clinica could not find FSL software: "
                f"the {binary} command is not present in your PATH environment.{Fore.RESET}"
            )
Beispiel #2
0
def check_environment_variable(environment_variable, software_name):
    import os

    content_var = os.environ.get(environment_variable, "")
    if not content_var:
        raise ClinicaMissingDependencyError(
            f"Clinica could not find {software_name} software: "
            f"the {environment_variable} variable is not set.")
    if not os.path.isdir(content_var):
        raise ClinicaMissingDependencyError(
            f"The {environment_variable} environment variable "
            f"you gave is not a folder (content: {content_var}).")
    return content_var
Beispiel #3
0
def check_environment_variable(environment_variable, software_name):
    import os
    from colorama import Fore
    from .exceptions import ClinicaMissingDependencyError

    content_var = os.environ.get(environment_variable, '')
    if not content_var:
        raise ClinicaMissingDependencyError(
            '%s\n[Error] Clinica could not find %s software: the %s variable is not set.%s'
            % (Fore.RED, software_name, environment_variable, Fore.RESET))
    if not os.path.isdir(content_var):
        raise ClinicaMissingDependencyError(
            '%s\n[Error] The %s environment variable you gave is not a folder (content: %s).%s'
            % (Fore.RED, environment_variable, content_var, Fore.RESET))
    return content_var
Beispiel #4
0
def check_petpvc(version_requirements=None):
    """Check PETPVC software."""
    from colorama import Fore

    from clinica.utils.exceptions import ClinicaMissingDependencyError

    list_binaries = [
        "petpvc",
        "pvc_diy",
        "pvc_gtm",
        "pvc_iy",
        "pvc_labbe",
        "pvc_make4d",
        "pvc_mg",
        "pvc_mtc",
        "pvc_rbv",
        "pvc_relabel",
        "pvc_rl",
        "pvc_simulate",
        "pvc_stc",
        "pvc_vc",
    ]
    for binary in list_binaries:
        if not is_binary_present(binary):
            raise ClinicaMissingDependencyError(
                f"{Fore.RED}\n[Error] Clinica could not find PETPVC software: the "
                f"{binary} command is not present in your PATH environment.{Fore.RESET}"
            )
Beispiel #5
0
def check_dcm2niix():
    """Check dcm2niix software."""
    if not is_binary_present("dcm2niix"):
        raise ClinicaMissingDependencyError(
            "Clinica could not find dcm2niix software in your PATH environment: "
            "this can be downloaded or installed from https://github.com/rordenlab/dcm2niix."
        )
Beispiel #6
0
def check_convert3d(version_requirements=None):
    """Check Convert3D software."""
    list_binaries = ["c3d_affine_tool", "c3d"]
    for binary in list_binaries:
        if not is_binary_present(binary):
            raise ClinicaMissingDependencyError(
                f"[Error] Clinica could not find Convert3D software: "
                f"the {binary} command is not present in your PATH environment."
            )
Beispiel #7
0
def check_matlab():
    """Check Matlab toolbox."""
    from colorama import Fore
    from clinica.utils.exceptions import ClinicaMissingDependencyError

    if not is_binary_present("matlab"):
        raise ClinicaMissingDependencyError(
            '%sMatlab was not found in PATH environment. Did you add it?%s' %
            (Fore.RED, Fore.RESET))
Beispiel #8
0
def check_environment_variable(environment_variable, software_name):
    import os

    from colorama import Fore

    from .exceptions import ClinicaMissingDependencyError

    content_var = os.environ.get(environment_variable, "")
    if not content_var:
        raise ClinicaMissingDependencyError(
            f"{Fore.RED}\n[Error] Clinica could not find {software_name} software: "
            f"the {environment_variable} variable is not set.{Fore.RESET}"
        )
    if not os.path.isdir(content_var):
        raise ClinicaMissingDependencyError(
            f"{Fore.RED}\n[Error] The {environment_variable} environment variable "
            f"you gave is not a folder (content: {content_var}).{Fore.RESET}"
        )
    return content_var
Beispiel #9
0
def check_dcm2niix():
    """Check dcm2niix software."""
    from colorama import Fore
    from clinica.utils.exceptions import ClinicaMissingDependencyError

    if not is_binary_present('dcm2niix'):
        raise ClinicaMissingDependencyError(
            '%s\n[Error] Clinica could not find dcm2niix software in your PATH environment: '
            'this can be downloaded or installed from https://github.com/rordenlab/dcm2niix.%s' %
            (Fore.RED, Fore.RESET))
Beispiel #10
0
def check_dcm2nii():
    """Check dcm2nii software."""
    from colorama import Fore
    from clinica.utils.exceptions import ClinicaMissingDependencyError

    if not is_binary_present('dcm2nii'):
        raise ClinicaMissingDependencyError(
            '%s\n[Error] Clinica could not find dcm2nii tool from MRIcron in your PATH environment: '
            'this can be downloaded from https://www.nitrc.org/frs/?group_id=152 (choose the 2016 version).%s' %
            (Fore.RED, Fore.RESET))
Beispiel #11
0
def check_ants(version_requirements=None):
    """Check ANTs software."""
    check_environment_variable("ANTSPATH", "ANTs")

    list_binaries = ["N4BiasFieldCorrection", "antsRegistrationSyNQuick.sh"]
    for binary in list_binaries:
        if not is_binary_present(binary):
            raise ClinicaMissingDependencyError(
                "Clinica could not find ANTs software: "
                f"the {binary} command is not present in your PATH environment."
            )
    def check_custom_dependencies(self):
        """Check dependencies that can not be listed in the `info.json` file."""
        from clinica.utils.check_dependency import is_binary_present
        from clinica.utils.exceptions import ClinicaMissingDependencyError

        if self.parameters["use_cuda"]:
            if not is_binary_present("eddy_cuda"):
                raise ClinicaMissingDependencyError(
                    "[Error] FSL eddy with CUDA was set but Clinica could not find eddy_cuda in your PATH environment. "
                    "Check that  https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/eddy/UsersGuide#The_eddy_executables is correctly set."
                )
Beispiel #13
0
def check_petpvc(version_requirements=None):
    """Check PETPVC software."""
    from colorama import Fore
    from clinica.utils.exceptions import ClinicaMissingDependencyError

    list_binaries = ['petpvc', 'pvc_diy', 'pvc_gtm', 'pvc_iy', 'pvc_labbe', 'pvc_make4d', 'pvc_mg',
                     'pvc_mtc', 'pvc_rbv', 'pvc_relabel', 'pvc_rl', 'pvc_simulate', 'pvc_stc', 'pvc_vc']
    for binary in list_binaries:
        if not is_binary_present(binary):
            raise ClinicaMissingDependencyError(
                '%s\n[Error] Clinica could not find PETPVC software: the %s command is not present in your '
                'PATH environment.%s' % (Fore.RED, binary, Fore.RESET))
Beispiel #14
0
def check_freesurfer(version_requirements=None):
    """Check FreeSurfer software."""
    check_environment_variable("FREESURFER_HOME", "FreeSurfer")

    list_binaries = ["mri_convert", "recon-all"]
    for binary in list_binaries:
        if not is_binary_present(binary):
            raise ClinicaMissingDependencyError(
                "Clinica could not find FreeSurfer software: "
                f"the {binary} command is not present in your PATH environment: "
                "did you have the line `source $FREESURFER_HOME/SetUpFreeSurfer.sh` "
                "in your configuration file?")
Beispiel #15
0
def check_mrtrix(version_requirements=None):
    """Check MRtrix software."""
    from clinica.utils.exceptions import ClinicaMissingDependencyError

    list_binaries = [
        "transformconvert", "mrtransform", "dwi2response", "tckgen"
    ]
    for binary in list_binaries:
        if not is_binary_present(binary):
            raise ClinicaMissingDependencyError(
                f"Clinica could not find MRtrix software: "
                f"the {binary} command is not present in your PATH environment."
            )
Beispiel #16
0
def check_mrtrix(version_requirements=None):
    """Check MRtrix software."""
    from colorama import Fore
    from clinica.utils.exceptions import ClinicaMissingDependencyError

    check_environment_variable('MRTRIX_HOME', 'MRtrix')

    list_binaries = ['transformconvert', 'mrtransform', 'dwi2response', 'tckgen']
    for binary in list_binaries:
        if not is_binary_present(binary):
            raise ClinicaMissingDependencyError(
                '%s\n[Error] Clinica could not find MRtrix software: the %s command is not present in your '
                'PATH environment.%s' % (Fore.RED, binary, Fore.RESET))
Beispiel #17
0
def check_ants(version_requirements=None):
    """Check ANTs software."""
    from colorama import Fore
    from clinica.utils.exceptions import ClinicaMissingDependencyError

    check_environment_variable('ANTSPATH', 'ANTs')

    list_binaries = ['N4BiasFieldCorrection', 'antsRegistrationSyNQuick.sh']
    for binary in list_binaries:
        if not is_binary_present(binary):
            raise ClinicaMissingDependencyError(
                '%s\n[Error] Clinica could not find ANTs software: the %s command is not present '
                'in your PATH environment.%s' % (Fore.RED, binary, Fore.RESET))
Beispiel #18
0
def check_fsl(version_requirements=None):
    """Check FSL software."""
    import nipype.interfaces.fsl as fsl
    from colorama import Fore
    from clinica.utils.exceptions import ClinicaMissingDependencyError
    from clinica.utils.stream import cprint

    check_environment_variable('FSLDIR', 'FSL')

    try:
        if fsl.Info.version().split(".") < ['5', '0', '5']:
            raise ClinicaMissingDependencyError(
                '%sFSL version must be greater than 5.0.5%s' %
                (Fore.RED, Fore.RESET))
    except Exception as e:
        cprint(str(e))

    list_binaries = ['bet', 'flirt', 'fast', 'first']
    for binary in list_binaries:
        if not is_binary_present(binary):
            raise ClinicaMissingDependencyError(
                '%s\n[Error] Clinica could not find FSL software: the %s command is not present in your '
                'PATH environment.%s' % (Fore.RED, binary, Fore.RESET))
Beispiel #19
0
def check_freesurfer(version_requirements=None):
    """Check FreeSurfer software."""
    from colorama import Fore
    import nipype.interfaces.freesurfer as freesurfer
    from clinica.utils.exceptions import ClinicaMissingDependencyError

    check_environment_variable('FREESURFER_HOME', 'FreeSurfer')

    list_binaries = ['mri_convert', 'recon-all']
    for binary in list_binaries:
        if not is_binary_present(binary):
            raise ClinicaMissingDependencyError(
                '%s\n[Error] Clinica could not find FreeSurfer software: the %s command is not present in your PATH '
                'environment: did you have the line source ${FREESURFER_HOME}/'
                'SetUpFreeSurfer.sh in your configuration file?%s' % (Fore.RED, binary, Fore.RESET))
Beispiel #20
0
def check_mrtrix(version_requirements=None):
    """Check MRtrix software."""
    from colorama import Fore

    from clinica.utils.exceptions import ClinicaMissingDependencyError

    check_environment_variable("MRTRIX_HOME", "MRtrix")

    list_binaries = ["transformconvert", "mrtransform", "dwi2response", "tckgen"]
    for binary in list_binaries:
        if not is_binary_present(binary):
            raise ClinicaMissingDependencyError(
                f"{Fore.RED}\n[Error] Clinica could not find MRtrix software: "
                f"the {binary} command is not present in your PATH environment.{Fore.RESET}"
            )
Beispiel #21
0
def check_ants(version_requirements=None):
    """Check ANTs software."""
    from colorama import Fore

    from clinica.utils.exceptions import ClinicaMissingDependencyError

    check_environment_variable("ANTSPATH", "ANTs")

    list_binaries = ["N4BiasFieldCorrection", "antsRegistrationSyNQuick.sh"]
    for binary in list_binaries:
        if not is_binary_present(binary):
            raise ClinicaMissingDependencyError(
                f"{Fore.RED}\n[Error] Clinica could not find ANTs software: "
                f"the {binary} command is not present in your PATH environment.{Fore.RESET}"
            )
Beispiel #22
0
def check_software_requirements(current_version, version_requirements, software_name):
    from distutils.version import LooseVersion
    from string import punctuation
    from colorama import Fore
    from clinica.utils.exceptions import ClinicaMissingDependencyError

    comparison_operator = ''.join([c for c in version_requirements if c in punctuation.replace('.', '')])
    required_version = version_requirements.replace(comparison_operator, '')

    satisfy_version = eval('LooseVersion(\'%s\') %s LooseVersion(\'%s\')' %
                           (current_version, comparison_operator, required_version))

    if not satisfy_version:
        raise ClinicaMissingDependencyError(
            '%s\n[Error] Your %s version (%s) does not version requirements (%s).%s' %
            (Fore.RED, software_name, current_version, version_requirements, Fore.RESET))
Beispiel #23
0
def check_software_requirements(current_version, version_requirements,
                                software_name):
    from string import punctuation

    comparison_operator = "".join(
        [c for c in version_requirements if c in punctuation.replace(".", "")])
    required_version = version_requirements.replace(comparison_operator, "")

    satisfy_version = eval(
        f"LooseVersion('{current_version}') {comparison_operator} LooseVersion('{required_version}')"
    )

    if not satisfy_version:
        raise ClinicaMissingDependencyError(
            f"Your {software_name} version ({current_version}) "
            f"does not satisfy version requirements ({version_requirements}).")
Beispiel #24
0
def check_cat12():
    """
    Check installation of CAT12 (mostly used to provide atlases)
    """
    import os
    from colorama import Fore
    from .exceptions import ClinicaMissingDependencyError
    from .spm import check_spm_home

    spm_home = check_spm_home()

    cat12 = os.path.join(spm_home, 'toolbox', 'cat12')
    if not os.path.exists(cat12):
        raise ClinicaMissingDependencyError(
            '%s\n[Error] CAT12 is not installed in your SPM folder. It should be in %s.%s'
            % (Fore.RED, cat12, Fore.RESET))
    return cat12
Beispiel #25
0
def check_freesurfer(version_requirements=None):
    """Check FreeSurfer software."""
    import nipype.interfaces.freesurfer as freesurfer
    from colorama import Fore

    from clinica.utils.exceptions import ClinicaMissingDependencyError

    check_environment_variable("FREESURFER_HOME", "FreeSurfer")

    list_binaries = ["mri_convert", "recon-all"]
    for binary in list_binaries:
        if not is_binary_present(binary):
            raise ClinicaMissingDependencyError(
                f"{Fore.RED}\n[Error] Clinica could not find FreeSurfer software: "
                f"the {binary} command is not present in your PATH environment: "
                f"did you have the line source ${{FREESURFER_HOME}}/SetUpFreeSurfer.sh "
                f"in your configuration file?{Fore.RESET}"
            )
Beispiel #26
0
def check_software_requirements(current_version, version_requirements, software_name):
    from string import punctuation

    from colorama import Fore

    from clinica.utils.exceptions import ClinicaMissingDependencyError

    comparison_operator = "".join(
        [c for c in version_requirements if c in punctuation.replace(".", "")]
    )
    required_version = version_requirements.replace(comparison_operator, "")

    satisfy_version = eval(
        f"LooseVersion('{current_version}') {comparison_operator} LooseVersion('{required_version}')"
    )

    if not satisfy_version:
        raise ClinicaMissingDependencyError(
            f"{Fore.RED}\n[Error] Your {software_name} version ({current_version}) "
            f"does not satisfy version requirements ({version_requirements}).{Fore.RESET}"
        )
Beispiel #27
0
    def run_command(self, args):
        from os.path import exists
        from os import makedirs
        from colorama import Fore
        from clinica.iotools.converters.aibl_to_bids.aibl_to_bids import convert_clinical_data, convert_images
        from clinica.utils.check_dependency import is_binary_present, check_freesurfer
        from clinica.utils.exceptions import ClinicaMissingDependencyError

        list_binaries = ['dcm2niix', 'dcm2nii']
        for binary in list_binaries:
            if not is_binary_present(binary):
                raise ClinicaMissingDependencyError(
                    '%s\n[Error] Clinica could not find %s software: it is not present in your '
                    'PATH environment.%s' % (Fore.RED, binary, Fore.RESET))
        check_freesurfer()

        if not exists(args.bids_directory):
            makedirs(args.bids_directory)

        convert_images(args.dataset_directory, args.clinical_data_directory,
                       args.bids_directory)
        convert_clinical_data(args.bids_directory,
                              args.clinical_data_directory)
Beispiel #28
0
def check_petpvc(version_requirements=None):
    """Check PETPVC software."""
    list_binaries = [
        "petpvc",
        "pvc_diy",
        "pvc_gtm",
        "pvc_iy",
        "pvc_labbe",
        "pvc_make4d",
        "pvc_mg",
        "pvc_mtc",
        "pvc_rbv",
        "pvc_relabel",
        "pvc_rl",
        "pvc_simulate",
        "pvc_stc",
        "pvc_vc",
    ]
    for binary in list_binaries:
        if not is_binary_present(binary):
            raise ClinicaMissingDependencyError(
                "Clinica could not find PETPVC software: "
                f"the {binary} command is not present in your PATH environment."
            )
Beispiel #29
0
def check_matlab():
    """Check Matlab toolbox."""
    if not is_binary_present("matlab"):
        raise ClinicaMissingDependencyError(
            "Matlab was not found in PATH environment. Did you add it?")