Questions about adding a custom standard template

I am using fmriprep1.4.0 and trying to use a pediatric template for my toddler data preprocessing. The --output-spaces option allows for providing paths to custom templates that follow TemplateFlow’s naming conventions (e.g., /path/to/custom/templates/tpl-MyCustom:res-2). As I understand, the template should be in BIDS format with a corresponding .json file. However, the toddler template I am using is in NIFTI format already (http://nist.mni.mcgill.ca/?p=1005). Is there a way to convert it to BIDS format and generate .json file simultaneously? If I provide the path to the template in --output-spaces option, would this template be used throughout the preprocessing? What would be the voxel size of preprocessed images? Would it be the same as the voxel size of the template?

Thank you very much.

2 Likes

Hi @Yaqiong,

We are trying to add that particular template to TemplateFlow (and hence, fMRIPrep). At this point, fMRIPrep can’t read custom templates (everything is in place to allow it, but we still need a little bit of coding).

Since reading the template to provide it as custom and adding it to TemplateFlow would be equivalent, would you like to add it directly to TemplateFlow?

Hi @oesteban, thanks for your response. Glad to know this function is almost there. I am not quite sure how to add it directly to TemplateFlow, if I have the template folder (in a similar format as one here: https://github.com/templateflow/templateflow). Could you walk me through it? Thank you.

I think the bottleneck is just organizing the files and writing the metadata. Once that is done, it is fairly easy for me to upload the template.

Great. I am also working on a cohort of child fMRI data and hoping to use an age-matched pediatric template (http://www.bic.mni.mcgill.ca/ServicesAtlases/NIHPD-obj1; 7.5-13.5 years) or Haskins pediatric template (7-12 years) in AFNI. Could you please also upload these two templates to the TemplateFlow? It would be great if you can keep me updated when these templates are ready to use.

Thank you.

Hi @oesteban, just wanted to follow up on the topic of adding the pediatric templates to TemplateFlow. Are there any updates?
Thank you.

Hi @Yaqiong,

Could you try the new pediatric templates of TemplateFlow? We are testing this new feature on fMRIPrep version 1.4.1rc2

In principle, it should be as easy as adding the following arguments:

--skull-strip-template MNIInfant:cohort-3 --output-spaces MNIInfant:cohort-3:res-2 <other-spaces>

Please replace MNIInfant with MNIPediatricAsym if those fit better your age range (MNIInfant is 0-4.5yr and MNIPediatricAsym goes from 4.5yo through 18yo).

Please replace cohort-3 with the age range that better approximates your application (MNIInfant, MNIPediatricAsym)

Hi @oesteban,

Thank you very much for the updates. I have tried the new pediatric template of Template Flow using the command that you provided but ran into some errors (see below). I have several questions regarding the errors. First, I have specified output --output-spaces MNIInfant:cohort-9:res-2, but why did it download tpl-MNIInfant_cohort-9_res-1_T1w.nii.gz instead? Second, for Freesurfer, how can I specify the output space (default fsaverage5")? Third, how to add the output space for --use-aroma? It is not using the one I specified but using “MNI152NLin6Asym:res-2” instead. Thanks.

The whole command I am using is as following:
singularity run
–cleanenv
–home /scratch/YX_data_analysis:/asd/apps/software
/asd/apps/software/fmriprep_1.4.1rc2.sif
/asd/apps/software/Converted_BIDs /asd/apps/software/RESTvsTASK participant
–participant-label ${subj}
–skull-strip-template MNIInfant:cohort-9 --output-spaces MNIInfant:cohort-9:res-2
–use-aroma --output-spaces MNIInfant:cohort-9:res-2
–nthreads 6 --n_cpus 12 --omp-nthreads 12
–mem-mb 16000
–skip_bids_validation
–fs-license-file /asd/apps/software/license.txt I have several questions for that

Error report:
Although --fs-no-reconall was not set (i.e., FreeSurfer is to be run), no FreeSurfer output space (valid values are: fsaverage, fsaverage6, fsnative, fsaverage5) was selected. Adding default “fsaverage5” to the list of output spaces.
Option “–use-aroma” requires functional images to be resampled to MNI152NLin6Asym space. The argument “MNI152NLin6Asym:res-2” has been automatically added to the list of output spaces (option --output-spaces).
190609-07:50:42,606 nipype.workflow IMPORTANT:

Running fMRIPREP version 1.4.1rc2:
  * BIDS dataset path: /asd/apps/software/Converted_BIDs.
  * Participant list: ['AACE54614A'].
  * Run identifier: 20190609-075042_f3cd8a79-11cf-4049-8d45-919c48a89aeb.

Downloading https://templateflow.s3.amazonaws.com/tpl-MNIInfant/cohort-9/tpl-MNIInfant_cohort-9_res-1_T1w.nii.gz
Process Process-2:
Traceback (most recent call last):
File “/usr/local/miniconda/lib/python3.7/multiprocessing/process.py”, line 297, in _bootstrap
self.run()
File “/usr/local/miniconda/lib/python3.7/multiprocessing/process.py”, line 99, in run
self._target(*self._args, **self._kwargs)
File “/usr/local/miniconda/lib/python3.7/site-packages/fmriprep/cli/run.py”, line 608, in build_workflow
work_dir=str(work_dir),
File “/usr/local/miniconda/lib/python3.7/site-packages/fmriprep/workflows/base.py”, line 259, in init_fmriprep_wf
use_syn=use_syn,
File “/usr/local/miniconda/lib/python3.7/site-packages/fmriprep/workflows/base.py”, line 551, in init_single_subject_wf
skull_strip_template=skull_strip_template,
File “/usr/local/miniconda/lib/python3.7/site-packages/smriprep/workflows/anatomical.py”, line 230, in init_anat_preproc_wf
normalization_quality=‘precise’ if not debug else ‘testing’)
File “/usr/local/miniconda/lib/python3.7/site-packages/niworkflows/anat/ants.py”, line 188, in init_brain_extraction_wf
tpl_target_path = get_template(in_template, **template_spec)
File “/usr/local/miniconda/lib/python3.7/site-packages/templateflow/api.py”, line 39, in get
_s3_get(filepath)
File “/usr/local/miniconda/lib/python3.7/site-packages/templateflow/api.py”, line 139, in _s3_get
with filepath.open(‘wb’) as f:
File “/usr/local/miniconda/lib/python3.7/pathlib.py”, line 1176, in open
opener=self._opener)
File “/usr/local/miniconda/lib/python3.7/pathlib.py”, line 1030, in _opener
return self._accessor.open(self, flags, mode)
OSError: [Errno 30] Read-only file system: ‘/opt/templateflow/tpl-MNIInfant/cohort-9/tpl-MNIInfant_cohort-9_res-1_T1w.nii.gz’

We are currently looking into this and some other related issues ATM. Thanks for your patience.

--output-spaces should understand both volumetric and surface outputs - placing fsnative and/or fsaverageX should work out. Please note the ‘s’ at the end of --output-spaces because the command line still accepts the deprecated --output-space argument.

ICA-AROMA was trained on MNI152NLin6Asym:res-2 and thus, it can only operate correctly on that space. You could maybe discuss with @mmennes et al. whether it makes sense to also train the noisy components on some infant/pediatric template space. If that happened, we would allow swapping the ICA-AROMA template.

We are currently working on this, simultaneously to Q1.

Thanks very much

Hi @oesteban,

Just wanted to check in with you on the progress of those issues. Any updates?
Thank you very much for helping with that.

I’ll address the questions that remain open:

After reflecting on this, the resolution 1 is used for spatial normalization as target. Then res-2 is used as reference during resampling. Therefore that should be the regular behavior.

This should be fixed with version 1.4.1rc4. You may require some tunning of your singularity run command line to make sure templateflow has access to a writable directory. But, if your singularity installation automatically binds $HOME, it should work out of the box.

Hi @oesteban,

Thanks for the updates. I am now running the processing with 1.4.1rc4, and it is working so far. Though, I still have one follow-up question for you.

For Freesurfer, there are several options for the output space, including fsnative, fsaverage,fsaverage6, and fsaverage5. As I understand, fsnative is in the subject’s native space and the others are in MNI space, right? What is the difference between fsaverage6 and fsaverage5? In my case (toddler data), should I use fsnative instead?

Thank you very much.

Those are purely FreeSurfer’s outputs. That means you’ll find documentation about them in their website.

fsaverage, fsaverage6 and fsaverage5 are effectively in FS’ internal flavor of MNI305, after surface alignment to their average template.

The different fsaverage flavors are explained in this thread https://mail.nmr.mgh.harvard.edu/pipermail//freesurfer/2011-May/018571.html. It boils down to the density of sampling the surface.

Unless your study design requires you to work on surfaces, I’d say I would keep the analysis in the volume (and thus, no need for any fsX outputs). But this is not a question of the appropriateness of the outputs, is more about your analysis design.

Dear all,

I was wondering if there was any update about the possibility of adding a custom template to the fmriprep pipeline.

I work with old-subjects populations and would like to use an age-specific template such as the MCALT: https://www.nitrc.org/projects/mcalt/
I have already prepared a folder with the related files in ‘templateflow’ format.

Thank you very much for any input :slight_smile:

1 Like

@agriffa

We have successfully added a custom template. We used the filename conventions for OASIS (https://github.com/templateflow/tpl-OASIS30ANTs) and created the other derived outputs (tissue probability, masks, etc.). Then we placed the template in ~/.cache/templateflow/tpl-CUSTOMNAME and ran fmriprep. The only tricky part was getting things at a lower resolution, for which we just resampled three files of the template to 2mm and called them res-02.

If you are going this route, I suggest you specify exactly where are you stuck. In principle if you create the same files existing in another template you should be fine.

1 Like

Hi there, I am using two different templates (young and old) but they are in .nii.gz format. I understand that to add them to fmriprep they must be in BIDS format? How do I achieve this? Thanks!

1 Like

I have the same question when preprocessing infant fMRI data with fmriprep (version 20.2.1).
and I used the following arguments:
–skull-strip-template MNIInfant:cohort-1
–output-spaces MNIInfant:cohort-1: resolution:-2\

Error report as follows:

[MultiProc] Running 6 tasks, and 6 jobs ready. Free memory (GB): 64.21/80.00, Free processors: 4/10.
Currently running:
* fmriprep_wf.single_subject_101_wf.func_preproc_task_rest_run_01_wf.bold_confounds_wf.signals
* fmriprep_wf.single_subject_101_wf.func_preproc_task_rest_run_01_wf.bold_confounds_wf.rois_plot
* fmriprep_wf.single_subject_101_wf.func_preproc_task_rest_run_01_wf.bold_confounds_wf.acompcor
* fmriprep_wf.single_subject_101_wf.func_preproc_task_rest_run_02_wf.bold_confounds_wf.signals
* fmriprep_wf.single_subject_101_wf.func_preproc_task_rest_run_02_wf.bold_confounds_wf.rois_plot
* fmriprep_wf.single_subject_101_wf.func_preproc_task_rest_run_01_wf.sdc_unwarp_report_wf.bold_rpt

Intel MKL ERROR: Parameter 11 was incorrect on entry to SGESVD.
231025-15:11:06,36 nipype.workflow WARNING:
Storing result file without outputs
231025-15:11:06,100 nipype.workflow WARNING:
[Node] Error on “fmriprep_wf.single_subject_101_wf.func_preproc_task_rest_run_01_wf.bold_confounds_wf.acompcor” (/wd/fmriprep_wf/single_subject_101_wf/func_preproc_task_rest_run_01_wf/bold_confounds_wf/acompcor)
231025-15:11:07,606 nipype.workflow ERROR:
Node acompcor failed to run on host xbt049.
231025-15:11:08,861 nipype.workflow ERROR:
Saving crash info to /output/fmriprep/sub-101/log/20231025-125603_b5f65960-fcbc-44c1-8413-00f235d0b7f8/crash-20231025-151107-yhuang-acompcor-78a97f77-4709-4add-a54e-0a06ca9ada68.txt
Traceback (most recent call last):
File “/usr/local/miniconda/lib/python3.7/site-packages/nipype/pipeline/plugins/multiproc.py”, line 67, in run_node
result[“result”] = node.run(updatehash=updatehash)
File “/usr/local/miniconda/lib/python3.7/site-packages/nipype/pipeline/engine/nodes.py”, line 516, in run
result = self._run_interface(execute=True)
File “/usr/local/miniconda/lib/python3.7/site-packages/nipype/pipeline/engine/nodes.py”, line 635, in _run_interface
return self._run_command(execute)
File “/usr/local/miniconda/lib/python3.7/site-packages/nipype/pipeline/engine/nodes.py”, line 741, in _run_command
result = self._interface.run(cwd=outdir)
File “/usr/local/miniconda/lib/python3.7/site-packages/nipype/interfaces/base/core.py”, line 419, in run
runtime = self._run_interface(runtime)
File “/usr/local/miniconda/lib/python3.7/site-packages/niworkflows/interfaces/patches.py”, line 23, in _run_interface
runtime = super(RobustACompCor, self)._run_interface(runtime)
File “/usr/local/miniconda/lib/python3.7/site-packages/nipype/algorithms/confounds.py”, line 742, in _run_interface
components_names[retained] = components_header
ValueError: cannot copy sequence with size 448 to array axis with dimension 867

How can I address this issue? Thanks so much!!