Skip to content

Commit 865ae41

Browse files
batch_single_subject.sh: Replace old commands with tweaked new ones
The previous commit added commands to `batch_single_subject.sh` to reproduce the existing `batch_processing.sh` metrics EXACTLY. But, to do so, many outdated commands and methods were needed. This commit removes the outdated methods, and tries to reproduce the relevant metric files using only the commands that were already present within `batch_single_subject.sh`. Doing this will fundamentally change the values we produced (due to different underlying methods), but it allows us to keep the pipeline we've already developed for the SCT Course over the years. Only minimal changes to the existing commands were necessary, and the changes should be painless to port over to the SCT Course. This provides a smooth transition from having 2 scripts (batch_processing.sh and batch_single_subject.sh) to just 1 script (batch_single_subject.sh), allowing us to get rid of the old script entirely. For documentation on what exactly changed here from old -> new, refer to the extensive comments in the previous commit.
1 parent db7730a commit 865ae41

1 file changed

Lines changed: 12 additions & 110 deletions

File tree

single_subject/batch_single_subject.sh

Lines changed: 12 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -84,24 +84,9 @@ sct_label_vertebrae -i t2.nii.gz -s t2_seg.nii.gz -c t2 -discfile t2_totalspines
8484
# ======================================================================================================================
8585

8686
# Compute cross-sectional area (CSA) of spinal cord and average it across levels C3 and C4
87-
sct_process_segmentation -i t2_seg.nii.gz -vert 3:4 -discfile t2_totalspineseg_discs.nii.gz -o csa_c3c4.csv
88-
89-
#######################################################################################################################
90-
# FIXME: Metric 1/8: [t2/csa_c2c3.csv-0-MEAN(area)]
91-
# Notes:
92-
# - We have a corresponding command that computes `csa_c3c4.csv` (see above).
93-
# - The above `batch_single_subject.sh` command uses the disc labels directly.
94-
# - By comparison, the old `batch_processing.sh` commands rely on the the warped template (registered using the vert labels)
95-
# - In summary, the old metric values we are testing are wholly incompatible with our current up-to-date pipelines.
96-
sct_label_vertebrae -i t2.nii.gz -s t2_seg.nii.gz -c t2
97-
sct_label_utils -i t2_seg_labeled.nii.gz -vert-body 2,5 -o labels_vert.nii.gz
98-
sct_register_to_template -i t2.nii.gz -s t2_seg.nii.gz -l labels_vert.nii.gz -c t2
99-
sct_warp_template -d t2.nii.gz -w warp_template2anat.nii.gz -a 0
100-
sct_process_segmentation -i t2_seg.nii.gz -vert 2:3 -o csa_c2c3.csv
101-
#######################################################################################################################
102-
87+
sct_process_segmentation -i t2_seg.nii.gz -vert 2:3 -discfile t2_totalspineseg_discs.nii.gz -o csa_c2c3.csv
10388
# Aggregate CSA value per level
104-
sct_process_segmentation -i t2_seg.nii.gz -vert 3:4 -discfile t2_totalspineseg_discs.nii.gz -perlevel 1 -o csa_perlevel.csv
89+
sct_process_segmentation -i t2_seg.nii.gz -vert 2:3 -discfile t2_totalspineseg_discs.nii.gz -perlevel 1 -o csa_perlevel.csv
10590
# Aggregate CSA value per slices
10691
sct_process_segmentation -i t2_seg.nii.gz -z 30:35 -discfile t2_totalspineseg_discs.nii.gz -perslice 1 -o csa_perslice.csv
10792

