FCP-INDI / C-PAC

Configurable Pipeline for the Analysis of Connectomes
https://fcp-indi.github.io/
GNU Lesser General Public License v3.0
62 stars 40 forks source link

🐛 [slice timing] unmatched tpattern and slices #2145

Open suxpert opened 2 weeks ago

suxpert commented 2 weeks ago

Describe the bug

I have some functional data which covers only half of the brain, and with slice setting to almost perpendicular to anterior-posterior, i.e., coronal slices.

fmriprep works fine for this data, and because I failed run C-PAC on top of fmriprep's result, I tried with the raw data in BIDS. Still without any lucky, C-PAC failed with following errors:

Traceback (most recent call last):
  File "/usr/share/fsl/6.0/lib/python3.10/site-packages/nipype/pipeline/plugins/linear.py", line 47, in run
    node.run(updatehash=updatehash)
  File "/code/CPAC/pipeline/nipype_pipeline_engine/engine.py", line 443, in run
    return super().run(updatehash)
  File "/usr/share/fsl/6.0/lib/python3.10/site-packages/nipype/pipeline/engine/nodes.py", line 527, in run
    result = self._run_interface(execute=True)
  File "/usr/share/fsl/6.0/lib/python3.10/site-packages/nipype/pipeline/engine/nodes.py", line 645, in _run_interface
    return self._run_command(execute)
  File "/usr/share/fsl/6.0/lib/python3.10/site-packages/nipype/pipeline/engine/nodes.py", line 771, in _run_command
    raise NodeExecutionError(msg)
nipype.pipeline.engine.nodes.NodeExecutionError: Exception raised while executing Node slice_timing.

Cmdline:
        3dTshift -prefix sub-0358_task-rest_run-01_bold_resample_calc_tshift.nii.gz -tpattern @/out/working/pipeline_cpac_preproc/cpac_sub-0358_ses-1/_scan_rest_run-01/bold_scan_params_sub-0358_ses-1/tpattern.txt -TR 1.5s /out/working/pipeline_cpac_preproc/cpac_sub-0358_ses-1/func_slice_timing_correction_122/_scan_rest_run-01/slice_timing/sub-0358_task-rest_run-01_bold_resample_calc.nii.gz
Stdout:

Stderr:
        ++ 3dTshift: AFNI version=AFNI_23.3.09 (Dec  8 2023) [64-bit]
        ** FATAL ERROR: tpattern file /out/working/pipeline_cpac_preproc/cpac_sub-0358_ses-1/_scan_rest_run-01/bold_scan_params_sub-0358_ses-1/tpattern.txt has 66 values but have 96 slices
        ** Program compile date = Dec  8 2023
