Questions about adding a custom standard template

fmriprep
templateflow
#1

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
fMRIPrep: TemplateFlow fails with OSError: [Errno 30] Read-only file system
Using custom template --output-spaces
#2

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?

#3

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.

#4

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.

#5

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.

#6

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

#7

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)

#8

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’

#9

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

#10

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.

#11

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.

#12

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.

#13

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.