csttool 0.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (197) hide show
  1. csttool-0.5.0/.github/workflows/ci.yml +69 -0
  2. csttool-0.5.0/.github/workflows/docs.yaml +24 -0
  3. csttool-0.5.0/.gitignore +65 -0
  4. csttool-0.5.0/CHANGELOG.md +187 -0
  5. csttool-0.5.0/LICENSE +21 -0
  6. csttool-0.5.0/PKG-INFO +167 -0
  7. csttool-0.5.0/README.md +136 -0
  8. csttool-0.5.0/diagrams/mermaid/batch.mmd +75 -0
  9. csttool-0.5.0/diagrams/mermaid/check.mmd +82 -0
  10. csttool-0.5.0/diagrams/mermaid/check_dataset.mmd +68 -0
  11. csttool-0.5.0/diagrams/mermaid/extraction.mmd +86 -0
  12. csttool-0.5.0/diagrams/mermaid/import_cmd.mmd +74 -0
  13. csttool-0.5.0/diagrams/mermaid/metrics.mmd +99 -0
  14. csttool-0.5.0/diagrams/mermaid/pipeline_overview.mmd +22 -0
  15. csttool-0.5.0/diagrams/mermaid/preprocess.mmd +98 -0
  16. csttool-0.5.0/diagrams/mermaid/run.mmd +110 -0
  17. csttool-0.5.0/diagrams/mermaid/tracking.mmd +63 -0
  18. csttool-0.5.0/diagrams/mermaid/validate.mmd +100 -0
  19. csttool-0.5.0/docs/assets/figures/cst.png +0 -0
  20. csttool-0.5.0/docs/assets/figures/diffusion_ellipsoid.png +0 -0
  21. csttool-0.5.0/docs/assets/figures/dti_limits_a.png +0 -0
  22. csttool-0.5.0/docs/assets/figures/dti_limits_b.png +0 -0
  23. csttool-0.5.0/docs/assets/figures/dwi_sequence.png +0 -0
  24. csttool-0.5.0/docs/assets/figures/roi_operations.png +0 -0
  25. csttool-0.5.0/docs/assets/figures/stejskal_tanner.png +0 -0
  26. csttool-0.5.0/docs/contributing/architecture.md +89 -0
  27. csttool-0.5.0/docs/contributing/code-style.md +414 -0
  28. csttool-0.5.0/docs/contributing/contributing.md +31 -0
  29. csttool-0.5.0/docs/contributing/development-setup.md +79 -0
  30. csttool-0.5.0/docs/explanation/cst-anatomy.md +47 -0
  31. csttool-0.5.0/docs/explanation/design-decisions.md +95 -0
  32. csttool-0.5.0/docs/explanation/diffusion-mri.md +79 -0
  33. csttool-0.5.0/docs/explanation/explanation.md +10 -0
  34. csttool-0.5.0/docs/explanation/limitations.md +165 -0
  35. csttool-0.5.0/docs/explanation/references.md +41 -0
  36. csttool-0.5.0/docs/explanation/tractography.md +84 -0
  37. csttool-0.5.0/docs/getting-started/data-requirements.md +193 -0
  38. csttool-0.5.0/docs/getting-started/installation.md +193 -0
  39. csttool-0.5.0/docs/getting-started/quickstart.md +129 -0
  40. csttool-0.5.0/docs/how-to/data-formats.md +61 -0
  41. csttool-0.5.0/docs/how-to/how-to.md +9 -0
  42. csttool-0.5.0/docs/how-to/multiple-subjects.md +83 -0
  43. csttool-0.5.0/docs/how-to/troubleshooting.md +97 -0
  44. csttool-0.5.0/docs/index.md +59 -0
  45. csttool-0.5.0/docs/javascripts/placeholder.md +0 -0
  46. csttool-0.5.0/docs/reference/api/extract.md +16 -0
  47. csttool-0.5.0/docs/reference/api/metrics.md +17 -0
  48. csttool-0.5.0/docs/reference/api/preprocess.md +16 -0
  49. csttool-0.5.0/docs/reference/api/tracking.md +17 -0
  50. csttool-0.5.0/docs/reference/cli/batch.md +135 -0
  51. csttool-0.5.0/docs/reference/cli/check.md +18 -0
  52. csttool-0.5.0/docs/reference/cli/check_dataset.md +296 -0
  53. csttool-0.5.0/docs/reference/cli/doctor.md +98 -0
  54. csttool-0.5.0/docs/reference/cli/extract.md +312 -0
  55. csttool-0.5.0/docs/reference/cli/fetch-data.md +251 -0
  56. csttool-0.5.0/docs/reference/cli/import.md +134 -0
  57. csttool-0.5.0/docs/reference/cli/metrics.md +99 -0
  58. csttool-0.5.0/docs/reference/cli/overview.md +78 -0
  59. csttool-0.5.0/docs/reference/cli/preprocess.md +80 -0
  60. csttool-0.5.0/docs/reference/cli/run.md +167 -0
  61. csttool-0.5.0/docs/reference/cli/track.md +96 -0
  62. csttool-0.5.0/docs/reference/cli/validate.md +71 -0
  63. csttool-0.5.0/docs/reference/output-formats.md +179 -0
  64. csttool-0.5.0/docs/reference/parameters.md +181 -0
  65. csttool-0.5.0/docs/reference/v0.4.0-updates.md +175 -0
  66. csttool-0.5.0/docs/stylesheets/placeholder.md +0 -0
  67. csttool-0.5.0/docs/tutorials/batch-processing.md +104 -0
  68. csttool-0.5.0/docs/tutorials/first-analysis.md +90 -0
  69. csttool-0.5.0/environment.yml +35 -0
  70. csttool-0.5.0/mkdocs.yml +144 -0
  71. csttool-0.5.0/pyproject.toml +48 -0
  72. csttool-0.5.0/src/csttool/__init__.py +2 -0
  73. csttool-0.5.0/src/csttool/batch/__init__.py +23 -0
  74. csttool-0.5.0/src/csttool/batch/batch.py +389 -0
  75. csttool-0.5.0/src/csttool/batch/modules/__init__.py +5 -0
  76. csttool-0.5.0/src/csttool/batch/modules/discover.py +195 -0
  77. csttool-0.5.0/src/csttool/batch/modules/locking.py +76 -0
  78. csttool-0.5.0/src/csttool/batch/modules/logging_setup.py +91 -0
  79. csttool-0.5.0/src/csttool/batch/modules/manifest.py +100 -0
  80. csttool-0.5.0/src/csttool/batch/modules/report.py +176 -0
  81. csttool-0.5.0/src/csttool/batch/modules/validation.py +128 -0
  82. csttool-0.5.0/src/csttool/bids/__init__.py +19 -0
  83. csttool-0.5.0/src/csttool/bids/output.py +372 -0
  84. csttool-0.5.0/src/csttool/cli/__init__.py +834 -0
  85. csttool-0.5.0/src/csttool/cli/commands/__init__.py +0 -0
  86. csttool-0.5.0/src/csttool/cli/commands/batch.py +212 -0
  87. csttool-0.5.0/src/csttool/cli/commands/check.py +9 -0
  88. csttool-0.5.0/src/csttool/cli/commands/check_dataset.py +214 -0
  89. csttool-0.5.0/src/csttool/cli/commands/doctor.py +250 -0
  90. csttool-0.5.0/src/csttool/cli/commands/extract.py +563 -0
  91. csttool-0.5.0/src/csttool/cli/commands/fetch_data.py +253 -0
  92. csttool-0.5.0/src/csttool/cli/commands/import_cmd.py +325 -0
  93. csttool-0.5.0/src/csttool/cli/commands/metrics.py +310 -0
  94. csttool-0.5.0/src/csttool/cli/commands/preprocess.py +43 -0
  95. csttool-0.5.0/src/csttool/cli/commands/run.py +810 -0
  96. csttool-0.5.0/src/csttool/cli/commands/track.py +209 -0
  97. csttool-0.5.0/src/csttool/cli/commands/validate.py +220 -0
  98. csttool-0.5.0/src/csttool/cli/utils.py +282 -0
  99. csttool-0.5.0/src/csttool/data/LICENSES/FSL_LICENSE.txt +47 -0
  100. csttool-0.5.0/src/csttool/data/LICENSES/MNI152_LICENSE.txt +15 -0
  101. csttool-0.5.0/src/csttool/data/__init__.py +27 -0
  102. csttool-0.5.0/src/csttool/data/loader.py +303 -0
  103. csttool-0.5.0/src/csttool/data/manifest.py +146 -0
  104. csttool-0.5.0/src/csttool/data/mni152/MNI152_T1_1mm.nii.gz +0 -0
  105. csttool-0.5.0/src/csttool/extract/__init__.py +11 -0
  106. csttool-0.5.0/src/csttool/extract/modules/__init__.py +39 -0
  107. csttool-0.5.0/src/csttool/extract/modules/bidirectional_filtering.py +356 -0
  108. csttool-0.5.0/src/csttool/extract/modules/coordinate_validation.py +250 -0
  109. csttool-0.5.0/src/csttool/extract/modules/create_roi_masks.py +448 -0
  110. csttool-0.5.0/src/csttool/extract/modules/diagnostic.py +37 -0
  111. csttool-0.5.0/src/csttool/extract/modules/endpoint_filtering.py +442 -0
  112. csttool-0.5.0/src/csttool/extract/modules/passthrough_filtering.py +522 -0
  113. csttool-0.5.0/src/csttool/extract/modules/registration.py +976 -0
  114. csttool-0.5.0/src/csttool/extract/modules/roi_seeded_tracking.py +483 -0
  115. csttool-0.5.0/src/csttool/extract/modules/save_extract_outputs.py +0 -0
  116. csttool-0.5.0/src/csttool/extract/modules/visualizations.py +1089 -0
  117. csttool-0.5.0/src/csttool/extract/modules/warp_atlas_to_subject.py +642 -0
  118. csttool-0.5.0/src/csttool/ingest/__init__.py +339 -0
  119. csttool-0.5.0/src/csttool/ingest/modules/__init__.py +62 -0
  120. csttool-0.5.0/src/csttool/ingest/modules/analyze_series.py +500 -0
  121. csttool-0.5.0/src/csttool/ingest/modules/assess_quality.py +413 -0
  122. csttool-0.5.0/src/csttool/ingest/modules/convert_series.py +380 -0
  123. csttool-0.5.0/src/csttool/ingest/modules/save_ingest_outputs.py +348 -0
  124. csttool-0.5.0/src/csttool/ingest/modules/scan_study.py +291 -0
  125. csttool-0.5.0/src/csttool/metrics/__init__.py +77 -0
  126. csttool-0.5.0/src/csttool/metrics/modules/__init__.py +32 -0
  127. csttool-0.5.0/src/csttool/metrics/modules/bilateral_analysis.py +376 -0
  128. csttool-0.5.0/src/csttool/metrics/modules/reports.py +687 -0
  129. csttool-0.5.0/src/csttool/metrics/modules/templates/report.css +382 -0
  130. csttool-0.5.0/src/csttool/metrics/modules/templates/report.html.j2 +216 -0
  131. csttool-0.5.0/src/csttool/metrics/modules/unilateral_analysis.py +458 -0
  132. csttool-0.5.0/src/csttool/metrics/modules/visualizations.py +812 -0
  133. csttool-0.5.0/src/csttool/preprocess/__init__.py +42 -0
  134. csttool-0.5.0/src/csttool/preprocess/modules/__init__.py +23 -0
  135. csttool-0.5.0/src/csttool/preprocess/modules/background_segmentation.py +63 -0
  136. csttool-0.5.0/src/csttool/preprocess/modules/denoise.py +78 -0
  137. csttool-0.5.0/src/csttool/preprocess/modules/gibbs_unringing.py +47 -0
  138. csttool-0.5.0/src/csttool/preprocess/modules/load_dataset.py +125 -0
  139. csttool-0.5.0/src/csttool/preprocess/modules/perform_motion_correction.py +55 -0
  140. csttool-0.5.0/src/csttool/preprocess/modules/reslice_voxels.py +46 -0
  141. csttool-0.5.0/src/csttool/preprocess/modules/save_preprocessed.py +136 -0
  142. csttool-0.5.0/src/csttool/preprocess/modules/visualizations.py +725 -0
  143. csttool-0.5.0/src/csttool/preprocess/preprocess.py +242 -0
  144. csttool-0.5.0/src/csttool/reproducibility/__init__.py +14 -0
  145. csttool-0.5.0/src/csttool/reproducibility/context.py +56 -0
  146. csttool-0.5.0/src/csttool/reproducibility/provenance.py +120 -0
  147. csttool-0.5.0/src/csttool/reproducibility/tolerance.py +185 -0
  148. csttool-0.5.0/src/csttool/tracking/__init__.py +19 -0
  149. csttool-0.5.0/src/csttool/tracking/modules/__init__.py +45 -0
  150. csttool-0.5.0/src/csttool/tracking/modules/estimate_directions.py +129 -0
  151. csttool-0.5.0/src/csttool/tracking/modules/fit_tensors.py +103 -0
  152. csttool-0.5.0/src/csttool/tracking/modules/load_and_mask.py +57 -0
  153. csttool-0.5.0/src/csttool/tracking/modules/run_tractography.py +79 -0
  154. csttool-0.5.0/src/csttool/tracking/modules/save_tracking_outputs.py +181 -0
  155. csttool-0.5.0/src/csttool/tracking/modules/seed_and_stop.py +70 -0
  156. csttool-0.5.0/src/csttool/tracking/modules/visualizations.py +780 -0
  157. csttool-0.5.0/src/csttool/validation/__init__.py +30 -0
  158. csttool-0.5.0/src/csttool/validation/bundle_comparison.py +414 -0
  159. csttool-0.5.0/src/csttool/validation/visualization.py +114 -0
  160. csttool-0.5.0/tests/__init__.py +0 -0
  161. csttool-0.5.0/tests/batch/test_batch_report.py +145 -0
  162. csttool-0.5.0/tests/batch/test_discover.py +77 -0
  163. csttool-0.5.0/tests/batch/test_locking.py +55 -0
  164. csttool-0.5.0/tests/batch/test_manifest.py +72 -0
  165. csttool-0.5.0/tests/batch/test_validation.py +68 -0
  166. csttool-0.5.0/tests/bids/__init__.py +0 -0
  167. csttool-0.5.0/tests/bids/test_output.py +124 -0
  168. csttool-0.5.0/tests/cli_test.sh +87 -0
  169. csttool-0.5.0/tests/conftest.py +66 -0
  170. csttool-0.5.0/tests/extract/__init__.py +0 -0
  171. csttool-0.5.0/tests/extract/manual_extract_check.py +1056 -0
  172. csttool-0.5.0/tests/extract/test_coordinate_validation.py +247 -0
  173. csttool-0.5.0/tests/extract/test_extract.py +58 -0
  174. csttool-0.5.0/tests/extract/test_filtering.py +84 -0
  175. csttool-0.5.0/tests/extract/test_registration.py +65 -0
  176. csttool-0.5.0/tests/ingest/manual_ingest_check.py +479 -0
  177. csttool-0.5.0/tests/ingest/test_assess_quality.py +402 -0
  178. csttool-0.5.0/tests/ingest/test_ingest.py +28 -0
  179. csttool-0.5.0/tests/integration/conftest.py +78 -0
  180. csttool-0.5.0/tests/integration/test_optional_preprocess.py +97 -0
  181. csttool-0.5.0/tests/integration/test_pipeline.py +318 -0
  182. csttool-0.5.0/tests/metrics/__init__.py +0 -0
  183. csttool-0.5.0/tests/metrics/test_bilateral.py +110 -0
  184. csttool-0.5.0/tests/metrics/test_metrics.py +126 -0
  185. csttool-0.5.0/tests/metrics/test_reports.py +223 -0
  186. csttool-0.5.0/tests/preprocess/__init__.py +0 -0
  187. csttool-0.5.0/tests/preprocess/test_modules.py +194 -0
  188. csttool-0.5.0/tests/reproducibility/__init__.py +1 -0
  189. csttool-0.5.0/tests/reproducibility/conftest.py +213 -0
  190. csttool-0.5.0/tests/reproducibility/test_determinism.py +186 -0
  191. csttool-0.5.0/tests/reproducibility/test_metric_stability.py +177 -0
  192. csttool-0.5.0/tests/test_cli.py +55 -0
  193. csttool-0.5.0/tests/test_data_loader.py +275 -0
  194. csttool-0.5.0/tests/tracking/__init__.py +0 -0
  195. csttool-0.5.0/tests/tracking/test_tracking_modules.py +68 -0
  196. csttool-0.5.0/tests/validation/test_bundle_comparison.py +155 -0
  197. csttool-0.5.0/tests/validation/test_cli_validate.py +156 -0
