This repository contains pipelines for pediatric spinal cord data analysis. It includes both a pipeline to extract and analyze spinal cord morphometrics (using T2w and T2*w data), as well as a pipeline for DTI analysis using DWI data.
For this project, MRI data from the philadelphia-pediatric dataset was used, which includes typically-developing subjects aged 6 to 17.
The scripts inside this repository are organized as follows:
└── scripts
└── preprocessing
├── T2w_data_preprocessing.sh
├── T2starw_data_preprocessing.sh
├── T1w_data_preprocessing.sh
└── DWI_data_preprocessing.sh
└── analysis
├── morphometrics.py # Requires running T2w_data_preprcessing.sh
├── rootlets.py # Requires running T2w_data_preprcessing.sh
└── GM_WM_distribution.py # Requires running T2starw_data_preprcessing.sh and T2w_data_processing.sh
The results are organized as follows :
└── results
└── tables # This folder will be created to store the output CSV files when running the scripts above (i.e., to store per-participant extracted morphometrics, DTI values, etc.)
└── plots # This folder contains scripts to generate figures using the CSV files inside the `tables` folder
To run the scripts in this repository, you will need the following installed or cloned on your local computer:
- The Spinal Cord Toolbox (SCT), version 7.0
- A local clone of the spinal cord rootlet segmentation model (release r20250318)
yq, to process anexclude.ymlfile to exclude subjects from the analysis
To execute the scripts in this repo, you will need the following configuration files, located inside the config folder :
config_morphometrics.yaml: configuration file to process morphometricsconfig_rootlets.yaml: configuration file to process spinal rootlets
Note
Template versions of these configuration files are provided in the config folder, with a _template suffix. Before running the scripts, rename each config file by removing the _template suffix.
Inside the configuration files, you will need to set the following parameters:
path_data: the path to your local copy of the datasetpath_output: the path to where you want the output results savedjobs: the number of cores you want to use to run subjects in parallelscript_args: the path to your local clone of the spinal cord rootlet segmentation model (r20250318)include_list: the list of subjects you want to process
To run the scripts in this repository, you first need to activate the Spinal Cord Toolbox (SCT) virtual environment named venv_sct. You can activate it with the following command:
conda activate /path/to/your/venv_sct
Tip
To find the exact path to venv_sct on your system, run conda env list to display all conda environments
To run the scripts described in the following sections, make sure to change your directory to the project’s repository in your terminal:
cd path/to/your/local/clone/pediatric_data-analysis
The script T2w_data_preprocessing.sh (inside scripts/preprocessing) performs the following preprocessing steps on the T2w data :
- Segmentation of spinal cord from T2w data (sct_deepseg_sc)
- Detection of PMJ from T2w data (sct_detect_pmj)
- Labeling of vertebral levels from T2w data (sct_label_vertebrae)
- Segmentation of rootlets from T2w data (model-spinal-rootlets_ventral_D106_r20250318)
In order to run the script in parallel, the sct_run_batch command can be used as follows :
sct_run_batch -config config/config_preprocessing.yaml -script scripts/preprocessing/T2w_data_preprocessing.sh
The script morphometrics.py (inside scripts/analysis) allows to :
- Get the labeled segmentation from the disc labels on the preprocessed T2w data (using
sct_label_vertebrae) - Run sct_process_segmentation to compute spinal cord morphometrics (cross-sectional area, diameter, etc.)
To run this python script in pararallel, you can use the bash wrapper called wrapper_morphometrics.sh inside the sct_run_batch command :
sct_run_batch -config config/config.yaml -script wrappers/wrapper_morphometrics.sh
The script rootlets.py (inside scripts/analysis) :
- Runs
zeroing_false_positive_rootlets.pyfrom the model-spinal-rootlets/pediatric_rootlets directory to remove false positive rootlets below the Th1 level. - Runs
02a_rootlets_to_spinal_levels.pyfrom the model-spinal-rootlets/inter-rater_variability directory to extract spinal levels from the rootlets segmentation - Extracts the center of mass of each spinal level and saves it in a CSV file
The wrapper_rootlets.sh wrapper can be used to run the rootlets.py script in parallel with sct_run_batch :
sct_run_batch -config config/config.yaml -script wrappers/wrapper_rootlets.sh
The script GM_WM_distribution.py (inside scripts/analysis) extracts the CSA of GM and WM in the native T2*w space, at each spinal level along the spinal cord.
It requires as inputs (in the native T2*w space):
- T2*-weighted image (in the native space)
- The spinal cord segmentation
- The gray matter segmentation
- The white matter segmentation
- Single-voxel point labels for the start and end of each spinal level (registered from the spinal levels in the T2w space)
To extract GM and WM CSA in the native T2*w, the script:
- Gets the slices corresponding to the start and end (inferior and superior limits) of each spinal level from the single-voxel point labels
- Computes the slices between these start and end slices for each spinal level to get the slice range corresponding to each spinal level in the T2*w space
- Runs
sct_process_segmentation(for each spinal level) to compute the CSA of GM, WM and SC (using the-zflag to define the slice range)
For each subject, an output CSV file are saved in results/tables/GM_WM_distribution/ within folders WM, GM and SC.
The wrapper_GM_WM_distribution.sh wrapper can be used to run the GM_WM_distribution.py script in parallel with sct_run_batch :
sct_run_batch -config config/config.yaml -script wrappers/wrapper_GM_WM_distribution.sh
Inside results/plots, the following jupyter notebooks contain code to generate figures related to pediatric spinal cord morphometrics:
morphometrics.ipynb: figures for CSA analysis, right-left (RL) and antero-posterior (AP) diameters, etc.WMGM_distribution_figures.ipynb: figures for WM/GM distribution analysisgenerate_figure_rootlets_and_vertebral_spinal_levels.py: figure to compare spinal levels with vertebral levels (with their distances from the PMJ)get_distributions_and_sizes_vertebral_spinal_levels.py: figure to plot the distribution of spinal and vertebral levels (approximated by normal distributions)
The script generate_figure_rootlets_and_vertebral_spinal_levels.py contains code to generate figures comparing the correspondence between vertebral and spinal levels.
The script dwi_data_preprocessing.sh (inside scripts/preprocessing) performs the following preprocessing steps on the DWI data:
- Generate the mean DWI image
- Spinal cord segmentation
- Motion correction
- Compute DTI metrics
- Registration of T2w (or T1w) data to the PAM50 template (to generate initialization warping fields for DWI registration).
- Registration of the PAM50 template to the DWI space
- Extract DTI metrics using the PAM50 atlas registered to the DWI space
In order to run the script in parallel, the sct_run_batch command can be used as follows :
sct_run_batch -config config/config_preprocessing.yaml -script scripts/preprocessing/dwi_data_preprocessing.sh
Inside results/plots, the jupyter notebook DWI_figures.ipynb contains code to generate figures related to DTI analysis.