Ejemplo n.º 1
0
def test__add_to_entrypoint():
    cmd = "export FOO=bar"
    truth = "sed -i '$i{}' $ND_ENTRYPOINT".format(cmd)
    out = DF._add_to_entrypoint(cmd, with_run=False)
    assert truth in out and "RUN" not in out
    out = DF._add_to_entrypoint(cmd, with_run=True)
    assert truth in out and "RUN" in out
Ejemplo n.º 2
0
    def install_spm(self):
        """Return Dockerfile instructions to install standalone SPM."""
        from neurodocker.dockerfile import _add_to_entrypoint

        url = self._get_spm_url()

        mcr_path = posixpath.join(SPM.MCR_DEST,
                                  SPM.MCR_VERSIONS[str(self.matlab_version)],
                                  '')

        spm_cmd = '/opt/spm{0}/run_spm{0}.sh {1}'.format(self.version, mcr_path)
        spmmcrcmd = 'export SPMMCRCMD="{} script"'.format(spm_cmd)
        entrypoint_cmd = _add_to_entrypoint(spmmcrcmd, with_run=False)

        comment = "# Install standalone SPM"
        cmd = ('echo "Downloading standalone SPM ..."'
               "\n&& curl -sSL -o spm.zip {url}"
               "\n&& unzip -q spm.zip -d /opt"
               "\n&& chmod -R 777 /opt/spm*"
               "\n&& rm -rf spm.zip"
               "\n&& {spm_cmd} quit"
               "\n&& {entrypoint_cmd}"
               "".format(url=url, spm_cmd=spm_cmd,
                         entrypoint_cmd=entrypoint_cmd))
        cmd = indent("RUN", cmd)

        env_cmd = self._get_spm_env_cmd(mcr_path, spm_cmd)

        return '\n'.join((comment, cmd, env_cmd))
Ejemplo n.º 3
0
    def install_binaries(self, url):
        """Return Dockerfile instructions to install FSL using binaries hosted
        on FSL's website.
        """
        from neurodocker.dockerfile import _add_to_entrypoint

        cmd = self._install_binaries_deps()
        cmd += ('\n&& echo "Downloading FSL ..."'
                '\n&& curl -sSL {}'
                '\n| tar zx -C /opt'.format(url))

        if self.version >= LooseVersion('5.0.10'):
            fsl_python = "/opt/fsl/etc/fslconf/fslpython_install.sh"
            cmd += "\n&& /bin/bash {} -q -f /opt/fsl".format(fsl_python)

        ent_cmds = [
            "echo Some packages in this Docker container are non-free",
            ("echo If you are considering commercial use of this"
             " container, please consult the relevant license:"),
            "echo https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/Licence",
            "source $FSLDIR/etc/fslconf/fsl.sh",
        ]
        cmd += "\n&& {}".format(_add_to_entrypoint(ent_cmds, with_run=False))
        cmd = indent("RUN", cmd)

        env_cmd = ("FSLDIR=/opt/fsl" "\nPATH=/opt/fsl/bin:$PATH")
        env_cmd = indent("ENV", env_cmd)

        return "\n".join((cmd, env_cmd))
Ejemplo n.º 4
0
    def install_binaries(self):
        """Return command to download and install FreeSurfer binaries."""
        from neurodocker.dockerfile import _add_to_entrypoint

        url = self._get_binaries_url()

        if self.check_urls and self.version == 'dev':
            raise ValueError(
                "check_urls=True and version='dev' cannot be used "
                "together. Set check_urls to False.")
        elif self.check_urls:
            check_url(url)

        # https://github.com/nipy/workshops/blob/master/170327-nipype/docker/Dockerfile.complete#L8-L20
        # TODO: allow users to choose which directories to exclude.
        excluded_dirs = ("--exclude='freesurfer/trctrain'"
                         "\n--exclude='freesurfer/subjects/fsaverage_sym'"
                         "\n--exclude='freesurfer/subjects/fsaverage3'"
                         "\n--exclude='freesurfer/subjects/fsaverage4'"
                         "\n--exclude='freesurfer/subjects/fsaverage5'"
                         "\n--exclude='freesurfer/subjects/fsaverage6'"
                         "\n--exclude='freesurfer/subjects/cvs_avg35'"
                         "\n--exclude='freesurfer/subjects/cvs_avg35_inMNI152'"
                         "\n--exclude='freesurfer/subjects/bert'"
                         "\n--exclude='freesurfer/subjects/V1_average'"
                         "\n--exclude='freesurfer/average/mult-comp-cor'"
                         "\n--exclude='freesurfer/lib/cuda'"
                         "\n--exclude='freesurfer/lib/qt'")

        cmd = self._install_binaries_deps()
        ent = _add_to_entrypoint("source $FREESURFER_HOME/SetUpFreeSurfer.sh",
                                 with_run=False)
        cmd += ('\n&& echo "Downloading FreeSurfer ..."'
                "\n&& curl -sSL --retry 5 {url}"
                "\n| tar xz -C /opt\n{excluded}"
                "\n&& {entrypoint_cmd}"
                "".format(url=url, excluded=excluded_dirs, entrypoint_cmd=ent))
        cmd = indent("RUN", cmd)

        env_cmd = "ENV FREESURFER_HOME=/opt/freesurfer"

        return "\n".join((cmd, env_cmd))
Ejemplo n.º 5
0
    def add_min_recon_all(self):
        """Return Dockerfile instructions to install minimized version of
        recon-all.

        See https://github.com/freesurfer/freesurfer/issues/70 for more
        information.
        """
        from neurodocker.dockerfile import _add_to_entrypoint

        cmd = self._install_binaries_deps()
        url = ("https://dl.dropbox.com/s/nnzcfttc41qvt31/"
               "recon-all-freesurfer6-3.min.tgz")
        ent = _add_to_entrypoint("source $FREESURFER_HOME/SetUpFreeSurfer.sh",
                                 with_run=False)
        cmd += ('\n&& echo "Downloading minimized FreeSurfer ..."'
                "\n&& curl -sSL {} | tar xz -C /opt"
                "\n&& {entrypoint_cmd}"
                "".format(url, entrypoint_cmd=ent))
        cmd = indent("RUN", cmd)

        env_cmd = "ENV FREESURFER_HOME=/opt/freesurfer"
        return "\n".join((cmd, env_cmd))
Ejemplo n.º 6
0
    def install_binaries(self):
        """Return Dockerfile instructions to download and install MINC
        binaries.
        """
        from neurodocker.dockerfile import _add_to_entrypoint
        minc_url = self._get_binaries_urls(self.version)
        beast_url = self.BEAST_URL['1.1']
        models_09a_url = self.MODELS_URL['09a']
        models_09c_url = self.MODELS_URL['09c']
        if self.check_urls:
            check_url(minc_url)
            check_url(beast_url)
            check_url(models_09a_url)
            check_url(models_09c_url)

        cmd = self._install_binaries_deps()
        ent = _add_to_entrypoint("source /opt/minc/minc-toolkit-config.sh",
                                 with_run=False)
        cmd += self._get_install_cmd(minc_url, beast_url, models_09a_url,
                                     models_09c_url, ent)
        cmd = indent("RUN", cmd)
        return cmd