@@ -111,30 +96,12 @@ sct_process_segmentation -i t2_seg.nii.gz -z 30:35 -discfile t2_totalspineseg_di
11196
# of the spinal cord will vary depending on the position of the neck.
11297
sct_detect_pmj -i t2.nii.gz -c t2 -qc ~/qc_singleSubj
11398
# Check the QC to make sure PMJ was properly detected, then compute CSA using the distance from the PMJ:
114-
sct_process_segmentation -i t2_seg.nii.gz -pmj t2_pmj.nii.gz -pmj-distance 64 -pmj-extent 30 -o csa_pmj.csv -qc ~/qc_singleSubj -qc-image t2.nii.gz
115-
116-
#######################################################################################################################
117-
# FIXME: Metric 2/8: [t2/csa_pmj.csv-0-MEAN(area)]
118-
# Notes:
119-
# - We have a corresponding command that computes `csa_pmj.csv` (see above).
120-
# - There is only a small discrepancy in `-pmj-distance`, and this is easily fixable.
121-
sct_process_segmentation -i t2_seg.nii.gz -pmj t2_pmj.nii.gz -pmj-distance 60 -pmj-extent 30 -o csa_pmj.csv
122-
#######################################################################################################################
99+
sct_process_segmentation -i t2_seg.nii.gz -pmj t2_pmj.nii.gz -pmj-distance 60 -pmj-extent 30 -o csa_pmj.csv -qc ~/qc_singleSubj -qc-image t2.nii.gz
123100

124101
# The above commands will output the metrics in the subject space (with the original image's slice numbers)
125102
# However, you can get the corresponding slice number in the PAM50 space by using the flag `-normalize-PAM50 1`
126-
sct_process_segmentation -i t2_seg.nii.gz -discfile t2_totalspineseg_discs.nii.gz -perslice 1 -normalize-PAM50 1 -o csa_PAM50.csv
103+
sct_process_segmentation -i t2_seg.nii.gz -discfile t2_totalspineseg_discs.nii.gz -perslice 1 -normalize-PAM50 1 -o csa_pam50.csv
127104

128-
#######################################################################################################################
129-
# FIXME: Metric 3/8: [t2/csa_pam50.csv-38-MEAN(area)]
130-
# Notes:
131-
# - We have a corresponding command that computes `csa_pam50.csv` (see above).
132-
# - The above `batch_single_subject.sh` command uses the disc labels directly.
133-
# - By comparison, the old `batch_processing.sh` commands relies on the `sct_label_vertebrae` seg for `-vertfile`.
134-
# - In summary, the old metric values we are testing are wholly incompatible with our current up-to-date pipelines.
135-
sct_label_vertebrae -i t2.nii.gz -s t2_seg.nii.gz -c t2
136-
sct_process_segmentation -i t2_seg.nii.gz -vertfile t2_seg_labeled.nii.gz -perslice 1 -normalize-PAM50 1 -o csa_pam50.csv
137-
#######################################################################################################################
138105

139106

140107
# Quantifying spinal cord compression using maximum spinal cord compression (MSCC) and normalizing with database of healthy controls
@@ -157,78 +124,6 @@ sct_compute_compression -i t2_compressed_seg.nii.gz -vertfile t2_compressed_seg_
157124
# Compute ratio of AP diameter, normalized with healthy controls using `-normalize-hc 1`.
158125
sct_compute_compression -i t2_compressed_seg.nii.gz -vertfile t2_compressed_seg_labeled.nii.gz -l t2_compressed_labels-compression.nii.gz -metric diameter_AP -normalize-hc 1 -o ap_ratio_norm_PAM50.csv
159126

