HALFpipe / HALFpipe

ENIGMA HALFpipe is a user-friendly software that facilitates reproducible analysis of fMRI data
Other
74 stars 12 forks source link

Inputs do not occupy the same physical space #713

Closed hjameei closed 7 months ago

hjameei commented 7 months ago

What happened? I am running HALFpipe in a HPC on a set of subjects. I am providing T1 and resting state data. The preprocessing I am using contains generating atlas-based connectivity matrices, which runs for most of the subjects. However, on a number of subjects, I encounter an error when N4BiasFieldCorrection is run. Below is an example of the error for one subject (I have attached the err.txt file as well).

Is there an error message?

Cmdline:
│       N4BiasFieldCorrection --bspline-fitting [ 200 ] -d 3 --input-image /ext/data/gpfs/projects/punim0963/snuh/nipype/fmriprep_wf/single_subject_C044_wf/func_preproc_task_rsfMRI_wf/initial_boldref_wf/gen_ref/ref_bold.nii.gz --mask-image /ext/data/gpfs/projects/punim0963/snuh/nipype/fmriprep_wf/single_subject_C044_wf/func_preproc_task_rsfMRI_wf/initial_boldref_wf/enhance_and_skullstrip_bold_wf/check_hdr/tpl-MNI152NLin2009cAsym_res-01_label-brain_probseg_trans_mask_dil_hdr.nii.gz --output ref_bold_corrected.nii.gz -r
│     Stdout:
Stderr:
    terminate called after throwing an instance of 'itk::ExceptionObject'
      what():  /src/ants/build/staging/include/ITK-5.1/itkImageSink.hxx:242:
    itk::ERROR: LabelStatisticsImageFilter(0x26b0550): Inputs do not occupy the same physical space!
    InputImage Direction: 9.9999406e-01 3.4033828e-03 -5.4513358e-04
    3.4033827e-03 -9.4996626e-01 3.1233401e-01
    -5.4513357e-04 3.1233400e-01 9.4997219e-01
    , InputImagePrimary Direction: 9.9999379e-01 3.5189875e-03 1.7661476e-04
    3.2877769e-03 -9.4996626e-01 3.1233521e-01
    -1.2668819e-03 3.1233270e-01 9.4997194e-01

        Tolerance: 1.0000000e-06

    Aborted (core dumped)

What is the exact command that you used to run Halfpipe? I have attached Here is the script that I submitted on HPC:

#!/bin/bash

#SBATCH --job-name=halfpipe
#SBATCH --output=halfpipe.log.txt

#SBATCH --time=1-0
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=2
#SBATCH --mem=15706M

#SBATCH --array=1-118

if ! [ -x "$(command -v singularity)" ]; then
module load foss/2022a Apptainer/1.1.8
fi

singularity run \
--contain --cleanenv \
--bind /:/ext \
/data/gpfs/projects/punim0934/yuanzhe_run/halfpipe-halfpipe-latest.sif \
--workdir /ext/data/gpfs/projects/punim0963/snuh \
--only-run \
--uuid eed5b6a9 \
--subject-list /ext/data/gpfs/projects/punim0963/snuh/subject-list.txt \
--subject-chunks \
--only-chunk-index ${SLURM_ARRAY_TASK_ID} \
--nipype-n-procs 2 \
--keep some

Which settings did you use? Here is the spec.json file that I used for the preprocessing:

