Learn R Programming

⚠️There's a newer version (0.17.4) of this package.Take me there.

ciftiTools

CIFTI files contain brain imaging data in “grayordinates,” which represent the gray matter as cortical surface vertices (left and right) and subcortical voxels (cerebellum, basal ganglia, and other deep gray matter). ciftiTools provides a unified environment for reading, writing, visualizing and manipulating CIFTI-format data. It supports the “dscalar,” “dlabel,” and “dtseries” intents. Greyordinate data is read in as a "xifti" object, which is structured for convenient access to the data and metadata, and includes support for surface geometry files to enable spatially-dependent functionality such as static or interactive visualizations and smoothing.

Installation

You can install ciftiTools from CRAN with:

install.packages("ciftiTools")

Additionally, most of the ciftiTools functions require the Connectome Workbench, which can be installed from the HCP website.

Quick start guide

# Load the package and point to the Connectome Workbench --------
library(ciftiTools)
ciftiTools.setOption("wb_path", "path/to/workbench")

# Read and visualize a CIFTI file -------------------------------
cifti_fname <- ciftiTools::ciftiTools.files()$cifti["dtseries"]
surfL_fname <- ciftiTools.files()$surf["left"]
surfR_fname <- ciftiTools.files()$surf["right"]

xii <- read_cifti(
  cifti_fname, brainstructures="all", 
  surfL_fname=surfL_fname, surfR_fname=surfR_fname,
  resamp_res=4000
)

view_xifti_surface(xii) # or plot(xii)
# view_xifti_volume(xii) if subcortex is present

# Access CIFTI data ---------------------------------------------
cortexL <- xii$data$cortex_left
cortexL_mwall <- xii$meta$medial_wall_mask$left
cortexR <- xii$data$cortex_right
cortexR_mwall <- xii$meta$medial_wall_mask$right
# subcortVol <- xii$data$subcort
# subcortLabs <- xii$meta$subcort$labels
# subcortMask <- xii$meta$subcort$mask
surfL <- xii$surf$cortex_left
surfR <- xii$surf$cortex_right

# Create a `"xifti"` from data ----------------------------------
xii2 <- as.xifti(
  cortexL=cortexL, cortexL_mwall=cortexL_mwall,
  cortexR=cortexR, cortexR_mwall=cortexR_mwall,
  #subcortVol=subcortVol, subcortLabs=subcortLabs,
  #subcortMask=subcortMask,
  surfL=surfL, surfR=surfR
)

# Write a CIFTI file --------------------------------------------
write_cifti(xii2, "my_cifti.dtseries.nii")

Vignette

See this link to view the tutorial vignette.

Illustrations

FAQ

Why is a CIFTI file that has been read in called a "xifti"?

The "xifti" object is a general interface for not only CIFTI files, but also GIFTI and NIFTI files. For example, we can plot a surface GIFTI:

xii <- as.xifti(surfL=read_surf(ciftiTools.files()$surf["left"]))
plot(xii)

We can also convert metric GIFTI files and/or NIFTI files to CIFTI files (or vice versa) using the "xifti" object as an intermediary.

Related R extensions

  • NIFTI files: oro.nifti, RNifti
  • GIFTI files: gifti
  • CIFTI files: cifti can read in any CIFTI file, whereas ciftiTools provides a user-friendly interface for CIFTI files with the dscalar, dlabel, and dtseries intents only.
  • Other structural neuroimaging files: fsbrain
  • xml files: xml2
  • Interactive 3D rendering: rgl

Citation

You can cite our pre-print at https://arxiv.org/abs/2106.11338.

Data acknowledgement

The following data are included in the package for convenience:

Example CIFTI files provided by NITRC.

Cortical surfaces provided by the HCP, according to the Data Use Terms:

Data were provided [in part] by the Human Connectome Project, WU-Minn Consortium (Principal Investigators: David Van Essen and Kamil Ugurbil; 1U54MH091657) funded by the 16 NIH Institutes and Centers that support the NIH Blueprint for Neuroscience Research; and by the McDonnell Center for Systems Neuroscience at Washington University.

Several parcellations provided by Thomas Yeo’s Computational Brain Imaging Group (CBIG):

  1. Yeo, B. T. T. et al. The organization of the human cerebral cortex estimated by intrinsic functional connectivity. J Neurophysiol 106, 1125–1165 (2011).
  2. Schaefer, A. et al. Local-Global Parcellation of the Human Cerebral Cortex from Intrinsic Functional Connectivity MRI. Cereb Cortex 28, 3095–3114 (2018).
  3. Kong, R. et al. Individual-Specific Areal-Level Parcellations Improve Functional Connectivity Prediction of Behavior. Cerebral Cortex (2021).

Copy Link

Version

Install

install.packages('ciftiTools')

Monthly Downloads

466

Version

0.6.1

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Amanda Mejia

Last Published

September 16th, 2021

Functions in ciftiTools (0.6.1)

all_integers

All integers?
as.xifti

Assemble a "xifti" from data
as.matrix.xifti

Convert a "xifti" to a matrix
add_surf

Add surface(s) to a "xifti"
apply_xifti

Apply a function along the rows or columns of a "xifti"
ROY_BIG_BL

"ROY_BIG_BL" color palette
brainstructures_Param_LR

brainstructures
as.metric_gifti

Format metric data as a "gifti"
as.surf_gifti

Format surface data as a "gifti"
ciftiTools_msg

Print suppressible message
ROI_brainstructures_Param_LR

ROI_brainstructures
ciftiTools.listOptions

List ciftiTools options
ciftiTools

ciftiTools: Tools for Reading and Visualizing CIFTI Brain Files
ciftiTools.checkOption

Validate a ciftiTools option and value
get_data_meta_from_cifti_xml

Extract data-related metadata from CIFTI
cifti_component_suffix

Get CIFTI component suffix default
get_intn_meta_from_cifti_xml

Extract intent-specific metadata from CIFTI
cifti_fname_Param

cifti_fname
brainstructures_Param_all

brainstructures
ciftiTools.files

ciftiTools files
idx_Param

idx
ciftiTools.getOption

Get a ciftiTools option
fix_xifti

Fix a "xifti"
combine_xifti

Combine "xifti"s with non-overlapping brain structures
ciftiTools_warn

Print suppressible warning
confirm_wb_cmd_path

Confirm the Connectome Workbench command path
infer_resolution

Infer resolution from "xifti" and surfaces
make_cortex

Make the cortical components of a "xifti"
make_subcort

Make the subcortical components of a "xifti"
flatten_xifti

Flatten a "xifti"
check_cifti_type

Check CIFTI type
crop_vol

Crop a 3D array
expand_color_pal

Interpolates between entries in the input palette to make a larger palette with COLOR_RES entries.
ciftiTools.setOption

Set a ciftiTools option
.onAttach

Message on attach
dim.xifti

Dimensions of a "xifti"
fix_gifti_mwall

Fix GIFTI medial wall
is.surf

Validate a "surf" object (vertices + faces)
get_wb_cmd_path

Get the Connectome Workbench command path
is.xifti

Validate a "xifti" object.
header_cifti

Get NIFTI header (of a CIFTI)
expect_equal_xifti

Expect these "xifti"s to match
move_from_mwall

Move data locations from medial wall
convert_to_dlabel

Convert the intent of a CIFTI file or "xifti" object
move_to_mwall

Move data locations to the medial wall
get_kwargs

Get kwargs
pad_vol

Pad a 3D Array
is.nummat

Validate a numeric matrix
is.subcort_labs

Validate a factor vector of subcortical labels
resample_cifti

Resample CIFTI data
parc_borders

Parcellation borders
resample_cifti_components

Resample a series of GIFTIs related to a CIFTI file
load_parc

Load a parcellation included in ciftiTools
labels_Description

labels
get_misc_meta_from_cifti_xml

Extract misc metadata from CIFTI
info_cifti

Get CIFTI metadata
make_trans_mat

Make the subcortical transformation matrix
is.3D_mask

Validate a 3d binary mask
is.xifti_data

Validate the "data" component of a "xifti" object
newdata_xifti

Replace the data in a "xifti"
plot.surf

S3 method: plot surface
is.xifti_meta

Validate the "meta" component of a "xifti" object
ncol_xifti

Counts the number of columns in a "xifti".
coordlist_to_vol

Convert coordinate list to volume
format_path

Format a path
plot.xifti

S3 method: use view_xifti to plot a "xifti" object
resamp_res_Param_required