Traceback:
        Traceback (most recent call last):
          File "/usr/share/fsl/6.0/lib/python3.10/site-packages/nipype/interfaces/base/core.py", line 453, in aggregate_outputs
            setattr(outputs, key, val)
          File "/usr/share/fsl/6.0/lib/python3.10/site-packages/nipype/interfaces/base/traits_extension.py", line 330, in validate
            value = super(File, self).validate(objekt, name, value, return_pathlike=True)
          File "/usr/share/fsl/6.0/lib/python3.10/site-packages/nipype/interfaces/base/traits_extension.py", line 135, in validate
            self.error(objekt, name, str(value))
          File "/usr/share/fsl/6.0/lib/python3.10/site-packages/traits/base_trait_handler.py", line 74, in error
            raise TraitError(
        traits.trait_errors.TraitError: The 'out_file' trait of a TShiftOutputSpec instance must be a pathlike object or string representing an existing file, but a value of '/out/working/pipeline_cpac_preproc/cpac_sub-0358_ses-1/func_slice_timing_correction_122/_scan_rest_run-01/slice_timing/sub-0358_task-rest_run-01_bold_resample_calc_tshift.nii.gz' <class 'str'> was specified.

        During handling of the above exception, another exception occurred:

        Traceback (most recent call last):
          File "/code/CPAC/pipeline/nipype_pipeline_engine/monkeypatch.py", line 43, in run
            outputs = self.aggregate_outputs(runtime)
          File "/usr/share/fsl/6.0/lib/python3.10/site-packages/nipype/interfaces/base/core.py", line 460, in aggregate_outputs
            raise FileNotFoundError(msg)
        FileNotFoundError: No such file or directory '/out/working/pipeline_cpac_preproc/cpac_sub-0358_ses-1/func_slice_timing_correction_122/_scan_rest_run-01/slice_timing/sub-0358_task-rest_run-01_bold_resample_calc_tshift.nii.gz' for output 'out_file' of a TShift interface

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/code/CPAC/pipeline/cpac_pipeline.py", line 578, in run_workflow
    workflow_result = workflow.run(plugin=plugin,
  File "/usr/share/fsl/6.0/lib/python3.10/site-packages/nipype/pipeline/engine/workflows.py", line 638, in run
    runner.run(execgraph, updatehash=updatehash, config=self.config)
  File "/usr/share/fsl/6.0/lib/python3.10/site-packages/nipype/pipeline/plugins/linear.py", line 82, in run
    raise error from cause
RuntimeError: 2 raised. Re-raising first.

1700 might be the same issue, but 2 years have passed without further update.

To reproduce

No response

Preconfig

Custom pipeline configuration

No response

Run command

docker run -it --rm -u $(id -u) -v $BIDS:/data:ro -v $BIDS/derivatives/cpac:/out fcpindi/c-pac --preconfig preproc /data /out participant

Expected behavior

I would expect the preproc pipeline be able to run successfully since this is very simple BIDS dataset that has been validated via bida-validator and is nothing wrong for fmriprep.

Acceptance criteria

Screenshots

Here are crash and log files:

C-PAC version

v1.8.7

Container platform

Docker

Docker and/or Singularity version(s)

Docker version 26.1.5-ce

Additional context

$ fslsize bids-new3/sub-0151/func/sub-0151_task-rest_run-01_bold
dim1            116
dim2            96
dim3            66
dim4            200
pixdim1         1.458330
pixdim2         1.458330
pixdim3         1.500000
pixdim4         1.500000

$ jq -r '.SliceTiming | length' bids-new3/sub-0151/func/sub-0151_task-rest_run-01_bold.json
66
tamsinrogers commented 2 weeks ago

Hi @suxpert, thanks for reaching out.

C-PAC correctly applied slice timing correction and go without further issue It looks like your data data has the slice-timing info in the sidecar, but it’s either missing from the header or on a different axis than expected. Since fmriprep gets the slicetiming from the sidecar and you already have it in the sidecar, you can

  1. extract that array into a tpattern file for AFNI 3dTShift (just numbers and spaces in a text file)
  2. bind that tpattern file to your container
  3. run with a config file like:
    FROM: preproc
    functional_preproc:
    slice_timing_correction:
        tpattern: path/to/that/tpattern/file.txt

C-PAC accept turning off slice timing correction from command line rather than edit the terrified pipeline config files (which is hard for me because it is too complex for beginners and without detailed documents)

A pipeline config like this should run the preproc preconfig minus slice timing correction:

FROM: preproc
functional_preproc:
    slice_timing_correction:
        run: Off

There is documentation here for making small changes to a configuration and here for slice-timing settings. Looking at the slice-timing docs, it looks like instead of putting the tpattern file in the pipeline config, you could make that file and put its path in the “Acquisition” column of your scan_parameters.csv or scan_parameters_multiscan.csv file. Note: Scan parameter information specified for slice timing correction will override the settings specified in the pipeline configuration YAML.

Hopefully some of this helps with the issue you are having. It would also be helpful for us to know know what your expectations are for the CLI and documentation here, specifically. Any additional information helps us make improvements to C-PAC!

suxpert commented 2 weeks ago

I regard the config file as terrified since it:

tamsinrogers commented 2 weeks ago

Hi @suxpert,

Thank you for the update. If specifying the tpattern in the following ways has not resolved this issue, we can replicate on our end and get back to you with some more information. Specifying your intended use case, if you are able, will also help us do this!

  1. in config file

    FROM: preproc
    functional_preproc:
    slice_timing_correction:
        tpattern: path/to/that/tpattern/file.txt 
  2. make that file and put its path in the “Acquisition” column of your scan_parameters.csv or scan_parameters_multiscan.csv file

Here is some additional information relating to C-PAC configuration: