| Title: | R Inputs/Outputs for Tractography |
|---|---|
| Description: | 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. |
| Authors: | Aymeric Stamm [aut, cre, cph] (ORCID: <https://orcid.org/0000-0002-8725-3654>), Jeroen Ooms [ctb], Lee Thomason [ctb] (Author of the TinyXML2 C++ XML parser), Tim Schäfer [ctb] (Author of the freesurferformats R package) |
| Maintainer: | Aymeric Stamm <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.2.0.9000 |
| Built: | 2026-11-27 14:49:36 UTC |
| Source: | https://github.com/tractoverse/riot |
This is the go-to function to import bundles into R. Based on both VTK and DIPY, we currently
support eight different formats detailed in the documentation of input argument file.
read_bundle(file, reference_file = NULL, bundle_data = list())read_bundle(file, reference_file = NULL, bundle_data = list())
file |
A string specifying the path to the file containing the tractography data. Currently supported files are: |
reference_file |
A string specifying the path to a reference image file. This is only required
when importing |
bundle_data |
A named list of bundle-level metadata to store in the |
A bundle object when the file contains multiple
streamlines, or a streamline object when it contains
exactly one. Each streamline stores its coordinates as an
n x 3 numeric matrix in the @points slot (columns "X", "Y",
"Z", one row per point along the tract). Additional per-point scalar
attributes, when present in the source file, appear in the
@point_data slot, and per-streamline attributes in the
@streamline_data slot.
When a bundle is returned and bundle_data is non-empty, its @bundle_data
slot is populated with the supplied list.
write_bundle() to export bundles from R.
uf_left_vtk <- read_bundle(system.file("extdata", "UF_left.vtk", package = "riot")) # Attach bundle-level metadata uf_left_vtk2 <- read_bundle( system.file("extdata", "UF_left.vtk", package = "riot"), bundle_data = list(subject = "sub-01", hemisphere = "left") ) uf_left_vtk2@bundle_datauf_left_vtk <- read_bundle(system.file("extdata", "UF_left.vtk", package = "riot")) # Attach bundle-level metadata uf_left_vtk2 <- read_bundle( system.file("extdata", "UF_left.vtk", package = "riot"), bundle_data = list(subject = "sub-01", hemisphere = "left") ) uf_left_vtk2@bundle_data
This function exports a bundle stored as a bundle object
to a file in one of the supported formats. Supported formats include VTK
(.vtk), VTP (.vtp), FDS (.fds), TRK (.trk), TCK (.tck), TRX
(.trx), FIB (.fib), and DPY (.dpy). For formats that require a
reference image (such as TRX, FIB, and DPY), the user must provide the path
to a reference image file.
write_bundle(x, file, reference_file = NULL)write_bundle(x, file, reference_file = NULL)
x |
A bundle object. |
file |
A string specifying the path to the file containing the tractography data. Currently supported files are: |
reference_file |
A string specifying the path to a reference image file. This is only required
when importing |
Warning: we rely on DIPY to provide support to save bundles in .trk, .trx, .tck, .dpy
and .fib formats. Among these formats, only .trk and .trx formats are able to keep track of
additional attributes assigned to either streamlines or points.
The input bundle (invisibly) so that the function can be used in pipes.
read_bundle() to import bundles into R.
uf_left <- read_bundle(system.file("extdata", "UF_left.vtp", package = "riot")) ## Not run: out <- fs::file_temp(ext = ".vtp") write_bundle(uf_left, file = out) ## End(Not run)uf_left <- read_bundle(system.file("extdata", "UF_left.vtp", package = "riot")) ## Not run: out <- fs::file_temp(ext = ".vtp") write_bundle(uf_left, file = out) ## End(Not run)