Learn R Programming

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

ciftiTools

Tools for reading and visualizing CIFTI brain imaging files.

CIFTI files contain brain imaging data in “gray-ordinates”, which represent the gray matter as cortical surface vertices (left and right) and subcortical voxels (cerebellum, basal ganglia, and other deep gray matter).ciftiTools uses the Connectome Workbench to read CIFTI files into R and apply common pre-processing steps (e.g. smoothing, resampling). It also provides tools for visualizing the cortical surface with GIFTI files, and for visualizing the subcortical volume.

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::demo_files()$cifti["dtseries"]
surfL_fname <- demo_files()$surf["left"]
surfR_fname <- demo_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)
# 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

# Write a CIFTI file --------------------------------------------
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
)

new_cifti_fname <- "my_cifti.dtseries.nii"
write_cifti(xii2, new_cifti_fname)

Vignette

See this link to view the tutorial vignette.

Graphical summary

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=make_surf(demo_files()$surf["left"]))
view_xifti_surface(xii)

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

Copy Link

Version

Install

install.packages('ciftiTools')

Monthly Downloads

466

Version

0.3.1

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Amanda Mejia

Last Published

June 17th, 2021

Functions in ciftiTools (0.3.1)

as.xifti

Assemble a "xifti" object from data
confirm_wb_cmd_path

Confirm the Connectome Workbench command path
get_data_meta_from_cifti_xml

Extract data-related metadata from CIFTI
get_intn_meta_from_cifti_xml

Extract intent-specific metadata from CIFTI
convert_to_dlabel

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

Convert coordinate list to volume.
ciftiTools_msg

Print Suppressable Message
ciftiTools

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

Get ciftiTools option
ciftiTools.checkOption

Validate a ciftiTools option and value
crop_vol

Crop a 3D array
combine_xifti

Combine multiple "xifti" objects into one
cifti_fname_Param

cifti_fname
cifti_component_suffix

Get CIFTI component suffix default
ciftiTools_warn

Print Suppressable Warning
brainstructures_Param_all

brainstructures
brainstructures_Param_LR

brainstructures
demo_files

Get example files
dim.xifti

Dimensions of a "xifti"
check_cifti_type

Check CIFTI type
is.surf

Validate a surface (vertices + faces)
is.xifti

Validate a "xifti" object.
fix_xifti

Fix a "xifti" object
flatten_xifti

Flatten a "xifti" object
make_subcort

Make "xifti" subcortical components
make_cortex

Make "xifti" cortical components
original_fnames_Param_resampled

original_fnames: for resampling
make_color_pal

Make a color palette.
labels_Description

labels
pad_vol

Pad a 3D Array
.onAttach

Message on attach
resample_cifti_default_fname

Get resampled file name default
resample_cifti_from_template

Resample a CIFTI from a template
ciftiTools.listOptions

List ciftiTools options
expect_equal_xifti

Expect these CIFTIs to match
run_wb_cmd

Wrapper for Connectome Workbench Commands
select_xifti

Select columns of a "xifti" object
surface_plot_Params

surface plot
is.nummat

Validate a numeric matrix
sys_path

view_xifti

View a "xifti" object
read_xifti2

Read gifti file(s) as a xifti object
remove_xifti

Remove "xifti" component
resample_cifti_components

Resample a series of GIFTIs related to a CIFTI file
resample_cifti

Resample CIFTI Data
get_kwargs

Get kwargs
view_xifti_surface

View cortical surface data
get_misc_meta_from_cifti_xml

Extract misc metadata from CIFTI
view_xifti_surface.draw_title

Draw title in RGL
fix_gifti_mwall

Fix GIFTI medial wall
info_cifti

Get CIFTI metadata
is.3D_mask

Validate a 3d binary mask
expand_color_pal

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

Concatenate "xifti" objects
is.subcort_labs

Validate a factor vector of subcortical labels
ncol_xifti

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

surfL_original_fname
summary.xifti

Summarize cifti objects
supported_intents

