nipreps / nibabies

fMRIPrep-Infants - A robust, transparent workflow tailored for neonate and infant MRI
https://nibabies.readthedocs.io/en/latest
Apache License 2.0
23 stars 10 forks source link

CIFTI refinement should account for label of sub-structures #149

Closed ravisanjana closed 2 years ago

ravisanjana commented 2 years ago

I was running nibabies using the docker container and the wrapper script. Here is the command I used:

python3 nibabies_wrapper.py docker /Users/sealab/Documents/nibabies/bids/newborn /Users/sealab/Documents/nibabies/derivatives/newborn participant --age-months 1 --fs-license-file /Applications/freesurfer/7.1.1/license.txt --cifti-output --nprocs 4 -w /Users/sealab/Documents/nibabies/work/newborn

Any idea what went wrong? This is the error from the report:

Node Name: _create_dtseries5

File: /out/sub-1034/log/20211104-202559_7ae2f35c-a8cb-4c84-8dbe-69c24336b876/crash-20211105-001034-root-_create_dtseries5-52733c58-1773-4ed2-a404-42510fbc9dbc.txt
Working Directory: /scratch/nibabies_wf/single_subject_1034_wf/func_preproc_ses_newborn_task_restPA_run_01_wf/subcortical_mni_alignment_wf/create_dtseries/mapflow/_create_dtseries5
Inputs: 
args:
cerebellum_metric:
environ: {}
left_metric:
out_file: out.dtseries.nii
right_metric:
roi_cerebellum:
roi_left:
roi_right:
timestart:
timestep:
unit:
volume_data: /scratch/nibabies_wf/single_subject_1034_wf/func_preproc_ses_newborn_task_restPA_run_01_wf/subcortical_mni_alignment_wf/bold_mask_roi/mapflow/_bold_mask_roi5/vol0000_xform-00000_merged_flirt_masked.nii.gz
volume_structure_labels: /scratch/nibabies_wf/single_subject_1034_wf/func_preproc_ses_newborn_task_restPA_run_01_wf/subcortical_mni_alignment_wf/vol_label/mapflow/_vol_label5/vol0005_flirt_maths_labels.nii.gz
Traceback (most recent call last):
  File "/usr/local/miniconda/lib/python3.8/site-packages/nipype/pipeline/plugins/multiproc.py", line 67, in run_node
    result["result"] = node.run(updatehash=updatehash)
  File "/usr/local/miniconda/lib/python3.8/site-packages/nipype/pipeline/engine/nodes.py", line 516, in run
    result = self._run_interface(execute=True)
  File "/usr/local/miniconda/lib/python3.8/site-packages/nipype/pipeline/engine/nodes.py", line 635, in _run_interface
    return self._run_command(execute)
  File "/usr/local/miniconda/lib/python3.8/site-packages/nipype/pipeline/engine/nodes.py", line 741, in _run_command
    result = self._interface.run(cwd=outdir)
  File "/usr/local/miniconda/lib/python3.8/site-packages/nipype/interfaces/base/core.py", line 428, in run
    runtime = self._run_interface(runtime)
  File "/usr/local/miniconda/lib/python3.8/site-packages/nipype/interfaces/base/core.py", line 822, in _run_interface
    self.raise_exception(runtime)
  File "/usr/local/miniconda/lib/python3.8/site-packages/nipype/interfaces/base/core.py", line 749, in raise_exception
    raise RuntimeError(
RuntimeError: Command:
wb_command -cifti-create-dense-timeseries out.dtseries.nii -volume /scratch/nibabies_wf/single_subject_1034_wf/func_preproc_ses_newborn_task_restPA_run_01_wf/subcortical_mni_alignment_wf/bold_mask_roi/mapflow/_bold_mask_roi5/vol0000_xform-00000_merged_flirt_masked.nii.gz /scratch/nibabies_wf/single_subject_1034_wf/func_preproc_ses_newborn_task_restPA_run_01_wf/subcortical_mni_alignment_wf/vol_label/mapflow/_vol_label5/vol0005_flirt_maths_labels.nii.gz
Standard output:

Standard error:

While running:
wb_command -cifti-create-dense-timeseries out.dtseries.nii -volume /scratch/nibabies_wf/single_subject_1034_wf/func_preproc_ses_newborn_task_restPA_run_01_wf/subcortical_mni_alignment_wf/bold_mask_roi/mapflow/_bold_mask_roi5/vol0000_xform-00000_merged_flirt_masked.nii.gz /scratch/nibabies_wf/single_subject_1034_wf/func_preproc_ses_newborn_task_restPA_run_01_wf/subcortical_mni_alignment_wf/vol_label/mapflow/_vol_label5/vol0005_flirt_maths_labels.nii.gz

ERROR: cifti xml dimensions must be greater than zero

Return code: 255

System information: macOS Big Sur version 11.6 Docker: GB ram, 8 CPUs Nibabies Docker container version: 21.0.1

effigies commented 2 years ago

Possibly empty labels? Can you look at nibabies_wf/single_subject_1034_wf/func_preproc_ses_newborn_task_restPA_run_01_wf/subcortical_mni_alignment_wf/vol_label/mapflow/_vol_label5/vol0005_flirt_maths_labels.nii.gz with freeview or something?

ravisanjana commented 2 years ago

Ah yes, I opened it with Freeview and looks like it is empty!

mgxd commented 2 years ago

My guess is something is going wrong when resampling to MNIInfant.

Can you share some screenshots of the following:

# BOLD resampled to MNI Infant template
nibabies_wf/single_subject_01_wf/func_preproc_.../bold_std_trans_wf/_std_target_MNIInfantcohort-1.cohort1/merge/vol0000_xform-00000_merged.nii.gz

# subcortical segmentations resampled to MNI Infant template
nibabies_wf/single_subject_01_wf/func_preproc_.../subcortical_rois_wf/refine_bold_rois/aseg_trans_labels.nii.gz
ravisanjana commented 2 years ago

Here are some screenshots of each:

  1. Bold resampled to MNI Infant template: BOLD_resampled_1
BOLD_resampled_2 BOLD_resampled_3
  1. Subcortical segmentations resampled to MNI Infant template: subcortical_seg_1
subcortical_seg_2 subcortical_seg_3
  1. aseg_trans_labels file overlaid on the functional: combined
mgxd commented 2 years ago

Hm, the BOLD -> MNIInfant resampling does not look very good. Did this subject undergo any distortion correction?

Has this problem come up across multiple subjects?

madisoth commented 2 years ago

I think I'm having the same issue; errors on all create_dtseries5 nodes and empty files for label 5 (I believe this is BRAIN_STEM?)

Have tested on both:

anat dir contains 1 T1w and 1 T2w fmaps are PEpolar func data are multiecho

Run command to docker/derivatives build, with precomputed derivatives:

singularity run --cleanenv -B ~/Documents/license.txt:/license.txt -B <...>/bids/derivatives:/derivatives -B <...>/bids/nibabies_me_input:/input -B <...>/bids/nibabies_out:/out -B <...>/bids/nibabies_wd:/wd <...>/nibabies-21.0.2_derivatives2.sif --fs-license-file /license.txt --mem 180000 --omp-nthreads 8 --nprocs 8 --derivatives /derivatives/precomputed  --cifti-output 91k --age-months 2 -w /wd /input /out participant
mgxd commented 2 years ago

@madisoth is this error occurring consistently for that subject? If so, is it available on the shared box to debug with?

I believe @ericfeczko mentioned the dcan-infant-pipeline would also run into this in cases where some of the ROIs were essentially empty files. We probably should increase the fault tolerance of this to allow for this, although I have a slight concern that it could cause further errors to go undetected.

ericfeczko commented 2 years ago

@mgxd That's correct -- there are soft failures in the JLF algorithm, which turn into hard failures during the subcortical realignment to the atlas.

My advice would be to provide a message that a given segmentation is null or empty and prompt investigation of the suspect segmentation from JLF. Soft failures for JLF may go beyond simply a missing label.

audreymhoughton commented 2 years ago

@ericfeczko @mgxd Can someone elaborate on why JLF is running if @madisoth is feeding in an external segmentation?

ericfeczko commented 2 years ago

My bad, I misread his initial question.

@mgxd, this is probably not related to the same issues we get with dcan-infant-pipeline then.

madisoth commented 2 years ago

Thanks all for your responses, @mgxd I just uploaded the input and output directory to Box. I can also upload files from the work directory if needed.

From a quick check of the FreeSurfer output, aparc+aseg looks okay but the white surface is placed such that that none of the BRAIN_STEM ROI is contained within.

The error has happened 3 out of 3 times I have tried running this subject with --cifti-output 91k, twice with the derivatives branch build (both with and without using --derivatives) and once on the main branch unstable build.

It did process fine with the DCAN infant-abcd-bids-pipeline using its T2w-based JLF option (with tedana 0.0.11 used to combine the multiecho functional data prior to running).

mgxd commented 2 years ago

Okay, I see what's going on here. The brain stem (Label 16 in the FreeSurfer LUT) is actually segmented into its individual structures:

NiBabies should pick up these finer segmentations and relabel them to general brainstem to handle further processing. We will likely need to do this with other brain structures as well.

ericfeczko commented 2 years ago

Thanks for figuring this out @mgxd let us know if/how we can help further :)

madisoth commented 2 years ago

Thank you @mgxd for working that out! I noticed those labels 173-175 in my subject but didn't make the connection to why the CIFTI ROI was coming up empty.

mgxd commented 2 years ago

This was closed in #186 - we'll monitor to see if any other labels need to be accounted for