@@ -0,0 +1,69 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ tags: ["v*"]
7
+ pull_request:
8
+ branches: [main]
9
+
10
+ jobs:
11
+ # ---------------------------------------------------------------------------
12
+ # test: run on every push and PR, across all supported platforms + versions
13
+ # ---------------------------------------------------------------------------
14
+ test:
15
+ runs-on: ${{ matrix.os }}
16
+ strategy:
17
+ fail-fast: false
18
+ matrix:
19
+ os: [ubuntu-latest, macos-latest, windows-latest]
20
+ python-version: ["3.10", "3.11", "3.12"]
21
+
22
+ steps:
23
+ - uses: actions/checkout@v4
24
+
25
+ - uses: actions/setup-python@v5
26
+ with:
27
+ python-version: ${{ matrix.python-version }}
28
+
29
+ - name: Install csttool with test dependencies
30
+ run: pip install -e ".[test]"
31
+
32
+ - name: Run tests
33
+ run: pytest tests/ -x -q
34
+
35
+ # ---------------------------------------------------------------------------
36
+ # publish: triggered on a v* tag only, after tests pass
37
+ #
38
+ # Prerequisites (one-time setup on PyPI):
39
+ # 1. Create the csttool project on https://pypi.org
40
+ # 2. Under the project > Settings > Publishing, add a Trusted Publisher:
41
+ # Owner: alemnalo
42
+ # Repo: csttool
43
+ # Workflow: ci.yml
44
+ # Environment: (leave blank)
45
+ # This replaces API token auth with keyless OIDC — no secrets to manage.
46
+ # ---------------------------------------------------------------------------
47
+ publish:
48
+ needs: test
49
+ runs-on: ubuntu-latest
50
+ if: startsWith(github.ref, 'refs/tags/v')
51
+
52
+ permissions:
53
+ id-token: write # required for PyPI trusted publishing
54
+
55
+ steps:
56
+ - uses: actions/checkout@v4
57
+
58
+ - uses: actions/setup-python@v5
59
+ with:
60
+ python-version: "3.11"
61
+
62
+ - name: Install hatch
63
+ run: pip install hatch
64
+
65
+ - name: Build distributions
66
+ run: hatch build
67
+
68
+ - name: Publish to PyPI
69
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,24 @@
1
+ name: Deploy Documentation
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ workflow_dispatch:
8
+
9
+ permissions:
10
+ contents: write
11
+
12
+ jobs:
13
+ deploy:
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+
18
+ - uses: actions/setup-python@v4
19
+ with:
20
+ python-version: 3.x
21
+
22
+ - run: pip install -e . mkdocs-material mkdocstrings[python] pymdown-extensions
23
+
24
+ - run: mkdocs gh-deploy --force
@@ -0,0 +1,65 @@
1
+ # Python virtual environments
2
+ .venv/
3
+ env/
4
+
5
+ # Build artifacts
6
+ __pycache__/
7
+ *.pyc
8
+ *.pyo
9
+ *.pyd
10
+ *.egg-info/
11
+ build/
12
+ dist/
13
+
14
+ # IDE / editor junk
15
+ .vscode/
16
+ .spyproject
17
+ .idea/
18
+ .DS_Store
19
+
20
+ # Test & coverage
21
+ .pytest_cache/
22
+ .coverage
23
+ htmlcov/
24
+
25
+ # Generated outputs
26
+ validation_output/
27
+
28
+ #MkDocs
29
+ site/
30
+
31
+ # Claude
32
+ .claude
33
+
34
+ # Thesis build artifacts (source .tex/.bib/figures are tracked)
35
+ thesis/*.aux
36
+ thesis/*.bbl
37
+ thesis/*.bcf
38
+ thesis/*.blg
39
+ thesis/*.fdb_latexmk
40
+ thesis/*.fls
41
+ thesis/*.log
42
+ thesis/*.out
43
+ thesis/*.pdf
44
+ thesis/*.run.xml
45
+ thesis/*.synctex.gz
46
+ thesis/*.toc
47
+ thesis/chapters/*.aux
48
+
49
+ # local venv (in-repo)
50
+ lib/
51
+ lib64/
52
+ pyvenv.cfg
53
+
54
+ # Reproducibility outputs
55
+ reports/repro/
56
+ configs/
57
+ scripts/repro/
58
+ reports/repro/
59
+
60
+ # Virtual environment
61
+ bin/
62
+ lib/
63
+ lib64/
64
+ include/
65
+ pyvenv.cfg
@@ -0,0 +1,187 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ### Added
11
+
12
+ - **`--extraction-method bidirectional`** on `csttool run` — two-pass seeding with
13
+ per-side count-bounded intersection and a forward/reverse artifact diagnostic.
14
+
15
+ **Motivation:** Atlas-based motor cortex ROIs land at slightly different positions
16
+ relative to the GM/WM boundary on each side, causing the forward-seeded (motor→brainstem)
17
+ pass to produce asymmetric streamline counts. Brainstem-seeded reverse tracking is
18
+ inherently symmetric (confirmed on in-vivo data: R/L = 0.987). Bidirectional seeding
19
+ removes the cortical placement artifact while preserving genuine unilateral asymmetry
20
+ (e.g. stroke, tumour) — a bilateral-symmetry cap is intentionally NOT applied.
21
+
22
+ **Algorithm (three steps):**
23
+ 1. *Forward pass* — seed from left and right motor cortex ROIs separately; keep
24
+ streamlines that reach the brainstem.
25
+ 2. *Reverse pass* — seed from brainstem ROI; keep streamlines that reach each
26
+ motor cortex ROI, yielding `bs_to_left` and `bs_to_right` bundles.
27
+ 3. *Per-side count-bounded selection* — voxelise the reverse bundles into density
28
+ maps; cap each side independently at `min(N_forward, N_reverse)`; from each
29
+ forward bundle take the top streamlines ranked by spatial overlap score with the
30
+ corresponding reverse density map.
31
+
32
+ **Diagnostic (`artifact_index`):** Per-side forward/reverse inflation ratios are
33
+ reported. When the two ratios diverge (`artifact_index > 0.20`), residual L/R count
34
+ asymmetry is likely a cortical-interface artifact; when they agree, residual asymmetry
35
+ is likely structural (genuine biology or pathology). This lets the method correct the
36
+ artifact without masking pathology.
37
+
38
+ **Result on personal in-vivo data:** streamline count LI = +0.002 (271 L / 270 R),
39
+ vs −0.128 for passthrough. Matches the brainstem-seeded ground-truth (LI = +0.007).
40
+
41
+ **New files:**
42
+ - `src/csttool/extract/modules/bidirectional_filtering.py`
43
+ - `docs/fixes/bidirectional_seeding.md`
44
+ - `docs/explanation/design-decisions.md` — new section on bidirectional seeding
45
+
46
+ **Modified files:**
47
+ - `src/csttool/extract/__init__.py` — export `extract_cst_bidirectional`
48
+ - `src/csttool/cli/__init__.py` — `run` choices extended
49
+ - `src/csttool/cli/commands/extract.py` — guard + `run_bidirectional_extraction`
50
+ - `src/csttool/cli/commands/run.py` — routing branch added
51
+
52
+ ### Fixed
53
+
54
+ - **`csttool run` no longer consumes its `--nifti` input.** The BIDS reorganizer used
55
+ `shutil.move` unconditionally; when preprocessing was skipped (pass-through mode), the
56
+ user-supplied DWI/bval/bvec/json files were relocated into the output tree and
57
+ disappeared from their original location. Fix: detect whether each source path lives
58
+ inside the run's output directory and copy when it does not.
59
+ - **CST extraction report preserved in BIDS reports.** The reorganizer renamed every
60
+ JSON in `extraction/logs/` to `*_log-extraction.json`, causing the registration report
61
+ to overwrite the CST extraction report (last-write-wins). Fix: use per-filename tag
62
+ overrides so the registration report becomes `*_log-registration.json` and the CST
63
+ extraction stats (including the new `forward_reverse_ratio_*` and `artifact_index`
64
+ fields) survive as `*_log-extraction.json`.
65
+
66
+ ---
67
+
68
+ ## [0.5.0] - 2026-04-23
69
+
70
+ ### Added
71
+
72
+ - **BIDS-native output layout** — `csttool run` now writes a BIDS derivatives tree by
73
+ default, with no extra flags required. All outputs are moved (not copied) into the
74
+ subject directory; stage working directories are removed unconditionally afterwards.
75
+ - `sub-<id>/[ses-<id>/]dwi/` — preprocessed NIfTI, bval/bvec, scalar maps
76
+ (`space-orig_model-DTI_param-{FA,MD,RD,AD}_dwimap.nii.gz`), derivative JSON sidecars
77
+ - `sub-<id>/[ses-<id>/]dwi/tractography/` — whole-brain, CST left, CST right, and
78
+ bilateral combined tractograms
79
+ - `sub-<id>/[ses-<id>/]figures/` — QC images renamed with stage and label entities
80
+ (`stage-{preproc,tracking,extraction,metrics}_qc-{label}.png`)
81
+ - `sub-<id>/[ses-<id>/]reports/` — HTML/PDF reports, metrics JSON/CSV, pipeline logs
82
+ - `dataset_description.json`, `participants.tsv`, and `participants.json` at dataset root
83
+ - `SourceDatasets: [{"URL": "bids::"}]` when derivatives are nested under a raw BIDS root
84
+ - **`--bids-out`** flag on `csttool run` — overrides the derivatives root (default: `--out`)
85
+ - **`--session-id`** flag on `csttool run` — sets the BIDS session label
86
+ - **`--bids-out`** flag on `csttool batch` — writes `dataset_description.json` and
87
+ `participants.tsv` at the dataset root after the batch completes
88
+ - **Raw BIDS import** via `csttool import --dicom <dir> --raw-bids <out>` — produces a
89
+ fully BIDS-compliant raw dataset (`DatasetType: raw`)
90
+ - Subject label derived from SHA-256 hash of `PatientID` by default (anonymised)
91
+ - Session label derived from `StudyDate`
92
+ - `--keep-phi` flag to use `PatientID` directly (prints PHI warning)
93
+ - `--subject-id` and `--session-id` to override auto-derivation
94
+ - **`dcm2niix` promoted to primary DICOM converter** — handles Siemens, GE, Philips, and
95
+ Hitachi; generates BIDS JSON sidecars automatically. Falls back to `dicom2nifti` with a
96
+ `fallback_used` flag and a vendor-specific warning for known-unreliable vendors.
97
+ - **`pydicom`** added as a required dependency
98
+ - **`bids/output.py`** module: `write_dataset_description`, `update_participants_tsv`,
99
+ `write_participants_json`, `bids_filename`, `write_derivative_sidecar`,
100
+ `sanitize_bids_label`, `parse_dicom_age`, `hash_patient_id`
101
+ - **`manufacturer`** field added to import report JSON and series info JSON
102
+ - 25 unit tests for BIDS output helpers and QC image naming (`tests/bids/`)
103
+
104
+ ### Changed
105
+
106
+ - Output layout is BIDS derivatives by default — the flat stage-directory structure
107
+ (`tracking/`, `extraction/`, `metrics/`, `preprocessing/`) is internal working state
108
+ only, removed after finalization
109
+ - QC images explicitly routed to `figures/` with systematic names regardless of flags;
110
+ output contract is stable across all flag combinations
111
+ - Reports (HTML, PDF) and tabular outputs (metrics JSON, CSV) routed to `reports/`,
112
+ distinct from QC images in `figures/`
113
+
114
+ ## [0.4.0] - 2026-01-28
115
+
116
+ ### Added
117
+
118
+ - **Coordinate validation system** to prevent silent failures from tractogram/FA
119
+ coordinate mismatches
120
+ - Automatic validation checks bounding box overlap, detects voxel vs world space,
121
+ and verifies orientation
122
+ - New `--skip-coordinate-validation` flag to bypass validation (not recommended)
123
+ - **Hemisphere separation QC visualization** showing left/right CST bundles separately
124
+ with midline reference
125
+ - Displays cross-hemisphere contamination metrics
126
+ - Color-coded QC status (green for good separation, red for warnings)
127
+ - **`--quiet` flag** for `extract`, `run`, and `batch` commands
128
+ - Documentation updates:
129
+ - Expanded [limitations.md](docs/explanation/limitations.md)
130
+ - Updated [data-requirements.md](docs/getting-started/data-requirements.md) with
131
+ coordinate space requirements
132
+
133
+ ### Changed
134
+
135
+ - Extract command now validates tractogram coordinates against FA space before processing
136
+ - All QC visualization outputs now include hemisphere separation view by default when
137
+ using `--save-visualizations`
138
+
139
+ ## [0.3.1] - 2026-01-25
140
+
141
+ ### Changed
142
+
143
+ - Unified batch analysis metrics with the single-subject report format
144
+ - `batch_metrics.csv` now includes:
145
+ - All diffusivity scalars (MD, RD, AD) in addition to FA
146
+ - Localized metrics for pontine, PLIC, and precentral regions
147
+ - Consistent column naming conventions
148
+
149
+ ## [0.3.0] - 2026-01-22
150
+
151
+ ### Added
152
+
153
+ - Robust batch processing system (`csttool batch`)
154
+ - Manifest-based and BIDS-directory based batch execution
155
+ - Comprehensive pre-flight validation for batch inputs
156
+ - Consolidated CSV and JSON reporting for batch runs
157
+ - Parallel processing with timeout handling
158
+
159
+ ## [0.2.1] - 2026-01-20
160
+
161
+ ### Changed
162
+
163
+ - Refactored CLI into a modular package structure (`src/csttool/cli/`)
164
+ - Moved CLI entry point commands to separate modules
165
+
166
+ ### Fixed
167
+
168
+ - Updated `dipy.core.gradients.gradient_table` call to use `bvecs` keyword argument
169
+ - Enabled `copy_header=True` in `image.resample_to_img` to preserve header information
170
+
171
+ ## [0.2.0] - 2026-01-20
172
+
173
+ ### Changed
174
+
175
+ - Refined CST extraction logic:
176
+ - Added mutual exclusivity filter for motor cortices
177
+ - Added midline rejection filter (streamlines cannot cross X=0 sagittal plane)
178
+ - Major refactor of PDF report generation:
179
+ - Replaced inline generation with Jinja2 templating
180
+ - Switched to WeasyPrint for HTML-to-PDF conversion
181
+
182
+ ### Fixed
183
+
184
+ - Resolved ROI placement asymmetry caused by orientation mismatch (LAS vs RAS)
185
+ - Fixed `csttool run` failure when using NIfTI input (`--nifti`) instead of DICOM
186
+ - Re-enabled SyN non-linear registration for improved ROI symmetry
187
+ - Adjusted affine handling to respect original subject orientation
csttool-0.5.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 naloa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
csttool-0.5.0/PKG-INFO ADDED
@@ -0,0 +1,167 @@
1
+ Metadata-Version: 2.4
2
+ Name: csttool
3
+ Version: 0.5.0
4
+ Summary: Simple, modular CST assessment tool (DW-MRI).
5
+ Author: Alem Nalo
6
+ License: MIT
7
+ License-File: LICENSE
8
+ Requires-Python: >=3.10
9
+ Requires-Dist: cython
10
+ Requires-Dist: dicom2nifti
11
+ Requires-Dist: dipy
12
+ Requires-Dist: filelock
13
+ Requires-Dist: jinja2
14
+ Requires-Dist: matplotlib
15
+ Requires-Dist: nibabel
16
+ Requires-Dist: nilearn
17
+ Requires-Dist: numpy
18
+ Requires-Dist: platformdirs
19
+ Requires-Dist: pydicom
20
+ Requires-Dist: scipy
21
+ Provides-Extra: reports
22
+ Requires-Dist: weasyprint; extra == 'reports'
23
+ Provides-Extra: test
24
+ Requires-Dist: mkdocs; extra == 'test'
25
+ Requires-Dist: mkdocs-material; extra == 'test'
26
+ Requires-Dist: mkdocstrings[python]; extra == 'test'
27
+ Requires-Dist: pymdown-extensions; extra == 'test'
28
+ Requires-Dist: pytest; extra == 'test'
29
+ Requires-Dist: pytest-mock; extra == 'test'
30
+ Description-Content-Type: text/markdown
31
+
32
+ # csttool
33
+
34
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
35
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
36
+ [![Documentation](https://img.shields.io/badge/docs-available-brightgreen.svg)](https://alemnalo.github.io/csttool/)
37
+
38
+ `csttool` is a command-line tool for automated assessment of the corticospinal tract (CST) from diffusion-weighted MRI (DWI/DTI) data. It runs a full analysis pipeline — from DICOM import through tractography, CST extraction, and quantitative metrics — and produces BIDS-aligned derivative outputs.
39
+
40
+ ## What it does
41
+
42
+ The pipeline runs in six sequential steps:
43
+
44
+ | Step | Command | Description |
45
+ |------|---------|-------------|
46
+ | 1 | `check` | Verify Python environment and external dependencies |
47
+ | 2 | `import` | Convert DICOM to NIfTI, or validate an existing NIfTI dataset |
48
+ | 3 | `preprocess` | Denoise (patch2self or NLMEANS), skull-strip, optional motion correction and Gibbs unringing |
49
+ | 4 | `track` | Whole-brain deterministic tractography using a CSA ODF model |
50
+ | 5 | `extract` | Atlas-based bilateral CST extraction via MNI152 registration and Harvard-Oxford ROI masks |
51
+ | 6 | `metrics` | Per-side and bilateral metrics (FA, MD, morphology, tract profiles, asymmetry indices) with PDF/HTML reports |
52
+
53
+ Steps can be run individually or as a single `run` command. A `batch` command supports multi-subject processing via a BIDS dataset or JSON manifest.
54
+
55
+ ## Inputs
56
+
57
+ - **DICOM directory** — study root or series directory (converted with `dcm2niix`)
58
+ - **NIfTI dataset** — `.nii` / `.nii.gz` + bval + bvec files (DICOM conversion skipped)
59
+ - Optional: BIDS JSON sidecar, subject/session labels, field strength, echo time overrides
60
+
61
+ ## Outputs
62
+
63
+ All outputs are written to a BIDS-aligned derivative directory:
64
+
65
+ - Preprocessed DWI (denoised, brain-masked)
66
+ - Scalar maps: FA, MD
67
+ - Whole-brain tractogram (`.trk`)
68
+ - Left and right CST tractograms (`.trk`)
69
+ - Per-subject metrics in JSON and TSV
70
+ - HTML and PDF clinical reports
71
+ - QC visualizations (optional)
72
+
73
+ ## Installation
74
+
75
+ ### Recommended: conda (Linux, macOS, Windows)
76
+
77
+ Conda handles both the Python stack and the external `dcm2niix` binary, plus the native libraries (Cairo, Pango, GDK-PixBuf) that the PDF report backend depends on. This is the only path that gives full functionality on Windows out of the box.
78
+
79
+ ```bash
80
+ git clone https://github.com/alemnalo/csttool.git
81
+ cd csttool
82
+ conda env create -f environment.yml
83
+ conda activate csttool
84
+ csttool fetch-data --accept-fsl-license
85
+ ```
86
+
87
+ ### Advanced: pip
88
+
89
+ ```bash
90
+ pip install csttool # core pipeline + HTML reports
91
+ pip install 'csttool[reports]' # adds PDF rendering (Linux/macOS)
92
+ ```
93
+
94
+ On Windows, `pip install 'csttool[reports]'` will install `weasyprint` but its native dependencies (Cairo, Pango) are not bundled — PDF generation will fail at runtime with a missing-DLL error. Use the conda install path on Windows if you need PDF reports. HTML reports work on all platforms regardless.
95
+
96
+ You will also need to install `dcm2niix` separately:
97
+
98
+ ```bash
99
+ sudo apt install dcm2niix # Debian / Ubuntu (check version >= 1.0.20220720)
100
+ brew install dcm2niix # macOS
101
+ conda install -c conda-forge dcm2niix # any platform
102
+ ```
103
+
104
+ If `dcm2niix` is not on `PATH`, csttool falls back to `dicom2nifti`. The fallback does not produce BIDS JSON sidecars and is less reliable for non-Siemens data.
105
+
106
+ ### Atlas data (required for extraction)
107
+
108
+ ```bash
109
+ csttool fetch-data --accept-fsl-license
110
+ ```
111
+
112
+ Downloads the FMRIB58_FA template and Harvard-Oxford atlas under the FSL non-commercial license.
113
+
114
+ ### Development install
115
+
116
+ ```bash
117
+ git clone https://github.com/alemnalo/csttool.git
118
+ cd csttool
119
+ pip install -e '.[reports,test]'
120
+ ```
121
+
122
+ ## Usage
123
+
124
+ **Full pipeline from DICOM:**
125
+
126
+ ```bash
127
+ csttool run --dicom /path/to/dicom --out /path/to/output --subject-id sub-01 --save-visualizations --generate-pdf
128
+ ```
129
+
130
+ **Full pipeline from existing NIfTI:**
131
+
132
+ ```bash
133
+ csttool run --nifti sub-01_dwi.nii.gz --out /path/to/output --subject-id sub-01
134
+ ```
135
+
136
+ **Run individual steps:**
137
+
138
+ ```bash
139
+ csttool preprocess --dwi sub-01_dwi.nii.gz --out preproc/
140
+ csttool track --nifti preproc/sub-01_dwi_preproc.nii.gz --out tracking/
141
+ csttool extract --tractogram tracking/sub-01_tractogram.trk --nifti preproc/sub-01_dwi_preproc.nii.gz --out extract/
142
+ csttool metrics --cst-left extract/sub-01_cst-left.trk --cst-right extract/sub-01_cst-right.trk --out metrics/
143
+ ```
144
+
145
+ **Batch processing (BIDS dataset):**
146
+
147
+ ```bash
148
+ csttool batch --bids /path/to/bids --out /path/to/derivatives
149
+ ```
150
+
151
+ **Batch processing (manifest):**
152
+
153
+ ```bash
154
+ csttool batch --manifest subjects.json --out /path/to/derivatives
155
+ ```
156
+
157
+ **Assess DWI data quality before running:**
158
+
159
+ ```bash
160
+ csttool check-dataset --dwi sub-01_dwi.nii.gz --verbose
161
+ ```
162
+
163
+ ## Testing
164
+
165
+ ```bash
166
+ pytest tests/
167
+ ```
@@ -0,0 +1,136 @@
1
+ # csttool
2
+
3
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
5
+ [![Documentation](https://img.shields.io/badge/docs-available-brightgreen.svg)](https://alemnalo.github.io/csttool/)
6
+
7
+ `csttool` is a command-line tool for automated assessment of the corticospinal tract (CST) from diffusion-weighted MRI (DWI/DTI) data. It runs a full analysis pipeline — from DICOM import through tractography, CST extraction, and quantitative metrics — and produces BIDS-aligned derivative outputs.
8
+
9
+ ## What it does
10
+
11
+ The pipeline runs in six sequential steps:
12
+
13
+ | Step | Command | Description |
14
+ |------|---------|-------------|
15
+ | 1 | `check` | Verify Python environment and external dependencies |
16
+ | 2 | `import` | Convert DICOM to NIfTI, or validate an existing NIfTI dataset |
17
+ | 3 | `preprocess` | Denoise (patch2self or NLMEANS), skull-strip, optional motion correction and Gibbs unringing |
18
+ | 4 | `track` | Whole-brain deterministic tractography using a CSA ODF model |
19
+ | 5 | `extract` | Atlas-based bilateral CST extraction via MNI152 registration and Harvard-Oxford ROI masks |
20
+ | 6 | `metrics` | Per-side and bilateral metrics (FA, MD, morphology, tract profiles, asymmetry indices) with PDF/HTML reports |
21
+
22
+ Steps can be run individually or as a single `run` command. A `batch` command supports multi-subject processing via a BIDS dataset or JSON manifest.
23
+
24
+ ## Inputs
25
+
26
+ - **DICOM directory** — study root or series directory (converted with `dcm2niix`)
27
+ - **NIfTI dataset** — `.nii` / `.nii.gz` + bval + bvec files (DICOM conversion skipped)
28
+ - Optional: BIDS JSON sidecar, subject/session labels, field strength, echo time overrides
29
+
30
+ ## Outputs
31
+
32
+ All outputs are written to a BIDS-aligned derivative directory:
33
+
34
+ - Preprocessed DWI (denoised, brain-masked)
35
+ - Scalar maps: FA, MD
36
+ - Whole-brain tractogram (`.trk`)
37
+ - Left and right CST tractograms (`.trk`)
38
+ - Per-subject metrics in JSON and TSV
39
+ - HTML and PDF clinical reports
40
+ - QC visualizations (optional)
41
+
42
+ ## Installation
43
+
44
+ ### Recommended: conda (Linux, macOS, Windows)
45
+
46
+ Conda handles both the Python stack and the external `dcm2niix` binary, plus the native libraries (Cairo, Pango, GDK-PixBuf) that the PDF report backend depends on. This is the only path that gives full functionality on Windows out of the box.
47
+
48
+ ```bash
49
+ git clone https://github.com/alemnalo/csttool.git
50
+ cd csttool
51
+ conda env create -f environment.yml
52
+ conda activate csttool
53
+ csttool fetch-data --accept-fsl-license
54
+ ```
55
+
56
+ ### Advanced: pip
57
+
58
+ ```bash
59
+ pip install csttool # core pipeline + HTML reports
60
+ pip install 'csttool[reports]' # adds PDF rendering (Linux/macOS)
61
+ ```
62
+
63
+ On Windows, `pip install 'csttool[reports]'` will install `weasyprint` but its native dependencies (Cairo, Pango) are not bundled — PDF generation will fail at runtime with a missing-DLL error. Use the conda install path on Windows if you need PDF reports. HTML reports work on all platforms regardless.
64
+
65
+ You will also need to install `dcm2niix` separately:
66
+
67
+ ```bash
68
+ sudo apt install dcm2niix # Debian / Ubuntu (check version >= 1.0.20220720)
69
+ brew install dcm2niix # macOS
70
+ conda install -c conda-forge dcm2niix # any platform
71
+ ```
72
+
73
+ If `dcm2niix` is not on `PATH`, csttool falls back to `dicom2nifti`. The fallback does not produce BIDS JSON sidecars and is less reliable for non-Siemens data.
74
+
75
+ ### Atlas data (required for extraction)
76
+
77
+ ```bash
78
+ csttool fetch-data --accept-fsl-license
79
+ ```
80
+
81
+ Downloads the FMRIB58_FA template and Harvard-Oxford atlas under the FSL non-commercial license.
82
+
83
+ ### Development install
84
+
85
+ ```bash
86
+ git clone https://github.com/alemnalo/csttool.git
87
+ cd csttool
88
+ pip install -e '.[reports,test]'
89
+ ```
90
+
91
+ ## Usage
92
+
93
+ **Full pipeline from DICOM:**
94
+
95
+ ```bash
96
+ csttool run --dicom /path/to/dicom --out /path/to/output --subject-id sub-01 --save-visualizations --generate-pdf
97
+ ```
98
+
99
+ **Full pipeline from existing NIfTI:**
100
+
101
+ ```bash
102
+ csttool run --nifti sub-01_dwi.nii.gz --out /path/to/output --subject-id sub-01
103
+ ```
104
+
105
+ **Run individual steps:**
106
+
107
+ ```bash
108
+ csttool preprocess --dwi sub-01_dwi.nii.gz --out preproc/
109
+ csttool track --nifti preproc/sub-01_dwi_preproc.nii.gz --out tracking/
110
+ csttool extract --tractogram tracking/sub-01_tractogram.trk --nifti preproc/sub-01_dwi_preproc.nii.gz --out extract/
111
+ csttool metrics --cst-left extract/sub-01_cst-left.trk --cst-right extract/sub-01_cst-right.trk --out metrics/
112
+ ```
113
+
114
+ **Batch processing (BIDS dataset):**
115
+
116
+ ```bash
117
+ csttool batch --bids /path/to/bids --out /path/to/derivatives
118
+ ```
119
+
120
+ **Batch processing (manifest):**
121
+
122
+ ```bash
123
+ csttool batch --manifest subjects.json --out /path/to/derivatives
124
+ ```
125
+
126
+ **Assess DWI data quality before running:**
127
+
128
+ ```bash
129
+ csttool check-dataset --dwi sub-01_dwi.nii.gz --verbose
130
+ ```
131
+
132
+ ## Testing
133
+
134
+ ```bash
135
+ pytest tests/
136
+ ```