| Title: | Spinal Cord Injury Imaging Pipeline for MRI and CT Analysis in R |
|---|---|
| Description: | An end-to-end pipeline for longitudinal MRI and CT analysis in spinal cord injury (SCI) research. Provides R wrappers for the Spinal Cord Toolbox (SCT) including SCIsegV2 lesion segmentation, DICOM anonymization and NIfTI conversion tools, SCI-specific clinical metrics (MSCC, compression ratio, tissue bridge quantification), implant artifact grading, and pipeline orchestration with built-in quality control. Integrates with workflowr for reproducible, publication-ready neuroimaging analyses. |
| Authors: | R. Heller [aut, cre] |
| Maintainer: | R. Heller <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-11-03 18:18:09 UTC |
| Source: | https://github.com/CTTIR/scimagR |
Replaces identifying header fields (PatientName, PatientID, PatientBirthDate, etc.) and removes private tags. Saves an ID mapping CSV to a user-specified secure location.
anonymize_dicom( dicom_dir, mapping_csv, prefix = "SCI", python = Sys.getenv("PYTHON_BIN", "python3") )anonymize_dicom( dicom_dir, mapping_csv, prefix = "SCI", python = Sys.getenv("PYTHON_BIN", "python3") )
dicom_dir |
Character. Root DICOM directory. |
mapping_csv |
Character. Path for ID mapping output. Store securely! |
prefix |
Character. Anonymized ID prefix. Default |
python |
Character. Python executable. Default |
WARNING: This modifies DICOM files in-place. Create a backup first. The mapping CSV must NOT be stored in the project directory.
Exit code (invisible).
## Not run: anonymize_dicom("data/raw/dicom", "/secure/id_mapping.csv") ## End(Not run)## Not run: anonymize_dicom("data/raw/dicom", "/secure/id_mapping.csv") ## End(Not run)
Verifies that dcm2niix is installed and on PATH.
check_dcm2niix(verbose = TRUE)check_dcm2niix(verbose = TRUE)
verbose |
Logical. Print status message. Default |
Named list with components: available, version, path.
## Not run: check_dcm2niix() ## End(Not run)## Not run: check_dcm2niix() ## End(Not run)
Verifies that Python 3 with pydicom is available.
check_pydicom(python = Sys.getenv("PYTHON_BIN", "python3"), verbose = TRUE)check_pydicom(python = Sys.getenv("PYTHON_BIN", "python3"), verbose = TRUE)
python |
Character. Python executable. Default uses |
verbose |
Logical. Print status message. Default |
Named list with components: available, version, path.
## Not run: check_pydicom() ## End(Not run)## Not run: check_pydicom() ## End(Not run)
Verifies that SCT is installed and on PATH. Returns version and path information.
check_sct(verbose = TRUE)check_sct(verbose = TRUE)
verbose |
Logical. Print status message. Default |
Named list with components:
available: Logical.
version: Character. Version string or NA.
path: Character. Path to sct_version executable or NA.
## Not run: check_sct() ## End(Not run)## Not run: check_sct() ## End(Not run)
Maps integer grades 0–4 to an ordered factor:
0: none
1: mild
2: moderate
3: severe
4: non-evaluable
classify_artifact(grade)classify_artifact(grade)
grade |
Integer vector (0–4). Values outside this range produce |
Ordered factor with 5 levels: none < mild < moderate < severe < non-evaluable.
classify_artifact(c(0, 1, 2, 3, 4))classify_artifact(c(0, 1, 2, 3, 4))
Classification based on established SCI literature (Grassner et al. 2025, Freund et al. 2019):
<= 1 day: hyperacute
2–14 days: acute
15–90 days: subacute
91–365 days: intermediate
more than 365 days: chronic
classify_phase(days)classify_phase(days)
days |
Numeric vector. Days since trauma. |
Ordered factor with 5 levels: hyperacute < acute < subacute < intermediate < chronic.
classify_phase(c(0, 5, 30, 200, 400))classify_phase(c(0, 5, 30, 200, 400))
Calculates the ratio of anterior-posterior to transverse diameter.
compute_compression_ratio(ap, transverse)compute_compression_ratio(ap, transverse)
ap |
Numeric. Anterior-posterior diameter (mm). |
transverse |
Numeric. Transverse diameter (mm). |
Numeric. Compression ratio (unitless). NA if transverse <= 0
or any input is NA.
compute_compression_ratio(ap = 6.5, transverse = 12.0)compute_compression_ratio(ap = 6.5, transverse = 12.0)
Calculates the ratio of CSA at the injury level to the reference CSA (average of adjacent levels).
compute_csa_ratio(csa_injury, csa_above, csa_below)compute_csa_ratio(csa_injury, csa_above, csa_below)
csa_injury |
Numeric. CSA at injury level (mm^2). |
csa_above |
Numeric. CSA one level above (mm^2). |
csa_below |
Numeric. CSA one level below (mm^2). |
Numeric. CSA ratio (unitless). NA if reference is <= 0 or any
input is NA.
compute_csa_ratio(csa_injury = 45, csa_above = 70, csa_below = 72)compute_csa_ratio(csa_injury = 45, csa_above = 70, csa_below = 72)
Calculates MSCC using the formula:
compute_mscc(di, da, db)compute_mscc(di, da, db)
di |
Numeric. Sagittal AP diameter at injury level (mm). |
da |
Numeric. Sagittal AP diameter one level above (mm). |
db |
Numeric. Sagittal AP diameter one level below (mm). |
Numeric. MSCC percentage. NA if any input is NA or if the
reference diameter is <= 0.
compute_mscc(di = 5.2, da = 8.1, db = 8.5) compute_mscc(di = 0, da = 8, db = 8) # 100% compressioncompute_mscc(di = 5.2, da = 8.1, db = 8.5) compute_mscc(di = 0, da = 8, db = 8) # 100% compression
Iterates over a registry and converts all sessions from DICOM to NIfTI.
convert_batch( registry, dicom_root, nifti_root, compress = TRUE, verbose = TRUE )convert_batch( registry, dicom_root, nifti_root, compress = TRUE, verbose = TRUE )
registry |
Data frame with |
dicom_root |
Character. Root DICOM directory. |
nifti_root |
Character. Root NIfTI output directory. |
compress |
Logical. Gzip output. Default |
verbose |
Logical. Print progress. Default |
Tibble with columns: pat_id, session, status, n_files.
## Not run: convert_batch(registry, "data/raw/dicom", "data/nifti") ## End(Not run)## Not run: convert_batch(registry, "data/raw/dicom", "data/nifti") ## End(Not run)
Converts a single session's DICOM files to NIfTI format using dcm2niix.
convert_dcm2niix(dicom_dir, output_dir, compress = TRUE, verbose = TRUE)convert_dcm2niix(dicom_dir, output_dir, compress = TRUE, verbose = TRUE)
dicom_dir |
Character. Path to session DICOM directory. |
output_dir |
Character. Path for NIfTI output. |
compress |
Logical. Gzip output. Default |
verbose |
Logical. Print progress. Default |
Character vector of output NIfTI paths.
## Not run: convert_dcm2niix("data/raw/dicom/SCI001/ses-01", "data/nifti/SCI001/ses-01") ## End(Not run)## Not run: convert_dcm2niix("data/raw/dicom/SCI001/ses-01", "data/nifti/SCI001/ses-01") ## End(Not run)
Shows which patients have which modalities at which timepoints.
coverage_matrix(registry)coverage_matrix(registry)
registry |
Data frame. Validated registry with |
Tibble in wide format with one row per patient and one column per session containing the modality.
## Not run: reg <- validate_registry("imaging_registry.csv", strict = FALSE) cm <- coverage_matrix(reg) ## End(Not run)## Not run: reg <- validate_registry("imaging_registry.csv", strict = FALSE) cm <- coverage_matrix(reg) ## End(Not run)
Creates an empty QC log tibble or reads an existing one from CSV.
create_qc_log(path = NULL)create_qc_log(path = NULL)
path |
Character. Optional path to existing QC log CSV. |
Tibble with QC log columns: pat_id, session, rater,
date, seg_type, quality, notes.
qc <- create_qc_log()qc <- create_qc_log()
Takes raw DICOM metadata (from extract_dicom_metadata()), restructures
it into a proper imaging registry with computed fields (days_post_trauma,
phase classification), and optionally saves to CSV.
create_registry(dicom_meta, trauma_dates, op_dates = NULL, output_csv = NULL)create_registry(dicom_meta, trauma_dates, op_dates = NULL, output_csv = NULL)
dicom_meta |
Data frame or character path to DICOM metadata CSV. |
trauma_dates |
Named vector: names = pat_id, values = trauma date (Date or character coercible to Date). |
op_dates |
Named vector: names = pat_id, values = OP date. Optional. |
output_csv |
Character. Path to save registry. Optional. |
Tibble with registry columns.
## Not run: meta <- read.csv("dicom_metadata.csv") trauma <- c(SCI001 = "2024-01-15", SCI002 = "2024-02-20") reg <- create_registry(meta, trauma) ## End(Not run)## Not run: meta <- read.csv("dicom_metadata.csv") trauma <- c(SCI001 = "2024-01-15", SCI002 = "2024-02-20") reg <- create_registry(meta, trauma) ## End(Not run)
Walks a DICOM directory tree and extracts key header fields (StudyDate, Modality, SeriesDescription, FieldStrength, etc.) from the first DICOM file per session.
extract_dicom_metadata( dicom_dir, output_csv, python = Sys.getenv("PYTHON_BIN", "python3") )extract_dicom_metadata( dicom_dir, output_csv, python = Sys.getenv("PYTHON_BIN", "python3") )
dicom_dir |
Character. Root DICOM directory (expects
|
output_csv |
Character. Path for output CSV. |
python |
Character. Python executable. Default uses |
Character. Path to output CSV (invisible).
## Not run: extract_dicom_metadata("data/raw/dicom", "data/metadata/dicom_metadata.csv") ## End(Not run)## Not run: extract_dicom_metadata("data/raw/dicom", "data/metadata/dicom_metadata.csv") ## End(Not run)
Filters a dataset to sessions that meet artifact grade and modality criteria for analysis.
filter_evaluable( df, max_artifact = 2, modalities = c("MRT", "CT+MRT"), verbose = TRUE )filter_evaluable( df, max_artifact = 2, modalities = c("MRT", "CT+MRT"), verbose = TRUE )
df |
Data frame with |
max_artifact |
Integer. Maximum artifact grade to include. Default |
modalities |
Character vector. Modalities to include.
Default |
verbose |
Logical. Print exclusion summary. Default |
Filtered data frame.
## Not run: evaluable <- filter_evaluable(registry, max_artifact = 2) ## End(Not run)## Not run: evaluable <- filter_evaluable(registry, max_artifact = 2) ## End(Not run)
Reports dimensions, missing values per column, and duplicate count for a data frame. Returns the data frame invisibly for piping.
integrity_summary(df, id_cols = NULL)integrity_summary(df, id_cols = NULL)
df |
Data frame to summarize. |
id_cols |
Character vector. Columns to check for duplicates.
Default |
Invisibly returns df.
## Not run: registry |> integrity_summary(id_cols = c("pat_id", "session")) ## End(Not run)## Not run: registry |> integrity_summary(id_cols = c("pat_id", "session")) ## End(Not run)
Records before/after row counts and reason for an exclusion step. Useful for building a CONSORT-style exclusion flow.
log_exclusion(step, n_before, n_after, reason = "")log_exclusion(step, n_before, n_after, reason = "")
step |
Character. Name of the exclusion step. |
n_before |
Integer. Row count before filtering. |
n_after |
Integer. Row count after filtering. |
reason |
Character. Reason for exclusion. |
A 1-row tibble with columns: step, n_before, n_after,
n_excluded, reason.
log_exclusion("Artifact filter", 100, 85, "artifact_grade > 2")log_exclusion("Artifact filter", 100, 85, "artifact_grade > 2")
Named character vector of 5 colours for MRI artifact grades: none (green), mild (yellow), moderate (orange), severe (red), non-evaluable (grey).
pal_artifactpal_artifact
pal_artifactpal_artifact
Named character vector of 3 colours for imaging modalities.
pal_modalitypal_modality
pal_modalitypal_modality
Named character vector of 5 viridis-derived colours for SCI phases: hyperacute, acute, subacute, intermediate, chronic.
pal_phasepal_phase
pal_phasepal_phase
Creates a tile plot showing modality coverage per patient and session, with optional artifact grade overlay.
plot_coverage(registry)plot_coverage(registry)
registry |
Data frame. Validated registry. |
A ggplot2 object.
## Not run: plot_coverage(registry) ## End(Not run)## Not run: plot_coverage(registry) ## End(Not run)
Creates a forest plot for comparing model estimates with confidence intervals. Useful for sensitivity analysis comparisons.
plot_forest(estimates_df, xlab = "Estimate", title = NULL, vline = 0)plot_forest(estimates_df, xlab = "Estimate", title = NULL, vline = 0)
estimates_df |
Data frame with columns: |
xlab |
Character. X-axis label. Default |
title |
Character. Plot title. Default |
vline |
Numeric. Position of reference line. Default |
A ggplot2 object.
## Not run: est <- data.frame( model = c("Full", "Sensitivity 1", "Sensitivity 2"), estimate = c(-2.1, -1.9, -2.3), ci_lower = c(-3.5, -3.4, -3.8), ci_upper = c(-0.7, -0.4, -0.8) ) plot_forest(est) ## End(Not run)## Not run: est <- data.frame( model = c("Full", "Sensitivity 1", "Sensitivity 2"), estimate = c(-2.1, -1.9, -2.3), ci_lower = c(-3.5, -3.4, -3.8), ci_upper = c(-0.7, -0.4, -0.8) ) plot_forest(est) ## End(Not run)
Shows individual patient trajectories over time with an optional group-level smoother.
plot_spaghetti(df, x, y, group, colour = NULL, smoother = TRUE, title = NULL)plot_spaghetti(df, x, y, group, colour = NULL, smoother = TRUE, title = NULL)
df |
Data frame. |
x |
Character. Column name for x-axis (numeric, e.g., days). |
y |
Character. Column name for y-axis (numeric). |
group |
Character. Column name for grouping (e.g., |
colour |
Character. Column name for colour aesthetic. Default |
smoother |
Logical. Add group-level LOESS smoother. Default |
title |
Character. Plot title. Default |
A ggplot2 object.
## Not run: plot_spaghetti(df, x = "days_post_trauma", y = "csa", group = "pat_id", colour = "phase") ## End(Not run)## Not run: plot_spaghetti(df, x = "days_post_trauma", y = "csa", group = "pat_id", colour = "phase") ## End(Not run)
Creates a violin plot with embedded boxplot (no outlier points) and jittered individual data points. Uses viridis palette by default.
plot_violin_box(df, x, y, fill = x, title = NULL, ylab = y)plot_violin_box(df, x, y, fill = x, title = NULL, ylab = y)
df |
Data frame. |
x |
Character. Column name for x-axis (categorical). |
y |
Character. Column name for y-axis (numeric). |
fill |
Character. Column name for fill aesthetic. Default same as |
title |
Character. Plot title. Default |
ylab |
Character. Y-axis label. Default same as |
A ggplot2 object.
## Not run: plot_violin_box(df, x = "phase", y = "mscc", fill = "phase") ## End(Not run)## Not run: plot_violin_box(df, x = "phase", y = "mscc", fill = "phase") ## End(Not run)
Saves a ggplot2 plot at publication-ready resolution with white background.
save_fig(plot, filename, path, width = 7, height = 5, dpi = 600)save_fig(plot, filename, path, width = 7, height = 5, dpi = 600)
plot |
A ggplot2 object. |
filename |
Character. Output filename (e.g., |
path |
Character. Output directory. |
width |
Numeric. Figure width in inches. Default |
height |
Numeric. Figure height in inches. Default |
dpi |
Integer. Resolution. Default |
Character. Full path to saved file (invisible).
## Not run: p <- ggplot2::ggplot(mtcars, ggplot2::aes(wt, mpg)) + ggplot2::geom_point() save_fig(p, "test_plot.png", tempdir()) ## End(Not run)## Not run: p <- ggplot2::ggplot(mtcars, ggplot2::aes(wt, mpg)) + ggplot2::geom_point() save_fig(p, "test_plot.png", tempdir()) ## End(Not run)
Saves any R object as .rds with a confirmation message.
save_rds(obj, filename, path)save_rds(obj, filename, path)
obj |
Any R object. |
filename |
Character. Output filename (e.g., |
path |
Character. Output directory. |
Character. Full path to saved file (invisible).
## Not run: save_rds(mtcars, "cars.rds", tempdir()) ## End(Not run)## Not run: save_rds(mtcars, "cars.rds", tempdir()) ## End(Not run)
Saves a data frame as .xlsx via writexl.
save_table(df, filename, path)save_table(df, filename, path)
df |
A data frame. |
filename |
Character. Output filename (e.g., |
path |
Character. Output directory. |
Character. Full path to saved file (invisible).
## Not run: save_table(mtcars, "cars.xlsx", tempdir()) ## End(Not run)## Not run: save_table(mtcars, "cars.xlsx", tempdir()) ## End(Not run)
Colour and Fill Scales for Artifact Grades
scale_colour_artifact(...) scale_fill_artifact(...)scale_colour_artifact(...) scale_fill_artifact(...)
... |
Additional arguments passed to
|
A ggplot2 scale object.
Colour and Fill Scales for Imaging Modalities
scale_colour_modality(...) scale_fill_modality(...)scale_colour_modality(...) scale_fill_modality(...)
... |
Additional arguments passed to
|
A ggplot2 scale object.
Convenience wrappers around ggplot2::scale_colour_manual() and
ggplot2::scale_fill_manual() using pal_phase.
scale_colour_phase(...) scale_fill_phase(...)scale_colour_phase(...) scale_fill_phase(...)
... |
Additional arguments passed to
|
A ggplot2 scale object.
## Not run: ggplot(df, aes(x, y, colour = phase)) + geom_point() + scale_colour_phase() ## End(Not run)## Not run: ggplot(df, aes(x, y, colour = phase)) + geom_point() + scale_colour_phase() ## End(Not run)
Sets up a complete workflowr project with full directory structure,
pre-configured YAML files, template Rmd files, CSV templates, and
a .gitignore tuned for neuroimaging projects.
sci_create_project( path, title = "SCI Imaging Analysis", author = "Author Name", seed = 20260411L, open = TRUE )sci_create_project( path, title = "SCI Imaging Analysis", author = "Author Name", seed = 20260411L, open = TRUE )
path |
Character. Directory for the new project. |
title |
Character. Project title. |
author |
Character. Author name. |
seed |
Integer. Reproducibility seed. Default |
open |
Logical. Open project in RStudio. Default |
Character. Path to created project (invisible).
## Not run: sci_create_project("~/projects/my-sci-study", title = "Cervical SCI Longitudinal MRI Analysis", author = "Raban Heller") ## End(Not run)## Not run: sci_create_project("~/projects/my-sci-study", title = "Cervical SCI Longitudinal MRI Analysis", author = "Raban Heller") ## End(Not run)
Scans the project directory and reports which processing steps are complete for each patient and session.
sci_pipeline_status(project_dir)sci_pipeline_status(project_dir)
project_dir |
Character. Path to workflowr project root. |
Tibble with columns: pat_id, session, converted, sc_seg,
lesion_seg, vert_labels, qc_done, params_extracted.
## Not run: sci_pipeline_status("~/projects/my-sci-study") ## End(Not run)## Not run: sci_pipeline_status("~/projects/my-sci-study") ## End(Not run)
Orchestrates all external tool steps in sequence:
DICOM metadata extraction
Anonymization (if requested)
DICOM to NIfTI conversion
Spinal cord segmentation
Lesion segmentation (SCIsegV2)
Vertebral labeling
Parameter extraction
Merge & export
sci_run_pipeline( project_dir, steps = 1:8, anonymize = FALSE, overwrite = FALSE, verbose = TRUE )sci_run_pipeline( project_dir, steps = 1:8, anonymize = FALSE, overwrite = FALSE, verbose = TRUE )
project_dir |
Character. Path to workflowr project root. |
steps |
Integer vector. Which steps to run. Default |
anonymize |
Logical. Run anonymization step. Default |
overwrite |
Logical. Re-process existing outputs. Default |
verbose |
Logical. Print progress. Default |
Each step checks for existing outputs (idempotent). The pipeline can be interrupted and resumed at any step.
Tibble with pipeline status per step.
## Not run: sci_run_pipeline("~/projects/my-sci-study", steps = 1:3) ## End(Not run)## Not run: sci_run_pipeline("~/projects/my-sci-study", steps = 1:3) ## End(Not run)
Runs sct_analyze_lesion to compute lesion volume, length, max axial
damage ratio, and tissue bridge measurements.
sct_analyze_lesion(lesion_seg, sc_seg, output_dir = NULL, verbose = TRUE)sct_analyze_lesion(lesion_seg, sc_seg, output_dir = NULL, verbose = TRUE)
lesion_seg |
Character. Path to lesion segmentation NIfTI. |
sc_seg |
Character. Path to spinal cord segmentation NIfTI. |
output_dir |
Character. Directory for CSV output. |
verbose |
Logical. Print progress. Default |
Character. Path to output CSV, or NA on failure.
## Not run: sct_analyze_lesion("sub-01_lesion_seg.nii.gz", "sub-01_seg.nii.gz") ## End(Not run)## Not run: sct_analyze_lesion("sub-01_lesion_seg.nii.gz", "sub-01_seg.nii.gz") ## End(Not run)
Creates an HTML QC report overlaying a segmentation on the original image.
sct_generate_qc( input, segmentation, qc_dir, process = "sct_deepseg", verbose = TRUE )sct_generate_qc( input, segmentation, qc_dir, process = "sct_deepseg", verbose = TRUE )
input |
Character. Path to original NIfTI image. |
segmentation |
Character. Path to segmentation overlay. |
qc_dir |
Character. Directory for QC HTML output. |
process |
Character. SCT process name for labeling.
Default |
verbose |
Logical. Print progress. Default |
Exit code (invisible).
## Not run: sct_generate_qc("sub-01_T2w.nii.gz", "sub-01_T2w_seg.nii.gz", "qc/") ## End(Not run)## Not run: sct_generate_qc("sub-01_T2w.nii.gz", "sub-01_T2w_seg.nii.gz", "qc/") ## End(Not run)
Runs SCT's vertebral labeling on a spinal cord segmentation.
sct_label_vertebrae( input, segmentation, contrast = "t2", output_dir = NULL, overwrite = FALSE, verbose = TRUE )sct_label_vertebrae( input, segmentation, contrast = "t2", output_dir = NULL, overwrite = FALSE, verbose = TRUE )
input |
Character. Path to T2w NIfTI file. |
segmentation |
Character. Path to spinal cord segmentation. |
contrast |
Character. MRI contrast type. Default |
output_dir |
Character. Directory for output labels. Defaults to
the directory of |
overwrite |
Logical. Re-run if output exists? Default |
verbose |
Logical. Print progress. Default |
Character. Path to vertebral label NIfTI, or NA on failure.
## Not run: sct_label_vertebrae("sub-01_T2w.nii.gz", "sub-01_T2w_seg.nii.gz") ## End(Not run)## Not run: sct_label_vertebrae("sub-01_T2w.nii.gz", "sub-01_T2w_seg.nii.gz") ## End(Not run)
Runs sct_process_segmentation to compute cross-sectional area (CSA),
AP diameter, and transverse diameter per vertebral level.
sct_process_segmentation( sc_seg, vert_labels, output_dir = NULL, perslice = FALSE, verbose = TRUE )sct_process_segmentation( sc_seg, vert_labels, output_dir = NULL, perslice = FALSE, verbose = TRUE )
sc_seg |
Character. Path to spinal cord segmentation NIfTI. |
vert_labels |
Character. Path to vertebral labels NIfTI. |
output_dir |
Character. Directory for CSV output. |
perslice |
Logical. Compute per-slice metrics. Default |
verbose |
Logical. Print progress. Default |
Character. Path to output CSV, or NA on failure.
## Not run: sct_process_segmentation("sub-01_seg.nii.gz", "sub-01_labels-disc.nii.gz") ## End(Not run)## Not run: sct_process_segmentation("sub-01_seg.nii.gz", "sub-01_labels-disc.nii.gz") ## End(Not run)
Runs SCIsegV2 lesion segmentation model via SCT.
sct_segment_lesion( input, output = NULL, output_dir = NULL, overwrite = FALSE, verbose = TRUE, qc_dir = NULL )sct_segment_lesion( input, output = NULL, output_dir = NULL, overwrite = FALSE, verbose = TRUE, qc_dir = NULL )
input |
Character. Path to T2w NIfTI file (.nii.gz). |
output |
Character. Path for output segmentation. Auto-generated if
|
output_dir |
Character. Directory for output. Alternative to |
overwrite |
Logical. Re-run if output exists? Default |
verbose |
Logical. Print progress. Default |
qc_dir |
Character. If provided, auto-generate QC report. |
Character. Path to output lesion segmentation, or NA on failure.
## Not run: sct_segment_lesion("sub-01_T2w.nii.gz") ## End(Not run)## Not run: sct_segment_lesion("sub-01_T2w.nii.gz") ## End(Not run)
Runs SCT's contrast-agnostic spinal cord segmentation model.
sct_segment_sc( input, output = NULL, output_dir = NULL, overwrite = FALSE, verbose = TRUE, qc_dir = NULL )sct_segment_sc( input, output = NULL, output_dir = NULL, overwrite = FALSE, verbose = TRUE, qc_dir = NULL )
input |
Character. Path to NIfTI file (.nii.gz). |
output |
Character. Path for output segmentation. Auto-generated if
|
output_dir |
Character. Directory for output. Alternative to |
overwrite |
Logical. Re-run if output exists? Default |
verbose |
Logical. Print progress. Default |
qc_dir |
Character. If provided, auto-generate QC report. |
Character. Path to output segmentation file, or NA on failure.
## Not run: sct_segment_sc("sub-01_T2w.nii.gz") ## End(Not run)## Not run: sct_segment_sc("sub-01_T2w.nii.gz") ## End(Not run)
A clean ggplot2 theme based on ggplot2::theme_bw(), optimized for
publication-ready neuroimaging figures. Uses Arial font, no minor
gridlines, and a bottom legend.
theme_sci(base_size = 11, base_family = "Arial")theme_sci(base_size = 11, base_family = "Arial")
base_size |
Numeric. Base font size. Default |
base_family |
Character. Base font family. Default |
A ggplot2 theme object.
## Not run: library(ggplot2) ggplot(mtcars, aes(wt, mpg)) + geom_point() + theme_sci() ## End(Not run)## Not run: library(ggplot2) ggplot(mtcars, aes(wt, mpg)) + geom_point() + theme_sci() ## End(Not run)
Adds one or more QC entries to a QC log.
update_qc_log(qc_log, entries, output_csv = NULL)update_qc_log(qc_log, entries, output_csv = NULL)
qc_log |
Tibble. Existing QC log (from |
entries |
Data frame. New entries with the same columns as |
output_csv |
Character. Optional path to save updated log. |
Updated QC log tibble.
## Not run: qc <- create_qc_log() entry <- tibble::tibble( pat_id = "SCI001", session = "ses-01", rater = "RH", date = Sys.Date(), seg_type = "sc", quality = "good", notes = "" ) qc <- update_qc_log(qc, entry) ## End(Not run)## Not run: qc <- create_qc_log() entry <- tibble::tibble( pat_id = "SCI001", session = "ses-01", rater = "RH", date = Sys.Date(), seg_type = "sc", quality = "good", notes = "" ) qc <- update_qc_log(qc, entry) ## End(Not run)
Checks required columns and valid quality values.
validate_qc_log(qc_log)validate_qc_log(qc_log)
qc_log |
Data frame or path to CSV. |
Invisibly returns the validated QC log.
Checks: required columns present, no duplicate pat_id x session, dates are valid, days_post_trauma >= 0, artifact_grade in 0–4, modality in allowed values.
validate_registry(registry, strict = TRUE)validate_registry(registry, strict = TRUE)
registry |
Data frame or character path to CSV. |
strict |
Logical. Stop on errors ( |
Invisibly returns the validated registry tibble.
## Not run: validate_registry("data/metadata/imaging_registry.csv") ## End(Not run)## Not run: validate_registry("data/metadata/imaging_registry.csv") ## End(Not run)