{
    "halfpipe_version": "0.0.post1.dev1+g6781c9b",
    "schema_version": "3.0",
    "timestamp": "2024-03-06_18-28",
    "global_settings": {
        "dummy_scans": 4,
        "slice_timing": true,
        "use_bbr": null,
        "skull_strip_algorithm": "ants",
        "run_mriqc": false,
        "run_fmriprep": true,
        "run_halfpipe": true,
        "fd_thres": 0.5,
        "anat_only": false,
        "write_graph": false,
        "hires": false,
        "run_reconall": false,
        "t2s_coreg": false,
        "medial_surface_nan": false,
        "bold2t1w_dof": 9,
        "fmap_bspline": true,
        "force_syn": false,
        "longitudinal": false,
        "regressors_all_comps": false,
        "regressors_dvars_th": 1.5,
        "regressors_fd_th": 0.5,
        "skull_strip_fixed_seed": false,
        "skull_strip_template": "OASIS30ANTs",
        "aroma_err_on_warn": false,
        "aroma_melodic_dim": -200,
        "sloppy": false
    },
    "files": [
        {
            "path": "/ext/data/gpfs/projects/punim0963/snuh/snuh_data/{sub}_T1.nii.gz",
            "datatype": "anat",
            "suffix": "T1w",
            "extension": ".nii.gz",
            "tags": {}
        },
        {
            "path": "/ext/data/gpfs/projects/punim0963/snuh/snuh_data/{sub}_RS.nii.gz",
            "datatype": "func",
            "suffix": "bold",
            "extension": ".nii.gz",
            "tags": {
                "task": "rsfMRI"
            },
            "metadata": {
                "slice_encoding_direction": "si"
            }
        },
        {
            "path": "/ext/data/scratch/projects/punim0564/ENIGMA_rs_halfpipe/{desc}_seed_2009.nii.gz",
            "datatype": "ref",
            "suffix": "seed",
            "extension": ".nii.gz",
            "tags": {},
            "metadata": {}
        },
        {
            "path": "/ext/data/scratch/projects/punim0564/ENIGMA_rs_halfpipe/{desc}_maps_2009.nii.gz",
            "datatype": "ref",
            "suffix": "map",
            "extension": ".nii.gz",
            "tags": {},
            "metadata": {}
        },
        {
            "path": "/ext/data/scratch/projects/punim0564/ENIGMA_rs_halfpipe/tpl-MNI152NLin2009cAsym_atlas-{desc}.nii.gz",
            "datatype": "ref",
            "suffix": "atlas",
            "extension": ".nii.gz",
            "tags": {},
            "metadata": {}
        }
    ],
    "settings": [
        {
            "ica_aroma": true,
            "smoothing": {
                "fwhm": 6.0
            },
            "grand_mean_scaling": {
                "mean": 10000.0
            },
            "bandpass_filter": {
                "type": "gaussian",
                "hp_width": 125.0,
                "lp_width": null
            },
            "name": "seedCorrSetting",
            "output_image": false
        },
        {
            "ica_aroma": false,
            "smoothing": {
                "fwhm": 6.0
            },
            "grand_mean_scaling": {
                "mean": 10000.0
            },
            "bandpass_filter": {
                "type": "gaussian",
                "hp_width": 125.0,
                "lp_width": null
            },
            "confounds_removal": [
                "a_comp_cor_0[0-4]"
            ],
            "name": "seedCorr1Setting",
            "output_image": false
        },
        {
            "ica_aroma": true,
            "smoothing": {
                "fwhm": 6.0
            },
            "grand_mean_scaling": {
                "mean": 10000.0
            },
            "bandpass_filter": {
                "type": "gaussian",
                "hp_width": 125.0,
                "lp_width": null
            },
            "confounds_removal": [
                "a_comp_cor_0[0-4]"
            ],
            "name": "seedCorr2Setting",
            "output_image": false
        },
        {
            "ica_aroma": true,
            "smoothing": {
                "fwhm": 6.0
            },
            "grand_mean_scaling": {
                "mean": 10000.0
            },
            "bandpass_filter": {
                "type": "gaussian",
                "hp_width": 125.0,
                "lp_width": null
            },
            "name": "dualRegSetting",
            "output_image": false
        },
        {
            "ica_aroma": false,
            "smoothing": {
                "fwhm": 6.0
            },
            "grand_mean_scaling": {
                "mean": 10000.0
            },
            "bandpass_filter": {
                "type": "gaussian",
                "hp_width": 125.0,
                "lp_width": null
            },
            "confounds_removal": [
                "a_comp_cor_0[0-4]"
            ],
            "name": "dualReg1Setting",
            "output_image": false
        },
        {
            "ica_aroma": true,
            "smoothing": {
                "fwhm": 6.0
            },
            "grand_mean_scaling": {
                "mean": 10000.0
            },
            "bandpass_filter": {
                "type": "gaussian",
                "hp_width": 125.0,
                "lp_width": null
            },
            "confounds_removal": [
                "a_comp_cor_0[0-4]"
            ],
            "name": "dualReg2Setting",
            "output_image": false
        },
        {
            "ica_aroma": true,
            "grand_mean_scaling": {
                "mean": 10000.0
            },
            "bandpass_filter": {
                "type": "gaussian",
                "hp_width": 125.0,
                "lp_width": null
            },
            "name": "corrMatrixSetting",
            "output_image": false
        },
        {
            "ica_aroma": false,
            "grand_mean_scaling": {
                "mean": 10000.0
            },
            "bandpass_filter": {
                "type": "gaussian",
                "hp_width": 125.0,
                "lp_width": null
            },
            "confounds_removal": [
                "a_comp_cor_0[0-4]"
            ],
            "name": "corrMatrix1Setting",
            "output_image": false
        },
        {
            "ica_aroma": true,
            "grand_mean_scaling": {
                "mean": 10000.0
            },
            "bandpass_filter": {
                "type": "gaussian",
                "hp_width": 125.0,
                "lp_width": null
            },
            "confounds_removal": [
                "a_comp_cor_0[0-4]"
            ],
            "name": "corrMatrix2Setting",
            "output_image": false
        },
        {
            "ica_aroma": true,
            "grand_mean_scaling": {
                "mean": 10000.0
            },
            "bandpass_filter": {
                "type": "frequency_based",
                "low": 0.01,
                "high": 0.1
            },
            "name": "reHoSetting",
            "output_image": false
        },
        {
            "ica_aroma": false,
            "grand_mean_scaling": {
                "mean": 10000.0
            },
            "bandpass_filter": {
                "type": "frequency_based",
                "low": 0.01,
                "high": 0.1
            },
            "confounds_removal": [
                "a_comp_cor_0[0-4]"
            ],
            "name": "reHo1Setting",
            "output_image": false
        },
        {
            "ica_aroma": true,
            "grand_mean_scaling": {
                "mean": 10000.0
            },
            "bandpass_filter": {
                "type": "frequency_based",
                "low": 0.01,
                "high": 0.1
            },
            "confounds_removal": [
                "a_comp_cor_0[0-4]"
            ],
            "name": "reHo2Setting",
            "output_image": false
        },
        {
            "ica_aroma": true,
            "grand_mean_scaling": {
                "mean": 10000.0
            },
            "bandpass_filter": {
                "type": "frequency_based",
                "low": 0.01,
                "high": 0.1
            },
            "name": "fAlffSetting",
            "output_image": false
        },
        {
            "ica_aroma": true,
            "grand_mean_scaling": {
                "mean": 10000.0
            },
            "name": "fALFFUnfilteredSetting",
            "output_image": false
        },
        {
            "ica_aroma": false,
            "grand_mean_scaling": {
                "mean": 10000.0
            },
            "bandpass_filter": {
                "type": "frequency_based",
                "low": 0.01,
                "high": 0.1
            },
            "confounds_removal": [
                "a_comp_cor_0[0-4]"
            ],
            "name": "fAlff1Setting",
            "output_image": false
        },
        {
            "ica_aroma": false,
            "grand_mean_scaling": {
                "mean": 10000.0
            },
            "confounds_removal": [
                "a_comp_cor_0[0-4]"
            ],
            "name": "fALFF1UnfilteredSetting",
            "output_image": false
        },
        {
            "ica_aroma": true,
            "grand_mean_scaling": {
                "mean": 10000.0
            },
            "bandpass_filter": {
                "type": "frequency_based",
                "low": 0.01,
                "high": 0.1
            },
            "confounds_removal": [
                "a_comp_cor_0[0-4]"
            ],
            "name": "fAlff2Setting",
            "output_image": false
        },
        {
            "ica_aroma": true,
            "grand_mean_scaling": {
                "mean": 10000.0
            },
            "confounds_removal": [
                "a_comp_cor_0[0-4]"
            ],
            "name": "fALFF2UnfilteredSetting",
            "output_image": false
        }
    ],
    "features": [
        {
            "name": "seedCorr",
            "setting": "seedCorrSetting",
            "type": "seed_based_connectivity",
            "seeds": [
                "R_dorsalnexus",
                "R_postInsula",
                "Middle_PAG",
                "L_SPL",
                "L_lOFC",
                "L_ventralstriatum",
                "R_subcallosal",
                "R_rACC",
                "R_mOFC",
                "R_vmPFC",
                "L_vlPFC_pt",
                "Middle_Precuneus",
                "R_dACC",
                "L_thalamus",
                "L_antInsula",
                "R_thalamus",
                "L_STG_post",
                "L_subcallosal",
                "R_putamen",
                "L_postInsula",
                "Middle_subgenual",
                "L_putamen",
                "L_dlPFC",
                "L_vlPFC_po",
                "R_IPL",
                "L_amygdala",
                "L_mOFC",
                "R_caudate",
                "R_fusiform",
                "R_SPL",
                "L_rACC",
                "L_dACC",
                "L_hippocampus",
                "L_vmPFC",
                "R_MTG",
                "R_lOFC",
                "L_supramarginal",
                "R_dlPFC",
                "R_amygdala",
                "R_STG_post",
                "L_IPL",
                "L_ITG_tempocc",
                "Middle_PCC",
                "Middle_dmPFC",
                "R_ITG_tempocc",
                "R_vlPFC_po",
                "R_hippocampus",
                "R_vlPFC_pt",
                "R_supramarginal",
                "R_ventralstriatum",
                "L_fusiform",
                "L_caudate",
                "L_MTG_post",
                "L_dorsalnexus",
                "R_antInsula"
            ],
            "min_seed_coverage": 0.8
        },
        {
            "name": "seedCorr1",
            "setting": "seedCorr1Setting",
            "type": "seed_based_connectivity",
            "seeds": [
                "R_dorsalnexus",
                "R_postInsula",
                "Middle_PAG",
                "L_SPL",
                "L_lOFC",
                "L_ventralstriatum",
                "R_subcallosal",
                "R_rACC",
                "R_mOFC",
                "R_vmPFC",
                "L_vlPFC_pt",
                "Middle_Precuneus",
                "R_dACC",
                "L_thalamus",
                "L_antInsula",
                "R_thalamus",
                "L_STG_post",
                "L_subcallosal",
                "R_putamen",
                "L_postInsula",
                "Middle_subgenual",
                "L_putamen",
                "L_dlPFC",
                "L_vlPFC_po",
                "R_IPL",
                "L_amygdala",
                "L_mOFC",
                "R_caudate",
                "R_fusiform",
                "R_SPL",
                "L_rACC",
                "L_dACC",
                "L_hippocampus",
                "L_vmPFC",
                "R_MTG",
                "R_lOFC",
                "L_supramarginal",
                "R_dlPFC",
                "R_amygdala",
                "R_STG_post",
                "L_IPL",
                "L_ITG_tempocc",
                "Middle_PCC",
                "Middle_dmPFC",
                "R_ITG_tempocc",
                "R_vlPFC_po",
                "R_hippocampus",
                "R_vlPFC_pt",
                "R_supramarginal",
                "R_ventralstriatum",
                "L_fusiform",
                "L_caudate",
                "L_MTG_post",
                "L_dorsalnexus",
                "R_antInsula"
            ],
            "min_seed_coverage": 0.8
        },
        {
            "name": "seedCorr2",
            "setting": "seedCorr2Setting",
            "type": "seed_based_connectivity",
            "seeds": [
                "R_dorsalnexus",
                "R_postInsula",
                "Middle_PAG",
                "L_SPL",
                "L_lOFC",
                "L_ventralstriatum",
                "R_subcallosal",
                "R_rACC",
                "R_mOFC",
                "R_vmPFC",
                "L_vlPFC_pt",
                "Middle_Precuneus",
                "R_dACC",
                "L_thalamus",
                "L_antInsula",
                "R_thalamus",
                "L_STG_post",
                "L_subcallosal",
                "R_putamen",
                "L_postInsula",
                "Middle_subgenual",
                "L_putamen",
                "L_dlPFC",
                "L_vlPFC_po",
                "R_IPL",
                "L_amygdala",
                "L_mOFC",
                "R_caudate",
                "R_fusiform",
                "R_SPL",
                "L_rACC",
                "L_dACC",
                "L_hippocampus",
                "L_vmPFC",
                "R_MTG",
                "R_lOFC",
                "L_supramarginal",
                "R_dlPFC",
                "R_amygdala",
                "R_STG_post",
                "L_IPL",
                "L_ITG_tempocc",
                "Middle_PCC",
                "Middle_dmPFC",
                "R_ITG_tempocc",
                "R_vlPFC_po",
                "R_hippocampus",
                "R_vlPFC_pt",
                "R_supramarginal",
                "R_ventralstriatum",
                "L_fusiform",
                "L_caudate",
                "L_MTG_post",
                "L_dorsalnexus",
                "R_antInsula"
            ],
            "min_seed_coverage": 0.8
        },
        {
            "name": "dualReg",
            "setting": "dualRegSetting",
            "type": "dual_regression",
            "maps": [
                "FIND_ica"
            ]
        },
        {
            "name": "dualReg1",
            "setting": "dualReg1Setting",
            "type": "dual_regression",
            "maps": [
                "FIND_ica"
            ]
        },
        {
            "name": "dualReg2",
            "setting": "dualReg2Setting",
            "type": "dual_regression",
            "maps": [
                "FIND_ica"
            ]
        },
        {
            "name": "corrMatrix",
            "setting": "corrMatrixSetting",
            "type": "atlas_based_connectivity",
            "atlases": [
                "power2011_dseg",
                "schaefer2011Combined_dseg",
                "brainnetomeCombined_dseg"
            ],
            "min_region_coverage": 0.8
        },
        {
            "name": "corrMatrix1",
            "setting": "corrMatrix1Setting",
            "type": "atlas_based_connectivity",
            "atlases": [
                "power2011_dseg",
                "schaefer2011Combined_dseg",
                "brainnetomeCombined_dseg"
            ],
            "min_region_coverage": 0.8
        },
        {
            "name": "corrMatrix2",
            "setting": "corrMatrix2Setting",
            "type": "atlas_based_connectivity",
            "atlases": [
                "power2011_dseg",
                "schaefer2011Combined_dseg",
                "brainnetomeCombined_dseg"
            ],
            "min_region_coverage": 0.8
        },
        {
            "name": "reHo",
            "setting": "reHoSetting",
            "type": "reho",
            "smoothing": {
                "fwhm": 6.0
            }
        },
        {
            "name": "reHo1",
            "setting": "reHo1Setting",
            "type": "reho",
            "smoothing": {
                "fwhm": 6.0
            }
        },
        {
            "name": "reHo2",
            "setting": "reHo2Setting",
            "type": "reho",
            "smoothing": {
                "fwhm": 6.0
            }
        },
        {
            "name": "fALFF",
            "setting": "fAlffSetting",
            "type": "falff",
            "smoothing": {
                "fwhm": 6.0
            },
            "unfiltered_setting": "fALFFUnfilteredSetting"
        },
        {
            "name": "fALFF1",
            "setting": "fAlff1Setting",
            "type": "falff",
            "smoothing": {
                "fwhm": 6.0
            },
            "unfiltered_setting": "fALFF1UnfilteredSetting"
        },
        {
            "name": "fALFF2",
            "setting": "fAlff2Setting",
            "type": "falff",
            "smoothing": {
                "fwhm": 6.0
            },
            "unfiltered_setting": "fALFF2UnfilteredSetting"
        }
    ],
    "models": []
}

