Combining subcortical voxel labels with cortical label.gii in a cifti dlabel.nii atlas file

Summary of what happened:

Hi all!

I am trying to build an external custom BIDS atlas to import within xcp_d to extract custom connectivity matrices. To do so, I need to create a dlabel.nii file containing my left/right cortical labels and subcortical labels. For the cortical labels, I have two gifti files: child_164k_L.label.gii and child_164k_R.label.gii. For the subcortical label, I have a single nifti file: BN_child_subcortical.nii.gz. The final atlas needs to be in 32k space. For now, here are the steps I used (see code below):

  1. Add label data to the subcortical volume
  2. Combine both hemispheres and subcortical data into a single dlabel.nii file in 164k space.
  3. Resample the dlabel.nii file in the 32k space.

Everything seems to run fine (no specific log), and I can visualize my cortical labels in wb_view (unsure how to visualize subcortical labels though):

However, when I run xcp_d, I obtain FC for every cortical pairs, but only N/A for the subcortical regions.

I’ve searched other topics and resources, but every solutions did not seem to work in my specific use case. Anyone has a suggestion I could try? I can share the required files if necessary.

Command used (and if a helper script was used, a link to the helper script or the command generated):

# Create a cifti header in the nifit file.
wb_command -volume-label-import ${WDIR}/temp/BN_child_subcortical.nii.gz ${WDIR}/BN_child_parcel_labels.txt ${WDIR}/temp/BN_child_subcortical.nii -drop-unused-labels

# Create the 164k version of the dense nifti files.
wb_command -cifti-create-label ${WDIR}/temp/atlas-BrainnetomeChild_space-fsLR_den-164k_dseg.dlabel.nii \
    -volume ${WDIR}/temp/BN_child_subcortical.nii ${WDIR}/temp/BN_child_subcortical.nii \
    -left-label ${LEFT_ATLAS} \
    -right-label ${RIGHT_ATLAS}

# Resample the 164k dense nifti files to 32k using fsaverage spheres.
wb_command -cifti-resample ${WDIR}/temp/atlas-BrainnetomeChild_space-fsLR_den-164k_dseg.dlabel.nii COLUMN \
    ${REFERENCE} COLUMN BARYCENTRIC ENCLOSING_VOXEL temp/atlas-BrainnetomeChild_space-fsLR_den-32k_dseg.dlabel.nii \
    -left-spheres ${TEMPLATEFLOW_HOME}/tpl-fsLR/tpl-fsLR_space-fsaverage_hemi-L_den-164k_sphere.surf.gii ${TEMPLATEFLOW_HOME}/tpl-fsLR/tpl-fsLR_space-fsaverage_hemi-L_den-32k_sphere.surf.gii \
    -right-spheres ${TEMPLATEFLOW_HOME}/tpl-fsLR/tpl-fsLR_space-fsaverage_hemi-R_den-164k_sphere.surf.gii ${TEMPLATEFLOW_HOME}/tpl-fsLR/tpl-fsLR_space-fsaverage_hemi-R_den-32k_sphere.surf.gii

Version:

Connectome Workbench
Type: Command Line Application
Version: 2.0.1
Qt Compiled Version: 6.2.3
Qt Runtime Version: 6.2.3
Commit: 150de12f4f4b94b39bec6d9133ad2e7019d2d3ef
Commit Date: 2024-10-15 17:38:41 -0500
Compiler: c++ (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin)
Compiler Version: 13.0.0.13000029
Compiled Debug: NO
Operating System: Apple OSX
Compiled with OpenMP: YES

Environment (Docker, Singularity / Apptainer, custom installation):

Source install.

Data formatted according to a validatable standard? Please provide the output of the validator:

#Not relevant here

Relevant log outputs (up to 20 lines):

# No logs outputs.

For the sake of others who might want to perform a similar thing as what I am trying to do here, here is the solution I found:

The first is still to import the labels within the subcortical volume file to create the cifti header:

# Create a cifti header in the nifit file.
wb_command -volume-label-import ${WDIR}/temp/BN_child_subcortical.nii.gz ${WDIR}/refs/BN_child_parcel_labels.txt ${WDIR}/temp/BN_child_subcortical.nii -drop-unused-labels

Then, directly resample the volume into the final desired space (32k for me) using a reference subcortical volume:

# Resample into 32k space.
wb_command -volume-resample ${WDIR}/temp/BN_child_subcortical.nii ${REFERENCE_VOL} ENCLOSING_VOXEL ${WDIR}/temp/BN_child_subcortical_32k.nii

Combine both my left/right gifti files into a dlabel.nii, then resample it in the 32k space (using a reference dlabel.nii file in 32k space without subcortical data):

# Create the 164k version of the dense nifti files.
wb_command -cifti-create-label ${WDIR}/temp/atlas-BrainnetomeChild_space-fsLR_den-164k_dseg.dlabel.nii \
    -left-label ${LEFT_ATLAS} \
    -right-label ${RIGHT_ATLAS}

# Resample the 164k dense nifti files to 32k using fsaverage spheres.
wb_command -cifti-resample ${WDIR}/temp/atlas-BrainnetomeChild_space-fsLR_den-164k_dseg.dlabel.nii COLUMN \
    ${REFERENCE} COLUMN BARYCENTRIC ENCLOSING_VOXEL temp/atlas-BrainnetomeChild_space-fsLR_den-32k_dseg.dlabel.nii \
    -left-spheres ${TEMPLATEFLOW_HOME}/tpl-fsLR/tpl-fsLR_space-fsaverage_hemi-L_den-164k_sphere.surf.gii ${TEMPLATEFLOW_HOME}/tpl-fsLR/tpl-fsLR_space-fsaverage_hemi-L_den-32k_sphere.surf.gii \
    -right-spheres ${TEMPLATEFLOW_HOME}/tpl-fsLR/tpl-fsLR_space-fsaverage_hemi-R_den-164k_sphere.surf.gii ${TEMPLATEFLOW_HOME}/tpl-fsLR/tpl-fsLR_space-fsaverage_hemi-R_den-32k_sphere.surf.gii

The final step I missed earlier is to combine the subcortical volume with the dlabel.nii file using the wb_command -cifti-create-dense-from-template. Using a reference file with subcortical data allows the correct mapping of the subcortical voxels into each structure. I used the Tian atlas (32k space):

# Add subcortical data by creating a dense city file from the template.
wb_command -cifti-create-dense-from-template ${REFERENCE_CIFTI} \
    ${WDIR}/temp/atlas-BrainnetomeChild_space-fsLR_den-32k_dseg.dlabel.nii \
    -volume-all ${WDIR}/temp/BN_child_subcortical_32k.nii \
    -cifti ${WDIR}/temp/atlas-BrainnetomeChild_space-fsLR_den-32k_dseg.dlabel.nii

Supplying the newly created atlas to xcp_d gave a full connectivity matrice with subcortical structures. Cheers!