resamp_res: required
run_wb_cmd

Wrapper for Connectome Workbench Commands
get_cifti_extn

Get CIFTI file extension
resamp_res_Param_optional

resamp_res: optional
load_surf

Load a "surf" included in ciftiTools
is.cifti

Validate a "xifti" object
is.fname

Is this an existing file path?
resample_gifti

Resample a GIFTI file (with its ROI)
surfL_original_fname_Param

surfL_original_fname
resample_cifti_wrapper

resample_cifti wrapper
select_xifti

Select columns of a "xifti"
unmask_cortex

Unmask cortex
surfL_target_fname_Param

surfL_target_fname
merge_xifti

Concatenate "xifti"s
surfL_Param_optional

surfL
merge_kwargs

Merges two kwargs
make_xifti

Assemble a "xifti" object
nrow_xifti

Counts the number of rows (vertices + voxels) in a "xifti".
surfL_fname_Param

surfL_fname
resample_cifti_default_fname

Get resampled file name default
original_fnames_Param_resampled

original_fnames: for resampling
unmask_subcortex

Undo a volumetric mask
use_color_pal

Use a color palette
resample_surf

Resample a "surf" object
resample_cifti_from_template

Resample a CIFTI from a template
rgl_interactive_plots_Description

Navigating and Embedding the Interactive Plots
summary.xifti

Summarize a "xifti" object
verbose_Param_FALSE

verbose: FALSE
surfR_original_fname_Param

surfR_original_fname
read_cifti_convert

Read a CIFTI file quickly
read_surf

Get a "surf" object
read_cifti

Read a CIFTI file
transform_xifti

Apply a univariate transformation to a "xifti" or pair of "xifti"s.
supported_intents

The NIFTI intents supported by ciftiTools
read_dir_Param_separated

read_dir: separated files
template_xifti

Make a template "xifti" object
surfR_target_fname_Param

surfR_target_fname
view_xifti_surface.color

Get the palettes and data color mapping for view_xifti_surface
view_xifti_surface.cbar

Make the colorbar for view_xifti_surface
make_color_pal

Make a color palette.
write_cifti_components

Write CIFTI component files from a "xifti" object
write_surf_gifti

Write a "surf" to a GIFTI surface file
write_cifti

Write a CIFTI file from a "xifti" object
write_subcort_nifti

Write subcortical data to NIFTI files
separate_cifti

Separate a CIFTI file
smooth_cifti

Smooth CIFTI data
smooth_gifti

Smooth a metric GIFTI file
separate_cifti_wrapper

separate_cifti wrapper
surfR_Param_optional

surfR
view_xifti_surface.mesh_val

Get the mesh(es) and data values for view_xifti_surface
view_xifti_surface.surf_hemi

Sort out surface & hemisphere args for view_xifti_surface
xml_cifti

Get XML of a CIFTI
view_xifti_surface.draw_mesh

Draw brain hemisphere mesh in RGL
view_surf

View "surf" object(s)
verbose_Param_TRUE

verbose: TRUE
surfR_fname_Param

surfR_fname
read_cifti_flat

Read only the data matrix in a CIFTI file
match_input

Match user inputs to expected values
read_xifti2

Read in GIFTI files as a "xifti" object
write_metric_gifti

Write a data matrix to a GIFTI metric file
view_xifti_surface.draw_title

Draw title in RGL
match_exactly

Do these character vectors match exactly?
view_xifti.title

Get title for view_xifti_surface or view_xifti_volume
read_cifti_separate

Read a CIFTI file with optional resampling
remove_xifti

Remove a component from a "xifti"
write_spheres

Generate GIFTI sphere surface files
rotate_surf

Rotate a "surf" object
summary.surf

Summarize a "surf" object
surface_plot_Params

Surface plot
substructure_table

Substructure table
view_xifti_surface

View cortical surface data in a "xifti"
rgl_static_plots_Description

Embedding the Static Plots
x_Param_xifti

x: xifti
write_cifti_from_separate

Write a CIFTI file from NIFTI and GIFTI files
write_dir_Param_generic

write_dir: generic
xifti_Param

xifti
view_xifti

View a "xifti" object
sys_path

view_xifti.cleg

Draw color legend for qualitative mode
view_xifti_volume

View subcortical data in a "xifti"
wb_path_request

Request "wb_path"