I have tried comparing the header of the fMRI file that resulted in an error to the header of the fMRI that was processed successfully using fslhd. However, only the vertex to xyz transformation matrices were different along the two files.

Here is the comparison between the two head files (the second one is the one ending in the error):

< filename  /data/gpfs/projects/punim0963/snuh/nipype/fmriprep_wf/single_subject_C041_wf/func_preproc_task_rsfMRI_wf/initial_boldref_wf/gen_ref/ref_bold.nii.gz
---
> filename  /data/gpfs/projects/punim0963/snuh/nipype/fmriprep_wf/single_subject_C044_wf/func_preproc_task_rsfMRI_wf/initial_boldref_wf/gen_ref/ref_bold.nii.gz
29,30c29,30
< scl_slope 0.025201
< scl_inter 825.784668
---
> scl_slope 0.022466
> scl_inter 736.170654
48,50c48,50
< qto_xyz:1 -1.871556 -0.045740 -0.266174 125.787659
< qto_xyz:2 -0.038281 1.869848 -0.341807 -90.154892
< qto_xyz:3 -0.106946 0.131150 4.780410 -53.380650
---
> qto_xyz:1 -1.874988 -0.006598 -0.000848 119.258224
> qto_xyz:2 -0.006165 1.781187 -1.499209 -76.436783
> qto_xyz:3 -0.002375 0.585624 4.559865 -93.368042
57,59c57,59
< sto_xyz:1 -1.871556 -0.045740 -0.266167 125.787659
< sto_xyz:2 -0.038281 1.869848 -0.341807 -90.154892
< sto_xyz:3 -0.106943 0.131151 4.780411 -53.380650
---
> sto_xyz:1 -1.874989 -0.006545 0.000000 119.258224
> sto_xyz:2 -0.006218 1.781187 -1.499207 -76.436783
> sto_xyz:3 -0.002044 0.585624 4.559865 -93.368042
66c66
< descrip       TE=40;Time=120140.277;phase=1;dwell=0.390
---
> descrip       TE=40;Time=93008.460;phase=1;dwell=0.390

