As of version 1.2.0, four functions in VertexWiseR do surface data extraction and synthesis:
SURFvextract()
FSLRvextract()
CAT12vextract()
HIPvextract()
Surface extraction consists in reading through a preprocessing pipeline’s subjects directory, collating the surface data (for a chosen vertex-wise measure, e.g. thickness), and summarising it into one compact matrix R object, with N rows per subject and M columns per vertex values.
Surface extraction methods workflow
The functions save such objects as a .rds file. The file contains the R surface matrix and, with the default subj_ID setting, an appended list of the corresponding subjects ID. This file can be shared across any device with R and all VertexWiseR statistical analyses functions can be run on these, without the need to access the initially preprocessed data.
The demo data (218 MB) required to run the package demos can be downloaded from the package’s github repository with the following function:
#This will save the demo_data directory in a temporary directory (tempdir(), but you can change it to your own path)
demodata=VertexWiseR:::dl_demo(path=tempdir(), quiet=TRUE)
SURFvextract() extracts cortical surface data from a preprocessed FreeSurfer subjects directory (Fischl 2012).
The function makes use of internal FreeSurfer functions to resample every participant’s individual surface to fsaverage5 or fsaverage6. Therefore, it requires FreeSurfer to be installed and set in the environment where R is run and cannot be automatically run here.
For demonstration, we provide a subsample of 2 participants from the SPRENG dataset (Spreng et al. 2022), after preprocessing their surface data using FreeSurfer’s default recon-all pipeline. Certain files that were not needed (volumes, surfaces, label files) were removed to minimise the subsample’s size.
We give the following code as example:
SPRENG_CTv = SURFvextract(
sdirpath = paste0(demodata,'/spreng_surf_data_freesurfer'),
filename = "SPRENG_CTv.rds",
template='fsaverage5',
measure = 'thickness',
subj_ID = FALSE)
Here is an example of surface matrix object, extracted from FreeSurfer preprocessing of the all site 1 participants:
## [1] 238 20484
What dim(SPRENG_CTv) shows is that the matrix object contains the surface values of 238 participants, each with 20484 thickness values which correspond to the vertices of fsaverage5, both left-to-right hemispheres.
When the subj_ID argument is set to TRUE, the object returned is not a matrix on its own but a list containing both the matrix and an array listing the subject IDs from the directory. In our example: * SPRENG_CTv[[1]] will be the list of subject IDs * SPRENG_CTv[[2]] will be the matrix object
FSLRvextract() extracts cortical data in FSLR32k surface space from Human Connectome Project (HCP) (Van Essen et al. 2013), fMRIprep (Esteban et al. 2019) preprocessing output directories, as well as XCP-D (Mehta et al. 2024) postprocessing output directories . FSLRvextract() requires the HCP workbench to be installed, and uses the ciftiTools R package to read the .dscalar.nii files.
For demonstration, we provide a subsample of 2 participants from the SPRENG dataset (Spreng et al. 2022), after preprocessing their surface data using fMRIprep. The latter outputs fslr32k surface data when using the “–cifti-output” option (Esteban et al. 2019). Other anatomical files were removed and only the dscalar.nii and associated json files were preserved, to minimise its size.
FSLRvextract() gets the data from .dscalar.nii files associated with the specified measure (e.g. thickness, curv), and can extract it as follows (specify your own connectome workbench path):
dat_fslr32k=FSLRvextract(
sdirpath=paste0(demodata,"/spreng_surf_data/"),
wb_path="path/to/workbench",
filename="dat_fslr32k.rds",
dscaler="_space-fsLR_den-91k_thickness.dscalar.nii",
subj_ID = FALSE,
silent=FALSE)
Accordingly, the dat_fslr32k matrix will contain 2 rows (for 2 participants) and 64,984 columns (the subject’s cortical thickness values in every vertex of the fslr32k surface).
Additionally, the DTSERIESvextract() function can be used on an individual CIFTI dtseries.nii typically outputted in the same space by the fmriprep pipeline, to get one subject’s surface data across N time points.
CAT12vextract() was implemented in version 1.2.0 and can extract surface preprocessed with the CAT12 (Gaser et al. 2024) surface based morphometry pipeline. The function requires reticulate (Ushey, Allaire, and Tang 2023) to run.
For demonstration, we provide again a subsample of 2 participants from the SPRENG dataset (Spreng et al. 2022), after preprocessing their surface data using CAT12’s SBM pipeline (segmentation and resampling without smoothing), and extracting different possible surface measures. Only the 32k mesh .gii and .dat files were kept.
CAT12vextract() extracts surface data resampled to 32k meshes (with or without smoothing) and can be used as in this example:
CATsurf=CAT12vextract(
sdirpath=paste0(demodata,"/SPRENG_CAT12_subsample"),
filename='thickness.rds',
measure='thickness',
subj_ID = TRUE,
silent = FALSE)
Accordingly, the matrix will contained 2 rows (for 2 participants) and 64,984 columns (the subject’s cortical thickness values in every vertex of the 32k mesh):
#The surface object contains the surface matrix and the list of subjects ID (and session number if applicable)
names(CATsurf)
## [1] "sub_list" "surf_obj"
## [1] 2 64984
HIPvextract() extracts cortical data in CITI168 surface space from the HippUnfold preprocessing pipeline (DeKraker et al. 2023). As opposed to the other two functions, HIPvextract() does not require any system requirement.
For demonstration, we provide a subsample of 2 participants from the Fink dataset (Fink et al. 2021), after preprocessing their surface data using HippUnfold, keeping all output .gii files.
To extract and collate the data of the two participants, HIPvextract() can be run as follows:
hipp_surf=HIPvextract(sdirpath=paste0(demodata,
"/fink_surf_data"),
filename="hippocampal_surf.rds",
measure="thickness",
subj_ID = TRUE)
Note that when subjects directories have multiple sessions, the matrix object will contain N rows per participant and per session.
## [1] "sub-season101_ses-1" "sub-season101_ses-2" "sub-season101_ses-3"
## [4] "sub-season102_ses-1" "sub-season102_ses-2" "sub-season102_ses-3"
Here the matrix has 6 rows for 2 particiants with 3 sessions each; and 14,524 columns (the hippocampal thickness values in every vertex of the CITI168 surface).
## [1] 6 14524