| Title: | fMRI BOLD Signal Analysis for Circadian and Sleep Research |
|---|---|
| Description: | Analysis of Blood-Oxygen-Level-Dependent (BOLD) fMRI data for sleep and circadian research. Receives preprocessed derivatives from fMRIPrep and transforms them into analysis-ready outputs: atlas-agnostic parcellation with an extensible atlas schema, ROI-level timeseries extraction, voxelwise signal metrics (tSNR, GLM contrasts), and functional connectivity matrices. Exports parcellated BOLD data directly to syncR for integration with actigraphy, polysomnography, and questionnaire data in a unified participant-indexed database. Part of the Circadia Lab R ecosystem at Northumbria University. fmriprep gets you clean data. boldR gets you useful data. |
| Authors: | Lucas França [aut, cre] (ORCID: <https://orcid.org/0000-0003-0853-1319>), Mario Leocadio-Miguel [aut] (ORCID: <https://orcid.org/0000-0002-7248-3529>) |
| Maintainer: | Lucas França <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-07-01 23:56:50 UTC |
| Source: | https://github.com/circadia-bio/boldR |
Estimates a ROI-to-ROI functional connectivity matrix from a parcellated BOLD timeseries using Pearson correlation (default) or partial correlation. Returns both the full symmetric matrix and a tidy long-format data frame.
compute_fc(parcellated, method = c("pearson", "partial"), fisher_z = TRUE)compute_fc(parcellated, method = c("pearson", "partial"), fisher_z = TRUE)
parcellated |
A |
method |
Character. Connectivity metric. One of:
|
fisher_z |
Logical. Whether to apply Fisher r-to-z transformation
before returning values. Default |
A list of class boldr_fc with components:
Numeric matrix (n_rois × n_rois). Symmetric FC matrix with
NA on the diagonal.
Data frame (long format). Columns: roi_i, roi_j,
roi_name_i, roi_name_j, fc.
Character. Connectivity method used.
Logical. Whether Fisher z was applied.
Character. Atlas identifier.
## Not run: parc <- parcellate(cleaned, atlas) fc <- compute_fc(parc) dim(fc$matrix) head(fc$long) ## End(Not run)## Not run: parc <- parcellate(cleaned, atlas) fc <- compute_fc(parc) dim(fc$matrix) head(fc$long) ## End(Not run)
Returns a tibble of per-ROI summary statistics from the parcellated timeseries: mean signal, standard deviation, and temporal SNR.
compute_roi_metrics(parcellated)compute_roi_metrics(parcellated)
parcellated |
A |
A tibble with columns roi, mean, sd, tsnr, n_voxels.
## Not run: parcel <- parcellate(bold, atlas) metrics <- compute_roi_metrics(parcel) metrics ## End(Not run)## Not run: parcel <- parcellate(bold, atlas) metrics <- compute_roi_metrics(parcel) metrics ## End(Not run)
Calculates temporal signal-to-noise ratio (tSNR) for every in-mask voxel in a cleaned BOLD image. tSNR is defined as the ratio of the mean signal to its temporal standard deviation across the timeseries. It is a standard quality metric for fMRI acquisitions and preprocessing pipelines.
Calculates temporal signal-to-noise ratio (tSNR) for each voxel in the BOLD image: mean signal divided by standard deviation across timepoints. A standard quality metric for assessing fMRI data quality after preprocessing.
compute_tsnr(bold) compute_tsnr(bold)compute_tsnr(bold) compute_tsnr(bold)
bold |
A |
A list of class boldr_tsnr with components:
3D numeric array (same x × y × z as input). Contains tSNR
values for in-mask voxels and NA elsewhere.
Numeric. Mean tSNR across in-mask voxels.
Numeric. Median tSNR across in-mask voxels.
Integer. Number of in-mask voxels.
A list of class boldR_tsnr with components:
Numeric array. tSNR map with same x/y/z dimensions as BOLD.
Numeric. Mean tSNR across in-mask voxels.
Numeric. Median tSNR across in-mask voxels.
The input boldR_bold object.
## Not run: sub <- read_fmriprep("data/derivatives/fmriprep", "01", task = "rest") cleaned <- prepare_bold(sub) tsnr_out <- compute_tsnr(cleaned) tsnr_out$mean_tsnr ## End(Not run) ## Not run: fprep <- read_fmriprep("data/derivatives/fmriprep", subject = "01") bold <- prepare_bold(fprep, tr = 2, drop_volumes = 4) tsnr <- compute_tsnr(bold) tsnr$mean_tsnr ## End(Not run)## Not run: sub <- read_fmriprep("data/derivatives/fmriprep", "01", task = "rest") cleaned <- prepare_bold(sub) tsnr_out <- compute_tsnr(cleaned) tsnr_out$mean_tsnr ## End(Not run) ## Not run: fprep <- read_fmriprep("data/derivatives/fmriprep", subject = "01") bold <- prepare_bold(fprep, tr = 2, drop_volumes = 4) tsnr <- compute_tsnr(bold) tsnr$mean_tsnr ## End(Not run)
Packages the output of parcellate() into a boldR_export object
suitable for ingestion by syncR::sync(). The export includes the ROI
timeseries matrix, functional connectivity matrix (if computed), ROI
metrics, and participant metadata.
export_bold(parcellated, fc = NULL, roi_metrics = NULL, participant_id = NULL)export_bold(parcellated, fc = NULL, roi_metrics = NULL, participant_id = NULL)
parcellated |
A |
fc |
A |
roi_metrics |
A tibble from |
participant_id |
Character or |
A list of class boldR_export ready for syncR::sync().
## Not run: parcel <- parcellate(bold, atlas) fc <- compute_fc(parcel) exp <- export_bold(parcel, fc = fc) # Pass to syncR syncR::sync(..., bold = exp) ## End(Not run)## Not run: parcel <- parcellate(bold, atlas) fc <- compute_fc(parcel) exp <- export_bold(parcel, fc = fc) # Pass to syncR syncR::sync(..., bold = exp) ## End(Not run)
Returns a data frame describing the atlases bundled with boldR.
Custom atlases can be loaded via load_atlas().
list_atlases()list_atlases()
A tibble with columns name, n_rois, space, and description.
list_atlases()list_atlases()
Loads a boldR_atlas object either from the bundled atlas library or from
a custom NIfTI label map. The boldR_atlas schema is the extension point
for user-defined parcellations.
load_atlas(atlas, labels = NULL, space = NULL)load_atlas(atlas, labels = NULL, space = NULL)
atlas |
Character. Name of a built-in atlas (see |
labels |
Character vector or |
space |
Character or |
A list of class boldR_atlas with components:
Character. Atlas name or file path.
Character. Path to the atlas NIfTI label image.
Character vector. ROI label for each integer index.
Integer vector. Non-zero integer values in the atlas.
Integer. Number of ROIs.
Character. Template space.
## Not run: atlas <- load_atlas("schaefer100_7n") atlas # Custom atlas atlas <- load_atlas( atlas = "my_parcellation.nii.gz", labels = paste0("ROI_", 1:80), space = "MNI152NLin2009cAsym" ) ## End(Not run)## Not run: atlas <- load_atlas("schaefer100_7n") atlas # Custom atlas atlas <- load_atlas( atlas = "my_parcellation.nii.gz", labels = paste0("ROI_", 1:80), space = "MNI152NLin2009cAsym" ) ## End(Not run)
A named character vector of the eight colours used throughout the boldR package and its pkgdown site.
palette_boldpalette_bold
A named character vector of length 8.
Applies a parcellation atlas to a preprocessed BOLD image, returning
mean timeseries per ROI. Works with any boldR_atlas object – built-in
or custom – as long as the atlas is in the same template space as the BOLD.
parcellate(bold, atlas, summary_fn = mean, min_voxels = 10L)parcellate(bold, atlas, summary_fn = mean, min_voxels = 10L)
bold |
A |
atlas |
A |
summary_fn |
Function. Applied across voxels within each ROI at each
timepoint. Default |
min_voxels |
Integer. Minimum number of in-mask voxels an ROI must
contain to be included in the output. ROIs below this threshold are
returned with |
A list of class boldR_parcellated with components:
Numeric matrix, timepoints x ROIs. Column names are ROI labels from the atlas.
Integer vector. Number of in-mask voxels per ROI.
The boldR_atlas object used.
The boldR_bold object used.
Integer. Number of ROIs in output.
Integer. Number of timepoints.
## Not run: fprep <- read_fmriprep("data/derivatives/fmriprep", subject = "01") bold <- prepare_bold(fprep, tr = 2, drop_volumes = 4) atlas <- load_atlas("schaefer100_7n") parcel <- parcellate(bold, atlas) dim(parcel$timeseries) # timepoints x 100 ## End(Not run)## Not run: fprep <- read_fmriprep("data/derivatives/fmriprep", subject = "01") bold <- prepare_bold(fprep, tr = 2, drop_volumes = 4) atlas <- load_atlas("schaefer100_7n") parcel <- parcellate(bold, atlas) dim(parcel$timeseries) # timepoints x 100 ## End(Not run)
Checks file existence, reads NIfTI headers to confirm dimensionality and
TR, and returns an annotated boldR_bold object ready for downstream
analysis functions.
prepare_bold(fmriprep, tr = NULL, drop_volumes = 0L)prepare_bold(fmriprep, tr = NULL, drop_volumes = 0L)
fmriprep |
A |
tr |
Numeric or |
drop_volumes |
Integer. Number of initial volumes to discard (dummy
scans). Default |
A list of class boldR_bold with components:
The input boldR_fmriprep object.
Integer vector. BOLD array dimensions [x, y, z, t].
Numeric. Repetition time in seconds.
Integer. Total in-mask voxels.
Integer. Number of volumes after dummy-scan removal.
Integer. Volumes dropped.
## Not run: fprep <- read_fmriprep("data/derivatives/fmriprep", subject = "01") bold <- prepare_bold(fprep, tr = 2, drop_volumes = 4) bold ## End(Not run)## Not run: fprep <- read_fmriprep("data/derivatives/fmriprep", subject = "01") bold <- prepare_bold(fprep, tr = 2, drop_volumes = 4) bold ## End(Not run)
Reads preprocessed fMRI outputs from an
fMRIPrep BIDS derivatives directory for a single
participant and session, returning a structured boldR_fmriprep object
containing paths to the BOLD, T1w, T2w, and segmentation files.
read_fmriprep( derivatives_dir, subject, session = NULL, task = NULL, space = "MNI152NLin2009cAsym", resolution = NULL )read_fmriprep( derivatives_dir, subject, session = NULL, task = NULL, space = "MNI152NLin2009cAsym", resolution = NULL )
derivatives_dir |
Character. Path to the fMRIPrep derivatives root
(e.g. |
subject |
Character. Subject label without the |
session |
Character or |
task |
Character or |
space |
Character. Template space for the BOLD and mask files.
Default |
resolution |
Character or |
A list of class boldR_fmriprep with components:
Character. Path to the BOLD NIfTI file.
Character. Path to the brain mask NIfTI file.
Character. Path to the T1w NIfTI file in template space.
Character or NA. Path to the T2w NIfTI file if available.
Character. Path to the discrete segmentation NIfTI file.
Character. Path to the confounds TSV file.
Character. Subject label.
Character or NA. Session label.
Character. Task label.
Character. Template space.
Character. Resolved path to the derivatives root.
## Not run: fprep <- read_fmriprep( derivatives_dir = "data/derivatives/fmriprep", subject = "01", task = "rest" ) fprep ## End(Not run)## Not run: fprep <- read_fmriprep( derivatives_dir = "data/derivatives/fmriprep", subject = "01", task = "rest" ) fprep ## End(Not run)
Validates and registers a NIfTI label map and optional metadata table as a
boldR_atlas object. The schema is intentionally minimal: any parcellation
that provides a 3D integer label image and a label-to-name mapping can be
registered and passed to parcellate(). Bundled atlas helpers (Schaefer,
AAL, Glasser) use this same interface.
register_atlas( labels_img, metadata, name = "custom", space = "MNI152NLin2009cAsym" )register_atlas( labels_img, metadata, name = "custom", space = "MNI152NLin2009cAsym" )
labels_img |
A |
metadata |
A data frame with at minimum two columns:
Additional columns (hemisphere, network, x/y/z centroid, colour, etc.) are stored and carried through to output. |
name |
Character. A short identifier for this atlas
(e.g. |
space |
Character. The standard space this atlas is defined in.
Default |
A list of class boldR_atlas with components:
niftiImage. The 3D integer label map.
Data frame. ROI metadata.
Character. Atlas identifier.
Character. Standard space.
Integer. Number of unique non-zero labels.
## Not run: atlas <- register_atlas( labels_img = "atlases/Schaefer2018_200Parcels_7Networks_MNI.nii.gz", metadata = read.csv("atlases/Schaefer2018_200Parcels_labels.csv"), name = "Schaefer200", space = "MNI152NLin2009cAsym" ) atlas ## End(Not run)## Not run: atlas <- register_atlas( labels_img = "atlases/Schaefer2018_200Parcels_7Networks_MNI.nii.gz", metadata = read.csv("atlases/Schaefer2018_200Parcels_labels.csv"), name = "Schaefer200", space = "MNI152NLin2009cAsym" ) atlas ## End(Not run)