Here is the difference between header files of the mask and the fMRI file yeilding error:

< filename  /data/gpfs/projects/punim0963/snuh/nipype/fmriprep_wf/single_subject_C044_wf/func_preproc_task_rsfMRI_wf/initial_boldref_wf/gen_ref/ref_bold.nii.gz
---
> filename  /data/gpfs/projects/punim0963/snuh/nipype/fmriprep_wf/single_subject_C044_wf/func_preproc_task_rsfMRI_wf/initial_boldref_wf/enhance_and_skullstrip_bold_wf/check_hdr/tpl-MNI152NLin2009cAsym_res-01_label-brain_probseg_trans_mask_dil_hdr.nii.gz
4c4
< data_type INT16
---
> data_type FLOAT32
15,17c15,17
< datatype  4
< nbyper        2
< bitpix        16
---
> datatype  16
> nbyper        4
> bitpix        32
22,25c22,25
< pixdim4       1.000000
< pixdim5       1.000000
< pixdim6       1.000000
< pixdim7       1.000000
---
> pixdim4       0.000000
> pixdim5       0.000000
> pixdim6       0.000000
> pixdim7       0.000000
29,30c29,30
< scl_slope 0.022466
< scl_inter 736.170654
---
> scl_slope 1.000000
> scl_inter 0.000000
34,35c34,35
< slice_name    alternating_decreasing
< slice_code    4
---
> slice_name    Unknown
> slice_code    0
48,50c48,50
< qto_xyz:1 -1.874988 -0.006598 -0.000848 119.258224
< qto_xyz:2 -0.006165 1.781187 -1.499209 -76.436783
< qto_xyz:3 -0.002375 0.585624 4.559865 -93.368042
---
> qto_xyz:1 -1.874989 -0.006381 0.002617 119.258224
> qto_xyz:2 -0.006381 1.781187 -1.499203 -76.436783
> qto_xyz:3 -0.001022 0.585626 4.559866 -93.368042
66,67c66,67
< descrip       TE=40;Time=93008.460;phase=1;dwell=0.390
< aux_file  Reference_volume_for_mo
---
> descrip       FSL5.0
> aux_file

This is very strange, considering there is not much difference between header files of the fMRI files that were processed successfully and the files that led to an error. Should I try using N4BiasFieldCorrection with -d 2 on every slice separately?

I appreciate your help in advance. err.txt

HippocampusGirl commented 7 months ago

Hi @hjameei,

we recently fixed an issue related to ANTs (https://github.com/HALFpipe/HALFpipe/pull/692). Could you check if the container you used was downloaded after February 15th this year?

Best, Lea

hjameei commented 7 months ago

Hi @HippocampusGirl

I was using the August 2023 version previously. After trying the new container, the issue is fixed now.

Thanks very much!