Using .h5 file from fMRIPrep to apply warping to functional stats map

Hello,

I ran fMRIPrep (latest version) with the which generated an .h5 files containing the transforms for warping images from native space to MNI space.

Now, I need to apply this transformation to a functional stat map (a first-level contrast z map created in using Nilearn), but it seems that antsApplyTransforms does not accept .h5 files as direct inputs.

I’m looking for guidance on how to extract the transformation from the .h5 file and apply it correctly.

Thank you!

Hi @maayanziv, and welcome to neurostars!

ants does accept the h5 files. Please show us the command and error so we can better help you.

Best,
Steven

Thank you! Here are the commands I’m using: # Load ANTs module
module load ants/2.3.1

  • Define input files
CONTRAST_IMG="/path/to/runA_first_level_contrast_effect_size.nii.gz"
T1_IMAGE="/path/to/ses-01_acq-hbcd_run-01_desc-preproc_T1w.nii.gz"
REFERENCE_IMG="/path/to/ses-01_task-animal_run-02_space-MNI152NLin2009cAsym_res-2_boldref.nii.gz"
OUTPUT_IMG="/path/to/output.nii.gz"
  • Transformation files
FUNC_TO_T1_XFM="/path/to/sub_XXX_ses-01_task-animal_run-02_from-boldref_to-T1w_mode-image_desc-coreg_xfm.txt"
T1_TO_MNI="/path/to/sub-XXX_ses-01_acq-hbcd_run-01_from-MNI152NLin2009cAsym_to-T1w_mode-image_xfm.h5"
  • Step 1: Apply transformation from functional space to T1 space
antsApplyTransforms -d 3 \
    -i ${CONTRAST_IMG} \
    -r ${T1_IMAGE} \
    -o contrast_in_T1.nii.gz \
    -t ${FUNC_TO_T1_XFM} \
    -n Linear
  • Step 2: Apply FULL nonlinear transformation from T1 to MNI space
antsApplyTransforms -d 3 \
    -i contrast_in_T1.nii.gz \
    -r ${REFERENCE_IMG} \
    -o ${OUTPUT_IMG} \
    -t ${T1_TO_MNI} \
    -n Linear

This is the error I’m getting:

HDF5-DIAG: Error detected in HDF5 (1.8.17) thread 0:
  #000: /cbica/software/external/ants/centos7/2.3.1/ITKv5/Modules/ThirdParty/HDF5/src/itkhdf5/src/H5D.c line 358 in itk_H5Dopen2(): not found
    major: Dataset
    minor: Object not found
  #001: /cbica/software/external/ants/centos7/2.3.1/ITKv5/Modules/ThirdParty/HDF5/src/itkhdf5/src/H5Gloc.c line 430 in itk_H5G_loc_find(): can't find object
    major: Symbol table
    minor: Object not found
  #002: /cbica/software/external/ants/centos7/2.3.1/ITKv5/Modules/ThirdParty/HDF5/src/itkhdf5/src/H5Gtraverse.c line 861 in itk_H5G_traverse(): internal path traversal failed
    major: Symbol table
    minor: Object not found
  #003: /cbica/software/external/ants/centos7/2.3.1/ITKv5/Modules/ThirdParty/HDF5/src/itkhdf5/src/H5Gtraverse.c line 641 in H5G_traverse_real(): traversal operator failed
    major: Symbol table
    minor: Callback failed
  #004: /cbica/software/external/ants/centos7/2.3.1/ITKv5/Modules/ThirdParty/HDF5/src/itkhdf5/src/H5Gloc.c line 385 in H5G_loc_find_cb(): object 'TranformFixedParameters' doesn't exist
    major: Symbol table
    minor: Object not found
Transform reader for /cbica/home/zivma/Functional/derivative/fmriprep_24.1.1_new/fmriprep_t1/sub-CBPD0250/ses-01/anat/sub-CBPD0250_ses-01_acq-hbcd_run-01_from-MNI152NLin2009cAsym_to-T1w_mode-image_xfm.h5 caught an ITK exception:

itk::ExceptionObject (0x12d5c60)
Location: "unknown" 
File: /cbica/software/external/ants/centos7/2.3.1/ITKv5/Modules/IO/TransformHDF5/include/itkHDF5TransformIO.hxx
Line: 378
Description: itk::ERROR: HDF5TransformIOTemplate(0x1145a60): H5Dopen2 failed

Hi @maayanziv,

In the future, please format your code text using the tick marks (or </> in the text editor). You can see I edited your code for you this time for readability.

May you please try a more updated version of ANTs and confirm the paths you defined are correct? Perhaps, try running ANTs using the same fmriprep container, to better ensure version comparability.

Best,
Steven

Thank you so much! Running it in the same container seems to have solved the problem!

Best,
Maayan