The NIFTI intents supported by ciftiTools
view_xifti_surface.mesh_val

Get the mesh(es) and data values for view_xifti_surface
format_path

Format a path
xifti_Param

xifti
xml_cifti

Get XML of a CIFTI
get_cifti_extn

Get CIFTI file extension
resample_surf

Resample a "surf" object
is.cifti

Validate a "xifti" object
read_dir_Param_separated

read_dir: separated files
read_cifti_separate

Read a CIFTI file with optional resampling
get_wb_cmd_path

Get the Connectome Workbench command path
header_cifti

Get NIFTI header (of a CIFTI)
match_exactly

Do these character vectors match exactly?
make_xifti

Assemble a "xifti" object
newdata_xifti

Replace the data in a "xifti"
make_surf

Convert input to a "surf" object
is.fname

File name check
read_cifti_convert

Read a CIFTI file quickly
nrow_xifti

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

surfL_target_fname
match_input

Match user inputs to expected values
template_xifti

Make a template "xifti" object
make_trans_mat

Make the subcortical transformation matrix
transform_xifti

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

Rotate a "surface" object
merge_kwargs

Merges two kwargs
read_cifti_flat

Read only the data matrix in a CIFTI file
rgl_static_plots_Description

Embedding the Static Plots
rgl_interactive_plots_Description

Navigating and Embedding the Interactive Plots
view_xifti_surface.cbar

Make the colorbar for view_xifti_surface
is.xifti_data

Validate the "data" component of a "xifti" object
is.xifti_meta

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

Parcellation borders
plot.surf

S3 method: plot surface
surfR_original_fname_Param

surfR_original_fname
view_xifti_surface.cleg

Draw color legend for qualitative mode
surfR_target_fname_Param

surfR_target_fname
write_surf_gifti

Write CIFTI surface data to GIFTI
view_surf

View "surf" object(s)
smooth_cifti

Smooth a CIFTI
smooth_gifti

Smooth a metric GIFTI
verbose_Param_TRUE

verbose: TRUE
plot.xifti

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

Read a CIFTI file
resample_cifti_wrapper

resample_cifti wrapper
x_Param_xifti

x: xifti
resamp_res_Param_optional

resamp_res: optional
resamp_res_Param_required

resamp_res: required
write_spheres

Generate GIFTI sphere surface files
separate_cifti_wrapper

separate_cifti wrapper
separate_cifti

Separate a CIFTI file
resample_gifti

Resample a metric GIFTI file (with its ROI)
surfR_Param_optional

surfR
substructure_table

Substructure table
write_subcort_nifti

Write subcortical data to NIFTI files
view_xifti_surface.color

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

Draw brain hemisphere mesh in RGL
summary.surf

Summarize cifti objects
surfL_fname_Param

surfL_fname
surfL_Param_optional

surfL
surfR_fname_Param

surfR_fname
unmask_cortex

Unmask cortex
write_cifti_components

Write CIFTI component files from a "xifti" object.
write_cifti_from_separate

Make CIFTI file
unmask_vol

Undo a volumetric mask
view_xifti_surface.surf_hemi

Sort out surface & hemisphere args for view_xifti_surface
write_cifti

Write a CIFTI file from a "xifti" object.
use_color_pal

Use a color palette
wb_path_request

Request "wb_path"
verbose_Param_FALSE

verbose: FALSE
view_xifti_volume

View subcortex
write_dir_Param_generic

write_dir: generic
write_metric_gifti

Write CIFTI cortex data to GIFTI
as.matrix.xifti

Convert a "xifti" to a matrix
ROY_BIG_BL

"ROY_BIG_BL" color palette
add_surf

Add surface(s) to a "xifti" object
all_integers

All Integers?
Connectome_Workbench_Description

Connectome_Workbench
as.surf_gifti

Format surface data as a "gifti" object
as.metric_gifti

Format metric data as a "gifti" object
ROI_brainstructures_Param_LR

ROI_brainstructures
ciftiTools.setOption

Set ciftiTools option