MyNixOS website logo
Description

S7 Data Structures for Diffusion MRI Tractography.

Provides three S7 classes — streamline, bundle, and bundle_set — for representing diffusion MRI tractography data in R, together with a concise set of methods for computing shape descriptors (arc-length, curvature, torsion, sinuosity), the Hausdorff distance between streamlines, arc-length reparametrization of streamlines and bundles onto uniform grids, combination of streamlines or bundles into a single bundle, combination of bundles from multiple subjects or sessions into a bundle_set, and coercion to and from the dwiFiber S4 class of the 'dti' package. See Dell'Acqua, F., Descoteaux, M. and Leemans, A. (2024) "Handbook of Diffusion MR Tractography" <doi:10.1016/C2018-0-02520-7> for more about the mathematical and computational underpinnings of diffusion MRI tractography.

fiber

R-CMD-check Codecov testcoverage pkgdown CRANstatus

Overview

The fiber package provides three S7 classes — streamline, bundle, and bundle_set — for representing diffusion MRI tractography data in R, together with a concise set of methods:

FunctionDescription
streamline()Construct a single streamline
bundle()Construct a bundle of streamlines
bundle_set()Construct a set of bundles (multi-subject / multi-session)
is_streamline()Test if an object is a streamline
is_bundle()Test if an object is a bundle
is_bundle_set()Test if an object is a bundle_set
bind_bundles()Combine streamlines and/or bundles into a single bundle
bind_bundle_sets()Combine bundles and/or bundle sets into a single bundle set
as_streamline()Coerce to streamline class
as_bundle()Coerce to bundle class
as_bundle_set()Coerce to bundle_set class
as_dwifiber()Coerce to dwiFiber class from
reparametrize()Resample onto a uniform arc-length grid
get_euclidean_length()Straight-line distance between endpoints
get_curvilinear_length()Total arc-length
get_sinuosity()Curvilinear / Euclidean length ratio
get_curvature()Curvature profile or summary scalar
get_torsion()Torsion profile or summary scalar
add_shape_descriptors()Add curvature, torsion, and/or sinuosity to @point_data and/or @streamline_data
compute_hausdorff_distance()Symmetric Hausdorff distance

Classes

A streamline stores:

  • @points — a numeric matrix of size $P \times 3$ (the number of points by the three spatial dimensions). The columns must be named "X", "Y", and "Z".
  • @point_data — a named list of numeric-only vectors of length $P$ (the number of points). Stores additional per-point attributes (e.g. fractional anisotropy).
  • @streamline_data — a named list of per-streamline scalars (length-1 values, any type, e.g. a mean FA or a character label).

A bundle stores:

  • @streamlines — a list of streamline objects.
  • @streamline_data — a named list of per-streamline vectors of length $S$ (the number of streamlines). Attributes common to all streamlines are lifted here automatically at construction time and pushed back into individual streamlines when subsetting.
  • @bundle_data — a named list of bundle-level scalars (length-1 values, any type).

A bundle_set stores:

  • @bundles — a list of bundle objects (optionally named, e.g. with subject or session IDs such as "sub-01", in which case names are transferred as a bundle attribute in @bundle_data called id_from_input_list).
  • @bundle_data — a named list of per-bundle vectors of length $B$ (the number of bundles). Attributes common to all bundles are lifted here automatically at construction time and pushed back into individual bundles when subsetting.
  • @set_data — a named list of set-level scalars (length-1 values, any type).

Installation

You can install the development version of fiber from GitHub with:

# install.packages("pak")
pak::pak("tractoverse/fiber")

Quick start

library(fiber)

# Build a helix streamline (50 points)
t <- seq(0, 2 * pi, length.out = 50)
sl <- streamline(
  points = cbind(X = cos(t), Y = sin(t), Z = t / (2 * pi))
)
sl
#> 
#> ── Object of class `fiber::streamline()` with 50 points. ──
#> 
#> • Point attributes: none
#> • Streamline attributes: none
#> 

# Shape descriptors
get_curvilinear_length(sl)
#> [1] 6.358015
get_sinuosity(sl)
#> [1] 6.358015
head(get_curvature(sl))
#> [1] 1.537338e-05 1.625127e-02 4.592627e-02 8.636675e-02 1.352354e-01
#> [6] 1.906608e-01

# Bundle two streamlines
sl2 <- streamline(
  points = cbind(X = cos(t) * 1.1, Y = sin(t) * 1.1, Z = t / (2 * pi))
)
b <- bundle(list(sl, sl2))
b
#> 
#> ── Object of class `fiber::bundle()` with 2 streamliness and [50–50] points per streamline. ──
#> 
#> • Point attributes: none
#> • Streamline attributes: none
#> • Bundle attributes: none
#> 

# Reparametrize to 20 points each
b20 <- reparametrize(b, n_points = 20L)
b20
#> 
#> ── Object of class `fiber::bundle()` with 2 streamliness and [20–20] points per streamline. ──
#> 
#> • Point attributes: none
#> • Streamline attributes: none
#> • Bundle attributes: none
#> 

# Hausdorff distance
compute_hausdorff_distance(sl, sl2)
#> [1] 0.1

# Multi-subject: collect bundles from two subjects into a bundle_set
b_sub01 <- bundle(
  streamlines = list(sl),
  bundle_data = list(subject = "sub-01")
)
b_sub02 <- bundle(
  streamlines = list(sl2),
  bundle_data = list(subject = "sub-02")
)
bs <- bundle_set(list("sub-01" = b_sub01, "sub-02" = b_sub02))
bs
#> 
#> ── Object of class `fiber::bundle_set()` with 2 bundles and [1–1] streamlines per bundle. ──
#> 
#> • Point attributes: none
#> • Streamline attributes: none
#> • Bundle attributes: "subject" and "id_from_input_names"
#> • Set attributes: none
#> 
bs[["sub-01"]]
#> 
#> ── Object of class `fiber::bundle()` with 1 streamlines and [50–50] points per streamline. ──
#> 
#> • Point attributes: none
#> • Streamline attributes: none
#> • Bundle attributes: "subject" and "id_from_input_names"
#> 
Metadata

Version

0.2.0

License

Unknown

Platforms (79)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    uefi
    wasip1
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-uefi
  • aarch64-windows
  • aarch64_be-none
  • arc-linux
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • sh4-linux
  • vc4-none
  • wasm32-wasip1
  • wasm64-wasip1
  • x86_64-cygwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-uefi
  • x86_64-windows