Advanced Python tool for extracting connectivity matrices using DSI Studio with comprehensive validation, batch processing, and organized output structure.
cd installation/
bash setup_env.sh
source ../venv/bin/activatePython dependencies are maintained in requirements.txt at the repository root.
The installer uses UV for lightning-fast package installation (10-100x faster than pip).
See Installation Guide for detailed setup instructions.
python scripts/connectivity/validate_setup.py --config configs/example_config.json --test-input /path/to/data/python scripts/pipeline/dsi_studio_pipeline.py \
--qsiprep_dir /path/to/qsiprep \
--output_dir /path/to/output \
--pilotpython scripts/pipeline/dsi_studio_pipeline.py \
--qsiprep_dir /path/to/qsiprep \
--output_dir /path/to/output \
--run_connectivity \
--connectivity_config configs/graph_analysis_config.jsondsistudio/
βββ README.md # This file
βββ requirements.txt # Canonical Python dependencies
βββ installation/ # Setup & installation files
β βββ setup_env.sh # Environment setup script
β βββ install.sh # Installation helper
β βββ requirements.txt # Compatibility include (-r ../requirements.txt)
βββ scripts/ # All executable scripts
β βββ pipeline/
β β βββ dsi_studio_pipeline.py
β β βββ create_differential_fib.py
β β βββ monitor_pipeline.sh
β βββ connectivity/
β β βββ extract_connectivity_matrices.py
β β βββ run_connectometry_batch.py
β β βββ validate_setup.py
β β βββ convert_mat_to_csv.py
β β βββ generate_jpgs_from_tt.py
β βββ visualization/
β β βββ generate_interactive_viewer.py
β β βββ create_thumbnail_pdfs.py
β βββ qa/
β β βββ check_fib_metrics.py
β βββ web/
β β βββ webui.py
β βββ common/
β β βββ utils.py
β βββ web_logs/
β βββ web_settings/
βββ configs/ # Configuration templates
β βββ example_config.json
β βββ graph_analysis_config.json
β βββ connectivity_config.json
β βββ *.json
βββ docs/ # Documentation
β βββ CONFIGURATION_GUIDE.md # Detailed config reference
β βββ PIPELINE_ENHANCEMENTS.md # Feature overview
β βββ ENHANCEMENTS_SUMMARY.txt
β βββ SCRIPT_INDEX.md # Script inventory and cleanup guidance
βββ legacy/ # Archived non-primary shell scripts
β βββ scripts/
β βββ code/
βββ code/ # Shared utilities & libraries
python scripts/pipeline/dsi_studio_pipeline.py \
--qsiprep_dir /path/to/qsiprep \
--output_dir /path/to/output \
--dsi_studio_path /path/to/dsi-studio/python scripts/pipeline/dsi_studio_pipeline.py \
--qsiprep_dir /path/to/qsiprep \
--output_dir /path/to/output \
--run_connectivity \
--connectivity_config configs/graph_analysis_config.jsonpython scripts/pipeline/dsi_studio_pipeline.py \
--qsiprep_dir /path/to/qsiprep \
--output_dir /path/to/output \
--skip_existingpython scripts/pipeline/dsi_studio_pipeline.py \
--qsiprep_dir /path/to/qsiprep \
--output_dir /path/to/output \
--skip_existing --forcepython scripts/connectivity/extract_connectivity_matrices.py \
--config configs/graph_analysis_config.json \
subject.fz output_dir/python scripts/connectivity/extract_connectivity_matrices.py \
--config configs/graph_analysis_config.json \
--batch /data/directory/ output_dir/python scripts/connectivity/extract_connectivity_matrices.py \
--config configs/graph_analysis_config.json \
--batch /data/directory/ output_dir/ \
--pilot --pilot-count 2# Basic validation
python scripts/connectivity/validate_setup.py
# With specific config
python scripts/connectivity/validate_setup.py --config configs/example_config.json| Flag | Purpose | Example |
|---|---|---|
--qsiprep_dir |
QSIPrep output directory | --qsiprep_dir /data/qsiprep |
--output_dir |
Output directory | --output_dir /data/output |
--dsi_studio_path |
DSI Studio installation | --dsi_studio_path /path/to/dsi-studio/ |
--run_connectivity |
Enable connectivity analysis | --run_connectivity |
--connectivity_config |
Configuration file | --connectivity_config configs/graph_analysis_config.json |
--skip_existing |
Skip existing outputs | --skip_existing |
--force |
Force regeneration | --force |
--pilot |
Test mode | --pilot |
| Option | Purpose | Example |
|---|---|---|
--config |
Configuration file | --config configs/graph_analysis_config.json |
--batch |
Batch processing mode | --batch |
--pilot |
Test 1-2 files | --pilot |
--pilot-count |
Number of pilot files | --pilot-count 2 |
--pattern |
File pattern | --pattern "*.fz" |
--tracks |
Override track count | --tracks 50000 |
--atlases |
Override atlases | --atlases "AAL3,Brainnetome" |
{
"dsi_studio_cmd": "/path/to/dsi_studio",
"atlases": ["AAL3", "Brainnetome"],
"connectivity_values": ["count", "fa", "qa"],
"track_count": 100000,
"thread_count": 8,
"tracking_parameters": {
"method": 0,
"fa_threshold": 0.0,
"turning_angle": 45.0,
"min_length": 0,
"max_length": 0
}
}- AAL Family: AAL, AAL2, AAL3
- Functional: Brodmann, HCP-MMP, AICHA
- Structural: Talairach, FreeSurferDKT, FreeSurferDKT_Cortical
- Parcellations: Schaefer100/200/400, Gordon333, Power264
- count - Number of streamlines
- ncount - Normalized count
- mean_length - Average streamline length
- qa - Quantitative anisotropy (GQI)
- fa - Fractional anisotropy (DTI)
- dti_fa, dti_md, dti_ad, dti_rd - DTI-specific metrics
- md - Mean diffusivity
- ad - Axial diffusivity
- rd - Radial diffusivity
See Configuration Guide for detailed reference.
output_folder/
βββ subject_20240806_143022/
β βββ tracks_100k_streamline/
β βββ by_atlas/ # Results organized by atlas
β β βββ AAL3/
β β βββ Brainnetome/
β β βββ FreeSurferDKT/
β βββ by_metric/ # Results organized by metric
β β βββ count/
β β βββ fa/
β β βββ qa/
β βββ combined/ # All results in one place
β βββ logs/ # Processing logs & summaries
β βββ extraction_summary.json
β βββ processing_results.csv
-
Setup environment
cd installation && bash setup_env.sh && cd .. source venv/bin/activate
-
Validate installation
python scripts/connectivity/validate_setup.py --config configs/example_config.json
-
Test with pilot
python scripts/pipeline/dsi_studio_pipeline.py \ --qsiprep_dir /path/to/qsiprep \ --output_dir /path/to/output \ --pilot -
Run full pipeline
python scripts/pipeline/dsi_studio_pipeline.py \ --qsiprep_dir /path/to/qsiprep \ --output_dir /path/to/output \ --run_connectivity \ --connectivity_config configs/graph_analysis_config.json
# Batch extraction with custom config
python scripts/connectivity/extract_connectivity_matrices.py \
--config configs/graph_analysis_config.json \
--batch /data/subjects/ output/ \
--tracks 100000 --threads 16# Run pipeline in background
nohup python scripts/pipeline/dsi_studio_pipeline.py \
--qsiprep_dir /path/to/qsiprep \
--output_dir /path/to/output \
> pipeline.log 2>&1 &
# Monitor progress
tail -f pipeline.log- Ensure DSI Studio is installed
- Verify
--dsi_studio_pathpoints to the correct installation - On macOS, often at:
/Applications/dsi_studio.app/Contents/MacOS/dsi_studio
# Add to ~/.zshrc or ~/.bash_profile
export FSLDIR=/usr/local/fsl
. ${FSLDIR}/etc/fslconf/fsl.sh
export PATH=${FSLDIR}/bin:${PATH}# Validate configuration before running
python scripts/connectivity/validate_setup.py --config configs/your_config.json- Start with pilot mode to test
- Check generated logs in output directory
- Review detailed error messages
- Configuration Guide - Complete reference for configuration options
- Pipeline Enhancements - Feature overview and capabilities
- Enhanced Summary - Additional details
- Script Index - Script purposes and cleanup recommendations
| Script | Purpose |
|---|---|
pipeline/dsi_studio_pipeline.py |
Main processing pipeline |
connectivity/extract_connectivity_matrices.py |
Connectivity matrix extraction |
connectivity/run_connectometry_batch.py |
Batch connectometry analysis |
connectivity/validate_setup.py |
Setup validation tool |
web/webui.py |
Web UI for visualization |
qa/check_fib_metrics.py |
FIB metrics and --inspect single-file mode |
pipeline/monitor_pipeline.sh |
Pipeline log monitor |
| File | Purpose |
|---|---|
example_config.json |
Basic example configuration |
graph_analysis_config.json |
Connectivity analysis config |
connectivity_config.json |
Extended template |
research_config.json |
Research-specific settings |
# Show help for any script
python scripts/pipeline/dsi_studio_pipeline.py --help
python scripts/connectivity/extract_connectivity_matrices.py --help
python scripts/connectivity/validate_setup.py --helpFor detailed configuration information, see docs/CONFIGURATION_GUIDE.md
For feature details, see docs/PIPELINE_ENHANCEMENTS.md