160-
# NB: All 5 of the metrics below use the T2 registration to template as an `-initwarp` step. This means that to reproduce
161-
# the old batch_processing.sh values, we need to use the old T2 warping fields, too. (See: "Metric 1/8" for the steps)
162-
# It's totally possible to move these commands to _after_ the revamped T2 registration step, but the values will be off:
163-
# - https://github.com/spinalcordtoolbox/sct_tutorial_data/commit/84139952c531ada90a901d9612ff7a8070bcc02f
164-
# - https://github.com/spinalcordtoolbox/spinalcordtoolbox/actions/runs/22780277293/job/67453420618?pr=5185
165-
166-
#######################################################################################################################
167-
# FIXME: Metric 4/8: [t2s/csa_gm.csv-3-MEAN(area)]
168-
# FIXME: Metric 5/8: [t2s/csa_wm.csv-3-MEAN(area)]
169-
# Notes:
170-
# - We have corresponding commands that compute the GM/WM (see GM sections later on).
171-
# - For `batch_single_subject.sh`, we use the new `graymatter` method, and register using the WM seg with updated params.
172-
# - For `batch_processing.sh`, we use the old `sct_deepseg_gm` method, and register using the GM seg with outdated params.
173-
cd ../t2s
174-
sct_deepseg spinalcord -i t2s.nii.gz -qc ~/qc_singleSubj
175-
sct_deepseg_gm -i t2s.nii.gz
176-
sct_maths -i t2s_seg.nii.gz -sub t2s_gmseg.nii.gz -o t2s_wmseg.nii.gz
177-
# - We also have corresponding commands that compute the `csa_wm.csv`/`csa_gm.csv` (see above).
178-
# - For `batch_single_subject.sh`, we compute `-perslice 1` directly on the segmentation file.
179-
# - For `batch_processing.sh`, we compute `-perlevel 1` using the warped template.
180-
# - In summary, the old metric values we are testing are wholly incompatible with our current up-to-date pipelines.
181-
sct_register_multimodal -i "$SCT_DIR/data/PAM50/template/PAM50_t2s.nii.gz" -iseg "$SCT_DIR/data/PAM50/template/PAM50_cord.nii.gz" -d t2s.nii.gz -dseg t2s_seg.nii.gz -param step=1,type=seg,algo=centermass:step=2,type=seg,algo=bsplinesyn,slicewise=1,iter=3:step=3,type=im,algo=syn,slicewise=1,iter=1,metric=CC -initwarp ../t2/warp_template2anat.nii.gz -initwarpinv ../t2/warp_anat2template.nii.gz -owarp warp_template2t2s.nii.gz -owarpinv warp_t2s2template.nii.gz
182-
sct_warp_template -d t2s.nii.gz -w warp_template2t2s.nii.gz
183-
sct_process_segmentation -i t2s_gmseg.nii.gz -vert 2:5 -perlevel 1 -o csa_gm.csv -centerline t2s_seg.nii.gz
184-
sct_process_segmentation -i t2s_wmseg.nii.gz -vert 2:5 -perlevel 1 -o csa_wm.csv -centerline t2s_seg.nii.gz
185-
#######################################################################################################################
186-
187-
#######################################################################################################################
188-
# FIXME: Metric 6/8: [mt/mtr_in_wm.csv-0-MAP()]
189-
# Notes:
190-
# - We have corresponding commands to compute the MTR (see MT sections later on).
191-
# - For `batch_single_subject.sh`, the mask is used directly for the `-m` argument of `sct_register_multimodal`.
192-
# - For `batch_processing.sh`, however, the mask is used to crop the image prior to registration.
193-
cd ../mt
194-
sct_get_centerline -i mt1.nii.gz -c t2
195-
sct_create_mask -i mt1.nii.gz -p centerline,mt1_centerline.nii.gz -size 45mm
196-
sct_crop_image -i mt1.nii.gz -m mask_mt1.nii.gz -o mt1_crop.nii.gz
197-
sct_deepseg spinalcord -i mt1_crop.nii.gz
198-
sct_register_multimodal -i mt0.nii.gz -d mt1_crop.nii.gz -dseg mt1_crop_seg.nii.gz -param step=1,type=im,algo=slicereg,metric=CC -x spline
199-
sct_compute_mtr -mt0 mt0_reg.nii.gz -mt1 mt1_crop.nii.gz
200-
# - We also have corresponding commands that compute the `mtr_in_wm.csv` file
201-
# - For `batch_single_subject.sh`, we A) use the mask during registration to template, B) we use the t2s for initwarp, and C) we don't aggregate the levels at all.
202-
# - For `batch_processing.sh`, however, A) use the cropped image during template registration, B) we use the t2 for initwarp, and C) we aggregate the MTR values across levels 2 to 5.
203-
# - In summary, the old metric values we are testing are wholly incompatible with our current up-to-date pipelines.
204-
sct_register_multimodal -i "$SCT_DIR/data/PAM50/template/PAM50_t2.nii.gz" -iseg "$SCT_DIR/data/PAM50/template/PAM50_cord.nii.gz" -d mt1_crop.nii.gz -dseg mt1_crop_seg.nii.gz -param step=1,type=seg,algo=slicereg,smooth=3:step=2,type=seg,algo=bsplinesyn,slicewise=1,iter=3 -initwarp ../t2/warp_template2anat.nii.gz -initwarpinv ../t2/warp_anat2template.nii.gz -owarp warp_template2mt.nii.gz -owarpinv warp_mt2template.nii.gz
205-
sct_warp_template -d mt1_crop.nii.gz -w warp_template2mt.nii.gz
206-
sct_extract_metric -i mtr.nii.gz -method map -o mtr_in_wm.csv -l 51 -vert 2:5
207-
#######################################################################################################################
208-
209-
#######################################################################################################################
210-
# FIXME: Metric 7/8: [dmri/fa_in_cst.csv-0-WA()]
211-
# FIXME: Metric 8/8: [dmri/fa_in_cst.csv-1-WA()]
212-
# - We have corresponding commands to compute the mask for motion correction (see dMRI sections later on).
213-
# - For `batch_single_subject.sh`, we currently segment the dMRI cord directly, then dilate it.
214-
# - For `batch_processing.sh`, we warp the T2 seg, then create the mask from that.
215-
cd ../dmri
216-
sct_dmri_separate_b0_and_dwi -i dmri.nii.gz -bvec bvecs.txt
217-
sct_register_multimodal -i ../t2/t2_seg.nii.gz -d dmri_dwi_mean.nii.gz -identity 1 -x nn
218-
sct_create_mask -i dmri_dwi_mean.nii.gz -p centerline,t2_seg_reg.nii.gz -size 35mm
219-
# - We also have corresponding commands to warp the template to the motion-corrected sequence (see dMRI sections later on).
220-
# - The process is basically the same (apart from the differing masks)
221-
sct_dmri_moco -i dmri.nii.gz -bvec bvecs.txt -m mask_dmri_dwi_mean.nii.gz
222-
sct_deepseg spinalcord -i dmri_moco_dwi_mean.nii.gz
223-
sct_qc -i dmri.nii.gz -d dmri_moco.nii.gz -s dmri_moco_dwi_mean_seg.nii.gz -p sct_dmri_moco
224-
sct_register_multimodal -i "$SCT_DIR/data/PAM50/template/PAM50_t1.nii.gz" -iseg "$SCT_DIR/data/PAM50/template/PAM50_cord.nii.gz" -d dmri_moco_dwi_mean.nii.gz -dseg dmri_moco_dwi_mean_seg.nii.gz -param step=1,type=seg,algo=centermass:step=2,type=seg,algo=bsplinesyn,metric=MeanSquares,smooth=1,iter=3 -initwarp ../t2/warp_template2anat.nii.gz -initwarpinv ../t2/warp_anat2template.nii.gz -owarp warp_template2dmri.nii.gz -owarpinv warp_dmri2template.nii.gz
225-
sct_warp_template -d dmri_moco_dwi_mean.nii.gz -w warp_template2dmri.nii.gz
226-
# - Lastly, we also have a corresponding command to extract DTI metrics (see dMRI sections later on).
227-
# - For `batch_single_subject.sh`, we compute FA in the WM aggregated across levels.
228-
# - For `batch_processing.sh`, we compute FA in the CST, aggregated across slices.
229-
sct_dmri_compute_dti -i dmri_moco.nii.gz -bval bvals.txt -bvec bvecs.txt
230-
sct_extract_metric -i dti_FA.nii.gz -z 2:14 -method wa -l 4,5 -o fa_in_cst.csv
231-
#######################################################################################################################
232127

