CoBrALab / RABIES

fMRI preprocessing pipeline and analysis tools adapted for rodent images. Visit the full documentation at https://rabies.readthedocs.io/en/stable/
Other
34 stars 14 forks source link

Indexing error during analysis (load_sub_input_dict) #340

Open essheh opened 11 months ago

essheh commented 11 months ago

Bug description I'm currently running RABIES on the dataset available at this adress https://data.mendeley.com/datasets/fmb2fwb53f/2 , the preprocess and the confound corrections seems to be working fine, but when I run the analysis outputs for some subjects of the dataset (3, 9, 10, 11) an indexing error happens ("IndexError: boolean index did not match indexed array along dimension 2; dimension is 52 but corresponding boolean dimension is 53") see analysis log file for more details.

RABIES calls I am running the following scripts:

Preprocess:

rabies_2.sif --p MultiProc preprocess /input_BIDS/ /preprocess_outputs/ \
--bold_only --bold_autobox --bold_inho_cor method=Rigid,otsu_thresh=2,multiotsu=false \
--commonspace_reg masking=true,brain_extraction=true,template_registration=SyN,fast_commonspace=false \
--apply_STC --TR 1.0 \
--labels $PWD/LABELS/Oh_annotation_2000_DSURQE_space_40_um_brain_masked.nii.gz \
--anat_template $PWD/LABELS/DSURQE_40micron_average.nii.gz \
--brain_mask /LABELS/DSURQE_40micron_mask.nii.gz \
--WM_mask $PWD/LABELS/DSURQE_40micron_eroded_WM_mask.nii.gz \
--CSF_mask  $PWD/LABELS/DSURQE_40micron_eroded_CSF_mask.nii.gz \ 
--vascular_mask $PWD/LABELS/vascular_mask.nii.gz

Confoud correction:

rabies_2.sif --p MultiProc confound_correction /preprocess_outputs/ /confound_correction_outputs/ \
--image_scaling global_variance \
--detrending_order linear \
--frame_censoring FD_censoring=true,FD_threshold=0.05,DVARS_censoring=false,minimum_timepoint=1200 \
--conf_list mot_6 \
--TR 1.0 \
--smoothing_filter 0.3 \
--timeseries_interval 120,1920

Analysis:

rabies_2.sif --p MultiProc \
analysis /confound_correction_outputs/ /analysis_outputs/ \
--prior_maps /LABELS/melodic_IC.nii.gz \
--ROI_csv $PWD/LABELS/Oh_ROI.csv --FC_matrix

Log files rabies_preprocess.log rabies_confound_correction.log rabies_analysis.log

gdevenyi commented 11 months ago

What version are you using?

essheh commented 11 months ago

0.5.1 , the error also happened using 0.5.0

gdevenyi commented 11 months ago

Can you please try to reproduce with ghcr.io/cobralab/rabies:nightly

gdevenyi commented 11 months ago

Hi,

Unless you're fixing this, this dataset is not properly oriented according to the NIFTI standard: image image

RABIES assumes properly oriented data, so processing issues are likely arising from this.

gdevenyi commented 11 months ago

If you look at the preprocessing QC outputs, you will likely see things were are "very wrong".

essheh commented 11 months ago

I should have specified that I fixed the orientation and the spacing (which was in cm instead of mm) before using the dataset, the preprocessing QC outputs look fine for every image. I'm currently trying to reproduce the error with hcr.io/cobralab/rabies:nightly. The code is currently running I should have the results in about two hours. github_image

essheh commented 11 months ago

After trying with the ghcr.io/cobralab/rabies:nightly version the problem is still not solved. Here is the new log rabies_analysis.log. The preprocess and confound correction steps still seem to be working correctly.

essheh commented 11 months ago

I think I might have a lead as what could be causing the problem.

After the preprocessing, the functionnal images don't have all the same dimensions in the coronal slices. Some are 52x40 pixels (the problematic images) and the other are 53x40. This is interesting because the missing index is 53 for the problematic subjects (see first post). I'm wondering if this could be caused by the the --bold_autobox command, not cropping out the same amount for all images.

Now, I'm currently to preprocess my dataset whitout --bold_autobox to confirm if the command is causing or not the error.

Gab-D-G commented 11 months ago

Hi @essheh , sorry for the delays on my end, and thank for investigating this. I looked into it, and my suspicion is that your images don't have the same voxel resolution, and since RABIES preserves original image dimension by default, the inconsistent dimensions cause an error at the analysis stage. This is something I should fix. However, this does mean however you cannot run any group-wise analyses like group-ICA (unless MELODIC allows it somehow), as your images don't currently align. Something that would fix your issue with the current RABIES version would be to resample your images to the same resolution in commonspace using the --commonspace_resampling parameter during preprocessing. I'll work on a better fix to the issue separately.

essheh commented 11 months ago

Hi @Gab-D-G , you were absolutely right, for some reasons, my images had really small differences in voxel resolution in one of the dimensions and that was exactly what was causing the errors. I've fixed my problem by redefining the resolution in all my images to be the same.

So thank you for your help! Also, congratulation on building this fMRI rodent pipeline, during my master I've tried many ways of doing functionnal connectivity analysis and it's been by far the easiest (thanks to Docker) and most unconstrained way of doing it that I've found.