R Inputs/Outputs for Tractography

Provides a unified input-output interface for reading and writing bundles — collections of 3-D polylines (streamlines) reconstructed by fibre-tracking algorithms applied to diffusion MRI data. Supported formats include VTK (.vtk), VTP (.vtp), medInria FDS (.fds), MRtrix TCK/TSF (.tck/.tsf), and TrackVis TRK (.trk), with additional formats accessible via the 'DIPY' Python library through 'reticulate'. Bundles are represented in R using the S7 classes defined in the 'fiber' package: a single tract (class 'streamline') stores its coordinates, per-point scalar attributes, and per-streamline scalar attributes in separate, typed slots; a collection of tracts (class 'bundle') wraps a list of streamlines together with optional bundle-level metadata. VTK support is provided at compile time by the 'rvtk' package, which supplies pre-compiled VTK libraries and headers so that no manual VTK installation is required on most platforms.


riot riot website

R-CMD-check Codecov testcoverage pkgdown CRANstatus

Overview

The riot (R Input/Output for Tractography) package provides an R interface for importing and exporting tractography data to and from R. Currently supported importing formats are:

The package reads tractography data into S7 objects defined by the {fiber} package:

  • streamline — a single fibre tract stored in three typed slots: @points (an $n \times 3$ matrix with columns X, Y, Z), @point_data (a named list of per-point numeric vectors, e.g. diffusion metrics sampled at every point), and @streamline_data (a named list of per-streamline scalar attributes).
  • bundle — an ordered collection of streamline objects in @streamlines, plus optional bundle-level metadata in @bundle_data.

read_bundle() returns a streamline when the file contains a single tract and a bundle otherwise. The optional bundle_data argument lets you attach a named list of bundle-level metadata (e.g. subject ID, hemisphere, or affine transform) directly at import time: the list is stored in the @bundle_data slot of the returned bundle.

The package also allows to write bundles back into the following exporting formats:

  • native VTK .vtk and .vtp files; or,
  • medInria .fds files;
  • .trk, .tck, .trx, .fib, and .dpy files through the ‘DIPY’ Python library (requires a reference image).

A guided tour of the package is available in the vignette("riot") vignette, and the internal design is described in the developer-oriented vignette("riot-api") vignette.

Installation

You can install the released version of riot from CRAN with:

install.packages("riot")

Alternatively you can install the development version of riot from GitHub with:

# install.packages("remotes")
remotes::install_github("tractoverse/riot")

Example

library(riot)

Native VTK .vtk and .vtp files

uf_left_vtk <- read_bundle(system.file(
  "extdata",
  "UF_left.vtk",
  package = "riot"
))
uf_left_vtk
#> 
#> ── Object of class `fiber::bundle()` with 2042 streamlines and [9–33] points per streamline. ──
#> 
#> • Point attributes: none
#> • Streamline attributes: none
#> • Bundle attributes: none
#> 
uf_left_vtp <- read_bundle(system.file(
  "extdata",
  "UF_left.vtp",
  package = "riot"
))
uf_left_vtp
#> 
#> ── Object of class `fiber::bundle()` with 2042 streamlines and [9–33] points per streamline. ──
#> 
#> • Point attributes: none
#> • Streamline attributes: none
#> • Bundle attributes: none
#> 

medInria .fds files

uf_left_fds <- read_bundle(system.file(
  "extdata",
  "UF_left.fds",
  package = "riot"
))
uf_left_fds
#> 
#> ── Object of class `fiber::bundle()` with 2042 streamlines and [9–33] points per streamline. ──
#> 
#> • Point attributes: none
#> • Streamline attributes: none
#> • Bundle attributes: none
#> 

MRtrix .tck/.tsf files

af_left_tck <- read_bundle(system.file(
  "extdata",
  "AF_left.tck",
  package = "riot"
))
af_left_tck
#> 
#> ── Object of class `fiber::bundle()` with 5000 streamlines and [8–54] points per streamline. ──
#> 
#> • Point attributes: none
#> • Streamline attributes: none
#> • Bundle attributes: none
#> 

TrackVis .trk files

cc_mid_trk <- read_bundle(system.file(
  "extdata",
  "CCMid.trk",
  package = "riot"
))
cc_mid_trk
#> 
#> ── Object of class `fiber::bundle()` with 525 streamlines and [29–270] points per streamline. ──
#> 
#> • Point attributes: none
#> • Streamline attributes: none
#> • Bundle attributes: none
#> 

Attaching bundle-level metadata with bundle_data

uf_left_meta <- read_bundle(
  system.file("extdata", "UF_left.vtk", package = "riot"),
  bundle_data = list(subject = "sub-01", hemisphere = "left")
)
uf_left_meta@bundle_data
#> $subject
#> [1] "sub-01"
#> 
#> $hemisphere
#> [1] "left"

Dependencies

fiber

riot relies on the fiber package for the S7 classes streamline and bundle that represent tractography data in R, as well as the constructors, predicates, and geometry methods that operate on them. riot does not depend on S7 directly.

VTK

Since version 1.2.0, riot delegates all VTK linkage to the rvtk infrastructure package. VTK is not a system requirement: neither for riot nor for rvtk. At install time, rvtk searches for a pre-installed VTK in the following order:

  1. VTK_DIR environment variable (highest priority).
  2. Homebrew — macOS only (brew install vtk).
  3. pkg-config — macOS and Linux.
  4. Well-known system prefix paths (/usr, /usr/local) — Linux.
  5. Rtools42+ pacman package for the active MSYS2 environment (e.g. mingw-w64-ucrt-x86_64-vtk for UCRT64) — Windows.

If no pre-installed VTK is found, rvtk automatically downloads a pre-compiled static or shared VTK build from its GitHub releases, so no manual VTK installation is ever required.

TinyXML-2

riot bundles TinyXML-2. tinyxml2.cpp has been modified to avoid the use of stdout and printf as per Writing R Extensions manual recommendations because R has its own input/output mechanism for writing to the console.

Acknowledgements

The authors would like to thank Tim Schäfer, the author of the freesurferformats package, for his helpful code to read MRtrix and TrackVis tractography file formats.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("riot")

1.2.0 by Aymeric Stamm, 2 days ago


https://github.com/tractoverse/riot, https://tractoverse.github.io/riot/


Report a bug at https://github.com/tractoverse/riot/issues


Browse source code at https://github.com/cran/riot


Authors: Aymeric Stamm [aut, cre, cph] (ORCID: , Jeroen Ooms [ctb] , Lee Thomason [ctb] (Author of the TinyXML2 C++ XML parser) , Tim Schäfer [ctb] (Author of the freesurferformats R package)


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports cli, fiber, fs, rlang, rvtk

Suggests knitr, pkgdown, quarto, reticulate, tinytest

Linking to cpp11

System requirements: Python (>= 3.7) with the 'dipy' package is optional; required only for TRX, FIB, and DPY bundle formats.


See at CRAN