233128

234129
# Registration to template
@@ -387,6 +282,9 @@ sct_extract_metric -i t2s.nii.gz -f t2s_gmseg.nii.gz -method bin -z 2:12 -o t2s_
387282
sct_register_multimodal -i "${SCT_DIR}"/data/PAM50/template/PAM50_t2s.nii.gz -iseg "${SCT_DIR}"/data/PAM50/template/PAM50_wm.nii.gz -d t2s.nii.gz -dseg t2s_wmseg.nii.gz -initwarp ../t2/warp_template2anat.nii.gz -initwarpinv ../t2/warp_anat2template.nii.gz -owarp warp_template2t2s.nii.gz -owarpinv warp_t2s2template.nii.gz -param step=1,type=seg,algo=rigid:step=2,type=seg,metric=CC,algo=bsplinesyn,slicewise=1,iter=3:step=3,type=im,metric=CC,algo=syn,slicewise=1,iter=2 -qc ~/qc_singleSubj
388283
# Warp template
389284
sct_warp_template -d t2s.nii.gz -w warp_template2t2s.nii.gz -qc ~/qc_singleSubj
285+
# Compute vertebral level-based metrics using warped template (needed for the template's vertlevel file)
286+
sct_process_segmentation -i t2s_gmseg.nii.gz -vert 2:5 -perlevel 1 -o csa_gm.csv -centerline t2s_seg.nii.gz
287+
sct_process_segmentation -i t2s_wmseg.nii.gz -vert 2:5 -perlevel 1 -o csa_wm.csv -centerline t2s_seg.nii.gz
390288

