PennLINC / xcp_d

Post-processing of fMRIPrep, NiBabies, and HCP outputs
https://xcp-d.readthedocs.io
BSD 3-Clause "New" or "Revised" License
78 stars 26 forks source link

KeyError: 'lh_pial_surf' - unclear what's wrong #1090

Closed mgirn closed 3 months ago

mgirn commented 8 months ago

Summary

I'm getting an error that's presumably related to freesurfer but I have no idea on how to troubleshoot.

Additional details

My command

docker run --rm -it \
    -v /Volumes/My_Passport_for_Mac/i2_derivatives/fmriprep:/fmriprep:ro \
    -v /Volumes/My_Passport_for_Mac/i2_derivatives/xcp_work:/work:rw \
    -v /Volumes/My_Passport_for_Mac/i2_derivatives/xcp-d:/out:rw \
    -v /Users/manesh/Downloads:/fslicense:rw \
    -v /Volumes/My_Passport_for_Mac/i2_derivatives/fmriprep/sourcedata/freesurfer:/freesurfer:ro \
    pennlinc/xcp_d:latest \
    /fmriprep /out participant \
    --despike -w /work --smoothing 4 -f 0 --nuisance-regressors acompcor \
    --fs-license-file /fslicense/license.txt

Error output

Process Process-2:
Traceback (most recent call last):
  File "/usr/local/miniconda/lib/python3.10/multiprocessing/process.py", line 314, in _bootstrap
    self.run()
  File "/usr/local/miniconda/lib/python3.10/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/miniconda/lib/python3.10/site-packages/xcp_d/cli/run.py", line 1059, in build_workflow
    retval["workflow"] = init_xcpd_wf(
  File "/usr/local/miniconda/lib/python3.10/site-packages/xcp_d/workflows/base.py", line 202, in init_xcpd_wf
    single_subj_wf = init_subject_wf(
  File "/usr/local/miniconda/lib/python3.10/site-packages/xcp_d/workflows/base.py", line 390, in init_subject_wf
    mesh_available, standard_space_mesh, mesh_files = collect_mesh_data(
  File "/usr/local/miniconda/lib/python3.10/site-packages/xcp_d/utils/bids.py", line 464, in collect_mesh_data
    f"Query: {queries[dtype]}"
KeyError: 'lh_pial_surf'
tsalo commented 8 months ago

It looks like there are two issues:

  1. Multiple files are being found for a given surface file search. This means there is either something wrong with XCP-D's query or with your outputs.
    • Can you share the tree for your failing subject's fMRIPrep anat folder?
  2. There's a small bug in XCP-D that messes up the formatting of the error message for 1.
    • I can fix this.
mgirn commented 8 months ago

Thanks for the quick reply.

Ahh I see. I did get the below warnings. I removed the session-specific anat folders and it now seems to be running. Is that what you would've advised?

240314-22:37:21,565 nipype.utils WARNING:
     Multiple files found for query 't1w':
    /fmriprep/sub-01/anat/sub-01_desc-preproc_T1w.nii.gz
    /fmriprep/sub-01/ses-V1/anat/sub-01_ses-V1_desc-preproc_T1w.nii.gz
    /fmriprep/sub-01/ses-V2/anat/sub-01_ses-V2_desc-preproc_T1w.nii.gz
240314-22:37:21,565 nipype.utils WARNING:
     Multiple files found for query 'anat_dseg':
    /fmriprep/sub-01/anat/sub-01_dseg.nii.gz
    /fmriprep/sub-01/ses-V1/anat/sub-01_ses-V1_dseg.nii.gz
    /fmriprep/sub-01/ses-V2/anat/sub-01_ses-V2_dseg.nii.gz
240314-22:37:21,565 nipype.utils WARNING:
     Multiple files found for query 'template_to_anat_xfm':
    /fmriprep/sub-01/anat/sub-01_from-MNI152NLin2009cAsym_to-T1w_mode-image_xfm.h5
    /fmriprep/sub-01/ses-V1/anat/sub-01_ses-V1_from-MNI152NLin2009cAsym_to-T1w_mode-image_xfm.h5
    /fmriprep/sub-01/ses-V2/anat/sub-01_ses-V2_from-MNI152NLin2009cAsym_to-T1w_mode-image_xfm.h5
240314-22:37:21,565 nipype.utils WARNING:
     Multiple files found for query 'anat_brainmask':
    /fmriprep/sub-01/anat/sub-01_desc-brain_mask.nii.gz
    /fmriprep/sub-01/ses-V1/anat/sub-01_ses-V1_desc-brain_mask.nii.gz
    /fmriprep/sub-01/ses-V2/anat/sub-01_ses-V2_desc-brain_mask.nii.gz
240314-22:37:21,565 nipype.utils WARNING:
     Multiple files found for query 'anat_to_template_xfm':
    /fmriprep/sub-01/anat/sub-01_from-T1w_to-MNI152NLin2009cAsym_mode-image_xfm.h5
    /fmriprep/sub-01/ses-V1/anat/sub-01_ses-V1_from-T1w_to-MNI152NLin2009cAsym_mode-image_xfm.h5
    /fmriprep/sub-01/ses-V2/anat/sub-01_ses-V2_from-T1w_to-MNI152NLin2009cAsym_mode-image_xfm.h5
tsalo commented 8 months ago

Did you run fMRIPrep in a custom manner to have the session-specific anatomical folders? If so, then I would recommend running XCP-D separately on each session.

mgirn commented 8 months ago

Hmm we did not. The dataset as input to fMRIprep had separate T1w files for each session, and fmriprep automatically processed them. However, given that the T1w files are presumably not changing in any significant away across the sessions, it should be fine to use the registrations based on the first one only. That'd keep things simple. Do you agree? Thanks and much appreciated.

tsalo commented 8 months ago

Can you share the fMRIPrep command you used? fMRIPrep generally calculates a single T1w from longitudinal datasets, so I wonder what settings you used to produce longitudinal structural derivatives.

mgirn commented 8 months ago

It was run by a colleague of mine, he used the following:

python3 -m fmriprep_docker \
    /Volumes/My_Passport_for_Mac/i2_data_BIDS  \
    /Volumes/My_Passport_for_Mac/i2_derivatives \
    --participant-label 01 \
    --fs-license-file /Users/lpasquini/Desktop/B_AssistantProf/software/Freesurfer_license/license.txt \
    --output-spaces MNI152NLin2009cAsym:res-2 \
    --use-aroma \
    -w /Volumes/My_Passport_for_Mac/tmp
tsalo commented 8 months ago

What version of fMRIPrep is that?

mgirn commented 8 months ago

21.0.1

tsalo commented 8 months ago

I'm still not sure how this particular output layout arose, but I think it might be a good idea to add a --longitudinal flag to XCP-D that will look for session-specific anatomical data and write out session-specific report files.

ksreeniv commented 7 months ago

I also ran into the same error as above and have a similar structure wherein there are session-specific anat folders. In my case, I had to run fMRIPrep in a custom manner to be able to use already processed freesurfer data for each session individually. I had to link the session-specific freesurfer folder to the sub-ses specific folder name and with a combination of the fsdir path flag and the bids filter file flag was able to process the session individually [credit: #4644].

I tried using the bids filter file flag for xcpd to try to run individual sessions and I ended up with the error shared by the OP. I thought that using the bids filter file to choose the specific session might limit the search within that session folder. However, I might have misunderstood the functionality in this case and would greatly appreciate any help/guidance.

tsalo commented 7 months ago

What are the contents of your bids filter file?

ksreeniv commented 7 months ago

I used the same as in the example shown (added the contents below)

{
   "bold": {
      "session": ["01"],
      "task": ["rest"]
   }
}