mandymejia / BayesfMRI

BayesfMRI R package
GNU General Public License v3.0
24 stars 7 forks source link

Adapting for fMRIPrep; Surfaces Do Not Load (sphere mismatch) #16

Closed smeisler closed 2 years ago

smeisler commented 2 years ago

Hello,

I am adapting the HCP tutorial for fmriprep outputs. I generated CIFTI outputs with fmriprep's --cifti-output 91k argument. This dataset has 3 runs of data. Thus, fnames_ts, events_all, and confounds_all are size-3 lists, as described in the documentation. I use the following gifti file (left hemisphere example): /PATH/TO/fmriprep/SUBJECT/ses-1/anat/SUBEJCT_ses-1_hemi-L_midthickness.surf.gii. I am running into an error described below:

Command

results <- BayesGLM_cifti(
    cifti_fname = fnames_ts,
    surfL_fname = fname_gifti_left,
    surfR_fname = fname_gifti_right,
    brainstructures = c("left", "right"),
    onsets = events_all,
    TR = TR,
    nuisance = confounds_all,
    nuisance_include = c("drift", "dHRF"),
    scale_BOLD = TRUE,
    scale_design = TRUE,
    GLM_method = "both",
    ar_order = 6,
    ar_smooth = 5,
    session_names = c('run-1','run-2','run-3'),
    resamp_res = 10000,
    num.threads =  parallel::detectCores() - 2,
    verbose = TRUE,
    outfile = NULL,
    return_INLA_result = TRUE,
    avg_sessions = TRUE,
    trim_INLA = TRUE,
    keep = FALSE,
)

Error

SETTING UP DATA 
    Reading in data for session 1
Error in read_surf(surfL, "left"): The object could not be converted into a surface.
Traceback:

1. BayesGLM_cifti(cifti_fname = fnames_ts, surfL_fname = fname_gifti_left, 
 .     surfR_fname = fname_gifti_right, brainstructures = c("left", 
 .         "right"), onsets = events_all, TR = TR, nuisance = confounds_all, 
 .     nuisance_include = c("drift", "dHRF"), scale_BOLD = TRUE, 
 .     scale_design = TRUE, GLM_method = "both", ar_order = 6, ar_smooth = 5, 
 .     session_names = c("run-1", "run-2", "run-3"), resamp_res = 10000, 
 .     num.threads = parallel::detectCores() - 2, verbose = TRUE, 
 .     outfile = NULL, return_INLA_result = TRUE, avg_sessions = TRUE, 
 .     trim_INLA = TRUE, keep = FALSE, )
2. read_cifti(cifti_fname[ss], surfL_fname = surfL_fname, surfR_fname = surfR_fname, 
 .     brainstructures = brainstructures, resamp_res = resamp_res)
3. read_cifti_separate(cifti_fname, surfL_fname = surfL_fname, surfR_fname = surfR_fname, 
 .     brainstructures = brainstructures, idx = idx, resamp_res = resamp_res, 
 .     mwall_values = mwall_values, verbose = verbose, ...)
4. add_surf(xifti, surfL = surfL_fname)
5. read_surf(surfL, "left")
6. stop("The object could not be converted into a surface.")

While running:
/rdma/vast-rdma/vast/gablab/smeisler/workbench/bin_rh_linux64/../exe_rh_linux64/wb_command -surface-resample /net/oms.ib.cluster/om4/group/gablab/data/ds003126/derivatives/fmriprep/sub-047EPKL011005/ses-1/anat/sub-047EPKL011005_ses-1_hemi-L_midthickness.surf.gii /tmp/Rtmp49kVVm/sphereL_32492.surf.gii /tmp/Rtmp49kVVm/sphereL_10000.surf.gii BARYCENTRIC /tmp/Rtmp49kVVm/resampled_10000_sub-047EPKL011005_ses-1_hemi-L_midthickness.surf.gii

ERROR: input surface has different number of nodes than input sphere

While running:
/rdma/vast-rdma/vast/gablab/smeisler/workbench/bin_rh_linux64/../exe_rh_linux64/wb_command -surface-resample /net/oms.ib.cluster/om4/group/gablab/data/ds003126/derivatives/fmriprep/sub-047EPKL011005/ses-1/anat/sub-047EPKL011005_ses-1_hemi-R_midthickness.surf.gii /tmp/Rtmp49kVVm/sphereR_32492.surf.gii /tmp/Rtmp49kVVm/sphereR_10000.surf.gii BARYCENTRIC /tmp/Rtmp49kVVm/resampled_10000_sub-047EPKL011005_ses-1_hemi-R_midthickness.surf.gii

ERROR: input surface has different number of nodes than input sphere

More info

The surfaces will load with load_surf so I am confident it is not a simple path issue. The current commands seems to have no option to input spheres and instead deafults to that in /tmp/Rtmp49kVVm/sphereL_32492.surf.gii. I have matching sphere files from the templateflow directory. How can I incorporate those?

p.s. I would be happy to share my example fmriprep script when done, in case it can add to your documentation. I imagine it may be of interest to many fmriprep users.

Thanks, Steven

damondpham commented 2 years ago

Hi @smeisler , it seems like the CIFTI resolution might not match the surface geometry resolution.

If you do summary(read_xifti(fnames_ts)), what is the printed output? This will show the numbers of data vertices on the left and right hemispheres.

Then, if you do summary(read_surf(fname_gifti_left)), what is the printed output? This will show the numbers of vertices on the left surface geometry.

damondpham commented 2 years ago

By the way, load_surf reads in the surfaces included in the ciftiTools package. To read in your own file, e.g. /PATH/TO/fmriprep/SUBJECT/ses-1/anat/SUBEJCT_ses-1_hemi-L_midthickness.surf.gii, read_surf should be used instead.

smeisler commented 2 years ago

image

Yes, they are different. Hmm, I wonder why fMRIprep would output a gifti that is incompatable....

And yes, the read vs. load surf was a typo on my end.

smeisler commented 2 years ago

I found a compatible .gii from templateflow, and it seems to be past the error now. Thanks!

damondpham commented 2 years ago

Great! If you do want to use fname_gifti_left, another option is resampling it with resample_surf, setting resamp_res=32492.

smeisler commented 2 years ago

When I try that, I get the following error: test <- resample_surf(surf=fname_gifti_left, resamp_res = 32492, hemisphere='left')

Error in read_surf(surf = surf, expected_hemisphere = expected_hemisphere, : The object could not be converted into a surface.
Traceback:

1. resample_surf(surf = fname_gifti_left, resamp_res = 32492, hemisphere = "left")
2. make_surf(gii_post, hemisphere)
3. read_surf(surf = surf, expected_hemisphere = expected_hemisphere, 
 .     resamp_res = NULL)
4. stop("The object could not be converted into a surface.")

And (I cut out most of the error message because it is very big and repetitive, the last part is below): triangle 317355, vertex 0Vertex used twice in one triangle: triangle 317356, vertex 0Vertex used twice in one triangle: triangle 317356, vertex 0Vertex used twice in one triangle: triangle 317357, vertex 0Vertex used twice in one triangle: triangle 317357, vertex 0...

It seems to have that error for every triangle.

I can crosspost this in ciftiTools since this is more of an issue with that.

damondpham commented 2 years ago

Sure, that would be great if you could crosspost to ciftiTools! Would you mind attaching the surface file in question as well? Thanks for helping us iron out these issues.