Skip to contents

Create a GDS plan from an image catalog. The catalog's assay mappings determine which files are used for the beta assay and, optionally, one uncertainty assay (se or var); mapping any other assay is an error. When the catalog has a subject column, its values become the GDS subject labels and uncertainty files are paired with beta files by subject; subject-level metadata from the catalog is attached as col_data.

Usage

# S3 method for class 'image_catalog'
as_gds(x, mask = NULL, ...)

Arguments

x

An image_catalog object with assay mappings set via map_assays().

mask

Optional mask file path or NeuroVol object.

...

Additional arguments passed to gds().

Value

A gds_plan object.

Examples

if (requireNamespace("neuroim2", quietly = TRUE) &&
    requireNamespace("RNifti", quietly = TRUE)) {
  # Write tiny 4x4x2 beta and SE maps for three subjects
  root <- tempfile("study_")
  for (s in c("01", "02", "03")) {
    d <- file.path(root, paste0("sub-", s), "stats")
    dir.create(d, recursive = TRUE)
    RNifti::writeNifti(array(rnorm(32), c(4, 4, 2)),
                       file.path(d, paste0("sub-", s, "_beta.nii.gz")))
    RNifti::writeNifti(array(0.5, c(4, 4, 2)),
                       file.path(d, paste0("sub-", s, "_se.nii.gz")))
  }

  catalog <- image_catalog(root, "sub-*/stats/*.nii.gz",
                           path_regex = "sub-(?<subject>[^/]+)") |>
    map_assays(beta = "_beta", se = "_se")

  plan <- as_gds(catalog)
  result <- compute(plan)
  print(result)

  unlink(root, recursive = TRUE)
}
#> GDS
#>   dims: 32 x 3 x 1 [sample x subject x contrast]
#>   space: voxel dim=4x4x2, storage=packed
#>   subjects: 3 (01, 02, 03)
#>   contrasts: 1 (contrast1)
#>   assays: beta[location], se[stdev]