391289
# Register another metric while reusing newly-created GM-informed warping fields
392290
cd ../mt
@@ -404,7 +302,7 @@ fsleyes mt1.nii.gz -cm greyscale -a 100.0 label/template/PAM50_t2.nii.gz -cm gre
404302

405303
# Extract MTR for each slice within the white matter (combined label: #51)
406304
# Tips: To list all available labels, type: "sct_extract_metric"
407-
sct_extract_metric -i mtr.nii.gz -f label/atlas -method map -l 51 -o mtr_in_wm_perslice.csv
305+
sct_extract_metric -i mtr.nii.gz -f label/atlas -method map -l 51 -vert 2:5 -o mtr_in_wm.csv
408306

409307
# Extract MTR within the right and left corticospinal tract and aggregate across specific slices
410308
sct_extract_metric -i mtr.nii.gz -f label/atlas -method map -l 4,5 -z 5:15 -o mtr_in_cst.csv
@@ -413,6 +311,7 @@ sct_extract_metric -i mtr.nii.gz -f label/atlas -method map -l 4,5 -z 5:15 -o mt
413311
sct_extract_metric -i mtr.nii.gz -f label/atlas -method map -l 53 -vert 2:4 -vertfile label/template/PAM50_levels.nii.gz -o mtr_in_dc.csv
414312

415313

314+
416315
# Diffusion-weighted MRI
417316
# ======================================================================================================================
418317

@@ -449,6 +348,9 @@ sct_dmri_compute_dti -i dmri_moco.nii.gz -bval bvals.txt -bvec bvecs.txt
449348

450349
# Compute FA within the white matter from individual level 2 to 5
451350
sct_extract_metric -i dti_FA.nii.gz -f label/atlas -l 51 -method map -vert 2:5 -vertfile label/template/PAM50_levels.nii.gz -perlevel 1 -o fa_in_wm.csv
351+
# Compute FA within the CST, aggregated across z slices, using the weighted average method
352+
sct_extract_metric -i dti_FA.nii.gz -f label/atlas -l 4,5 -method wa -z 2:14 -o fa_in_cst.csv
353+
452354

453355

454356
# Functional MRI

0 commit comments

Comments
 (0)