def xfm_atlas_to_functional(atlas_filepath, anatbrain_filepath, meanfunc_filepath,<EOL>atlas2anat_nonlin_xfm_filepath, is_atlas2anat_inverted,<EOL>anat2func_lin_xfm_filepath,<EOL>atlasinanat_out_filepath, atlasinfunc_out_filepath,<EOL>interp='<STR_LIT>', rewrite=True, parallel=False):
if is_atlas2anat_inverted:<EOL><INDENT>anat_to_mni_nl_inv = atlas2anat_nonlin_xfm_filepath<EOL><DEDENT>else:<EOL><INDENT>output_dir         = op.abspath   (op.dirname(atlasinanat_out_filepath))<EOL>ext                = get_extension(atlas2anat_nonlin_xfm_filepath)<EOL>anat_to_mni_nl_inv = op.join(output_dir, remove_ext(op.basename(atlas2anat_nonlin_xfm_filepath)) + '<STR_LIT>' + ext)<EOL><DEDENT>invwarp_cmd   = op.join('<STR_LIT>', '<STR_LIT>', '<STR_LIT>')<EOL>applywarp_cmd = op.join('<STR_LIT>', '<STR_LIT>', '<STR_LIT>')<EOL>fslsub_cmd    = op.join('<STR_LIT>', '<STR_LIT>', '<STR_LIT>')<EOL>if parallel:<EOL><INDENT>invwarp_cmd   = fslsub_cmd + '<STR_LIT:U+0020>' + invwarp_cmd<EOL>applywarp_cmd = fslsub_cmd + '<STR_LIT:U+0020>' + applywarp_cmd<EOL><DEDENT>if rewrite or (not is_atlas2anat_inverted and not op.exists(anat_to_mni_nl_inv)):<EOL><INDENT>log.debug('<STR_LIT>'.format(anat_to_mni_nl_inv))<EOL>cmd  = invwarp_cmd + '<STR_LIT:U+0020>'<EOL>cmd += '<STR_LIT>'.format(atlas2anat_nonlin_xfm_filepath)<EOL>cmd += '<STR_LIT>'.format(anat_to_mni_nl_inv)<EOL>cmd += '<STR_LIT>'.format(anatbrain_filepath)<EOL>log.debug('<STR_LIT>'.format(cmd))<EOL>check_call(cmd)<EOL><DEDENT>if rewrite or not op.exists(atlasinanat_out_filepath):<EOL><INDENT>log.debug('<STR_LIT>'.format(atlasinanat_out_filepath))<EOL>cmd  = applywarp_cmd + '<STR_LIT:U+0020>'<EOL>cmd += '<STR_LIT>'.format(atlas_filepath)<EOL>cmd += '<STR_LIT>'.format(anatbrain_filepath)<EOL>cmd += '<STR_LIT>'.format(anat_to_mni_nl_inv)<EOL>cmd += '<STR_LIT>'.format(interp)<EOL>cmd += '<STR_LIT>'.format(atlasinanat_out_filepath)<EOL>log.debug('<STR_LIT>'.format(cmd))<EOL>check_call(cmd)<EOL><DEDENT>if rewrite or not op.exists(atlasinfunc_out_filepath):<EOL><INDENT>log.debug('<STR_LIT>'.format(atlasinfunc_out_filepath))<EOL>cmd  = applywarp_cmd + '<STR_LIT:U+0020>'<EOL>cmd += '<STR_LIT>'.format(atlasinanat_out_filepath)<EOL>cmd += '<STR_LIT>'.format(meanfunc_filepath)<EOL>cmd += '<STR_LIT>'.format(anat2func_lin_xfm_filepath)<EOL>cmd += '<STR_LIT>'.format(interp)<EOL>cmd += '<STR_LIT>'.format(atlasinfunc_out_filepath)<EOL>log.debug('<STR_LIT>'.format(cmd))<EOL>check_call(cmd)<EOL><DEDENT>
Call FSL tools to apply transformations to a given atlas to a functional image.
    Given the transformation matrices.

    Parameters
    ----------
    atlas_filepath: str
        Path to the 3D atlas volume file.

    anatbrain_filepath: str
        Path to the anatomical brain volume file (skull-stripped and registered to the same space as the atlas,
        e.g., MNI).

    meanfunc_filepath: str
        Path to the average functional image to be used as reference in the last applywarp step.

    atlas2anat_nonlin_xfm_filepath: str
        Path to the atlas to anatomical brain linear transformation .mat file.
        If you have the inverse transformation, i.e., anatomical brain to atlas, set is_atlas2anat_inverted to True.

    is_atlas2anat_inverted: bool
        If False will have to calculate the inverse atlas2anat transformation to apply the transformations.
        This step will be performed with FSL invwarp.

    anat2func_lin_xfm_filepath: str
        Path to the anatomical to functional .mat linear transformation file.

    atlasinanat_out_filepath: str
        Path to output file which will contain the 3D atlas in the subject anatomical space.

    atlasinfunc_out_filepath: str
        Path to output file which will contain the 3D atlas in the subject functional space.

    verbose: bool
        If verbose will show DEBUG log info.

    rewrite: bool
        If True will re-run all the commands overwriting any existing file. Otherwise will check if
        each file exists and if it does won't run the command.

    parallel: bool
        If True will launch the commands using ${FSLDIR}/fsl_sub to use the cluster infrastructure you have setup
        with FSL (SGE or HTCondor).