MSHBM implementation in clinical trial: potential collaboration with UCSF

80 views
Skip to first unread message

lorenzo pasquini

unread,
Sep 14, 2024, 1:13:42 AM9/14/24
to CBIG users

Hi there,

 

I was wondering whether someone could help me with the following question.

I am trying to run  the example for the “simple way” of generating individual parcellations.

https://github.com/ThomasYeoLab/CBIG/tree/master/stable_projects/brain_parcellation/Kong2022_ArealMSHBM/examples

 

I am running the code using the enclosed script on our computational linux system.

 

The error message that I am receiving (see below) seems to be related to lines 182 and 148 in script CBIG_ArealMSHBM_generate_gradient.m. I think this error is resulting from the “space” after sh in the piece code below:

    cmd = ['sh ' CBIG_CODE_DIR '/utilities/matlab/speedup_gradients/CBIG_SPGrad_diffusion_embedding.sh '...

 

Error:

#########################

Construct graph ...

Elapsed time is 0.128935 seconds.

Compute pairwise shortest distance ...

Elapsed time is 7.734629 seconds.

Save as NPY format ...

########## Done!

sh: 0: cannot open /utilities/matlab/speedup_gradients/CBIG_SPGrad_diffusion_embedding.sh: No such file

Error using CBIG_SPGrad_upsample_embed_matrix (line 49)

Cannot find diffusion embedding matrix for left hemisphere

 

Error in CBIG_ArealMSHBM_generate_gradient (line 185)

    CBIG_SPGrad_upsample_embed_matrix(mesh, medial_mask, 100, out_gradient_dir);

 

Error in CBIG_ArealMSHBM_parcellation_single_subject (line 384)

        CBIG_ArealMSHBM_generate_gradient(target_mesh, project_dir, '1' , num2str(num_sess));

 

Error in test_cbig_cer (line 21)

[lh_labels, rh_labels] = CBIG_ArealMSHBM_parcellation_single_subject(params);

 

Error in run (line 112)

evalin('caller', strcat(scriptStem, ';'));

 

Yet, if I remove that space in those two location, I still get an error:

#########################

Construct graph ...

Elapsed time is 0.132370 seconds.

Compute pairwise shortest distance ...

Elapsed time is 7.674953 seconds.

Save as NPY format ...

########## Done!

sh: 0: cannot open /utilities/matlab/speedup_gradients/CBIG_SPGrad_diffusion_embedding.sh/home/lollopasquini/test_cbig2/gradients/sub1: No such file

Error using CBIG_SPGrad_upsample_embed_matrix (line 49)

Cannot find diffusion embedding matrix for left hemisphere

 

Error in CBIG_ArealMSHBM_generate_gradient (line 185)

    CBIG_SPGrad_upsample_embed_matrix(mesh, medial_mask, 100, out_gradient_dir);

 

Error in CBIG_ArealMSHBM_parcellation_single_subject (line 384)

        CBIG_ArealMSHBM_generate_gradient(target_mesh, project_dir, '1' , num2str(num_sess));

 

Error in test_cbig_cer (line 21)

[lh_labels, rh_labels] = CBIG_ArealMSHBM_parcellation_single_subject(params);

 

Error in run (line 112)

evalin('caller', strcat(scriptStem, ';'));

 

Have you ever encountered this? Any advice on how to solve it?

Any advice would be greatly appreciated.

Warmly


Lorenzo

test_cbig_cer[96].m

Ruby Kong

unread,
Sep 26, 2024, 4:01:59 AM9/26/24
to lorenzo pasquini, CBIG users
Hi Lorenzo,

The spaces shouldn't matter. The issue seems due to the global environment variable "CBIG_CODE_DIR" can not be identified. This is a variable we set in your environment:

To check it, can you set a breakpoint at this line (below) and check if "CBIG_CODE_DIR" is empty or not? To check it, you can simply type CBIG_CODE_DIR and press enter and see if it returns a empty string.
cmd = ['sh ' CBIG_CODE_DIR '/utilities/matlab/speedup_gradients/CBIG_SPGrad_diffusion_embedding.sh '...
--
You received this message because you are subscribed to the Google Groups "CBIG users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cbig_users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cbig_users/3e62bb40-d938-4ce7-a9b4-202624f70891n%40googlegroups.com.

lorenzo pasquini

unread,
Oct 1, 2024, 7:20:28 PM10/1/24
to Ruby Kong, CBIG users
Thanks Ruby, 

what I am unclear about, is which configuration file I should copy to run your 2022 "standalone" code.
i cannot find any configuration file in Kong2019 or Kong2022. Should I use the standard configuration file?
CBIG_sample_config.sh

Ruby Kong

unread,
Oct 1, 2024, 8:49:51 PM10/1/24
to lorenzo pasquini, CBIG users
Hi Lorenzo,

Yes the standard config works!

Best,

Ruby

Sent from my iPhone

On 2 Oct 2024, at 7:20 AM, lorenzo pasquini <lollop...@gmail.com> wrote:



lorenzo pasquini

unread,
Oct 2, 2024, 2:03:52 AM10/2/24
to Ruby Kong, CBIG users
Thanks Ruby,

the issue was indeed with the setup, more specifically with setting up the anaconda and python environment properly.
I wonder whether that part could be made clearer on the instructions?

Do you also have scripts to use the parcellations to derive the time series for the parcels?
My original data is in 92k space, the parcels seem to be in 32k space.
Do I need to downsample the data?

Many thanks for all your help so far.

Best

Lorenzo

Ruby Kong

unread,
Oct 2, 2024, 3:24:43 AM10/2/24
to lorenzo pasquini, CBIG users
Hi Lorenzo,

Is it the same data you send me previously? If so you can directly use your data. 32k is the number of cortical vertices per hemi. left+right is around 64k, plus subcortical part will be around 95k. My script will only take cortical part.

lorenzo pasquini

unread,
Oct 2, 2024, 1:45:46 PM10/2/24
to Ruby Kong, CBIG users
Thanks Ruby. Yes it is the same data!
I was more referring to:
1. How can I see the individual parcellation atlas? Like go from the .mat file to nifti or some other format to see where the ROIs are located in the brain?
2. On a similar note, what tools do you usually use to generate the whole brain connectivity matrix you showed me recently?, Like, go from the dtseries.nii format to a 3d nii format?

Sorry for all these questions. I am more used to a volumetric approach and just started getting used to cifti, surface analyses, etc.
I'd appreciate any advice.

Best

Lorenzo

lorenzo pasquini

unread,
Oct 7, 2024, 7:57:20 PM10/7/24
to Ruby Kong, CBIG users
Hi Ruby,

I was wondering whether you could help me with a previous email.

Could you advise on a set of tools or scripts I could use to:
1. how to visualize the .mat files resulting from the parcellation into a brain map 
2. how to use the .mat files to generate seed-to-whole brain maps and visualize these
3. I used the .mat files from the aprfellation to generate a roi-to-toi iFC matrix. Yet, the values look off scale to me (range -0.1 to 1).
Anything obvious that ocul shave gone wrong here?

Any advice would be very much appreciated.

Best

Lorenzo

lorenzo pasquini

unread,
Oct 7, 2024, 7:58:17 PM10/7/24
to Ruby Kong, CBIG users
sorry, forgot yo attach the iFC matrix. Now eneclosed.

best
Screen Shot 2024-10-07 at 7.54.23 PM.png

Ruby Kong

unread,
Oct 7, 2024, 9:48:41 PM10/7/24
to lorenzo pasquini, CBIG users
Hi Lorenzo,

To visualize the parcellation you can use our CBIG function. The color will be random:
CBIG_DrawSurfaceMaps_fslr(lh_data,rh_data,'fs_LR_32k','very_inflated', 1, 400, rand(401,3));

To do the seed-to-whole brain analysis we didn't have any script, you can extract vertices within a ROI and compute mean time series and then correlate it with the 64k vertices.

Are you using the individualized 400 ROIs to compute the FC? Or Schaefer group-level parcellation? To visualize your 400X400 FC you can consider using our script, this will reorder the ROIs so FC will have a better network structure.
CBIG_PlotCorrMatNetOrder(400, FC_gMSHBM, 'Schaefer_Kong17',[-5,5])
[-5,-5] is the colormap range you can change accordingly. 

If you find your FC weird, I suggest you compute FC using both individual 400 ROIs and Schaefer group-level 400 ROIs. They shouldn't look super different.

lorenzo pasquini

unread,
Oct 8, 2024, 5:22:17 PM10/8/24
to Ruby Kong, CBIG users
Hi Ruby

thank you so much for sharing the code.

I think the parcellations look good and the matrix values are in line with what I get with my custom code.
The range is very different from what I would get with a schaeffer atlas in volumetric space.

Is there a Schaeffer atlas 92K on the toolbox I could use to compare in cifti space?
Could it be that the parcellation was suboptimal since I used only two rs-fMRI runs?
Lastly, to generate seed-to-whole brain maps and visualize these, do you usually use the connectome workbench commands or some other tools?

Thank you so much for all your help so far, I really appreciate it.
Best

Lorenzo

Screen Shot 2024-10-08 at 5.18.44 PM.png

Ruby Kong

unread,
Oct 8, 2024, 11:05:16 PM10/8/24
to lorenzo pasquini, CBIG users
Oh the structure looks quite weird. For your reference, here is how I compute FC for HCP data which should be in the same format as yours:
% read in the fMRI data

tmp = ft_read_cifti('/mnt/isilon/CSC1/Yeolab/Data/HCP/S1200/individuals/100206/MNINonLinear/Results/rfMRI_REST1_LR/postprocessing/MSM_reg_wbsgrayordinatecortex/rfMRI_REST1_LR_Atlas_MSMAll_hp2000_clean_regress.dtseries.nii');
vol = tmp.dtseries;
vol(64985:end,:)=[];

% read in the censor file and exlude the outlier frames
censor_file = '/mnt/isilon/CSC1/Yeolab/Data/HCP/S1200/individuals/100206/MNINonLinear/Results/rfMRI_REST1_LR/postprocessing/MSM_reg_wbsgrayordinatecortex/scripts/rfMRI_REST1_LR_FD0.2_DV75_censoring.txt';
fid = fopen(censor_file, 'r');
mask_index = fscanf(fid,'%d');
vol(:,mask_index == 0) = [];

% find the medial mask, in HCP data, medial wall vertices will have NaN rows
medial_mask = find(isnan(mean(vol,2))==1);

% read in the parcellation
CBIG_CODE_DIR = getenv('CBIG_CODE_DIR');
parcel = ft_read_cifti([CBIG_CODE_DIR '/stable_projects/brain_parcellation/Schaefer2018_LocalGlobal/Parcellations/HCP/fslr32k/cifti/Schaefer2018_400Parcels_17Networks_order.dlabel.nii'],'mapname','array');
labels = parcel.dlabel;

for roi = 1:400
    ROIs_series(roi,:) = CBIG_nanmean(vol(labels == roi, :));
end

corr_mat = CBIG_self_corr(ROIs_series');
The Schaefer atlas can be found here:

You can check the following section for how to read it in matlab:

1.2 Read .dlabel.nii file

The parcellation file is saved as .dlabel.nii file as cifti format. Here, I am using the Schaefer parcellation with 400 parcels as the example.
If you read the parcellation in the same way as the .dtseries.nii file:

CBIG_CODE_DIR = getenv('CBIG_CODE_DIR'); parcel = ft_read_cifti([CBIG_CODE_DIR '/stable_projects/brain_parcellation/Schaefer2018_LocalGlobal/Parcellations/HCP/fslr32k/cifti/Schaefer2018_400Parcels_Kong2022_17Networks_order.dlabel.nii']); 

You can only obtain the parcellation labelling in parcel.parcels, which is a 64984 x 1 vector. The medial wall area is denoted as 0. There is no information about the labelnames for the 400 Schaefer parcels. Therefore, you need to pass in extra input arguments:

CBIG_CODE_DIR = getenv('CBIG_CODE_DIR'); parcel = ft_read_cifti([CBIG_CODE_DIR '/stable_projects/brain_parcellation/Schaefer2018_LocalGlobal/Parcellations/HCP/fslr32k/cifti/Schaefer2018_400Parcels_Kong2022_17Networks_order.dlabel.nii'],'mapname','array'); 

In this way, the parcellation labelling is saved in parcel.dlabel, the parcellation labelnames can be found in parcel.dlabellabel.
Important Note
The Schaefer parcellations in fs_LR_32k has a different medial wall mask as the original fs_LR_32k mesh. This is because the Schaefer parcellations were originally derived using GSP data in fsaverage6 space, and then we project the parellations from fsaverage6 to fs_LR_32k space. Therefore, the medial wall area for Schaefer parcellations in fs_LR_32k are actually the medial wall of fsaverage6 projected to fs_LR_32k.

For the vertex level seed analysis we use wb_view to explore because it allows you to click a seed anywhere in the cortex and then visualize it. To do that need to first compute a NbyN (N will be 64k in your case) correlation matrix and then save it as a dconn file. Our lab created our own script to do it:

https://github.com/ThomasYeoLab/CBIG/blob/master/utilities/matlab/fslr_matlab/CBIG_write_correlation_matrix_into_ciftiformat.m

lorenzo pasquini

unread,
Oct 9, 2024, 4:37:51 PM10/9/24
to Ruby Kong, CBIG users
thank you so much Ruby! Removing nans made the magic, I think:)
Screen Shot 2024-10-09 at 4.33.19 PM.png

Ruby Kong

unread,
Oct 9, 2024, 9:33:42 PM10/9/24
to lorenzo pasquini, CBIG users
Awesome! Greate it solves the problem!

-- Ruby

Ruby Kong

unread,
Oct 9, 2024, 9:36:36 PM10/9/24
to lorenzo pasquini, CBIG users
Just another quick note. For Schaefer atlases we have different versions. They are actually the same parcels but the parcels are ordered differently, means that parcel1 in versionA could be parcel2 in versionB. In my previous email, my FC script example is using Schaefer2018_400Parcels_17Networks_order.dlabel.nii'. But for your case you should use Schaefer2018_400Parcels_Kong2022_17Networks_order.dlabel.nii.
Reply all
Reply to author
Forward
0 new messages