|
| 1 | +### PAM50 Levels |
| 2 | + |
| 3 | +These level files are a slightly modified copy of the [level files](https://github.com/PhillipsLab/pam50/tree/main/Spinal%20Cord%20Levels%20NIfTI) produced by the [Phillips Lab](https://github.com/PhillipsLab): |
| 4 | + |
| 5 | +Modifications include: |
| 6 | + |
| 7 | +- Change data type from float64 to float32 |
| 8 | +- Copy header from current PAM50/spinal_levels |
| 9 | +- Rename files |
| 10 | + |
| 11 | +To reproduce the modified files, please run `git checkout e854bbad9ab550fd93acabeaf43c97cf66b3a4e5`, then run the following script in your terminal: |
| 12 | + |
| 13 | +```bash |
| 14 | +#!/bin/bash |
| 15 | +# |
| 16 | +# Process Phillips Lab PAM50 spinal levels to match existing PAM50 conventions. |
| 17 | +# |
| 18 | +# Usage: |
| 19 | +# ./process_spinal_levels.sh |
| 20 | +# 1. Clone https://github.com/spinalcordtoolbox/PAM50 |
| 21 | +# 2. Checkout commit e854bbad9ab550fd93acabeaf43c97cf66b3a4e5 |
| 22 | +# 3. Run inside /PAM50/spinal_levels_PhillipsLab/ |
| 23 | +# Authors: Sandrine Bédard, Joshua Newton |
| 24 | + |
| 25 | +set -x |
| 26 | +# Immediately exit if error |
| 27 | +set -e -o pipefail |
| 28 | + |
| 29 | +# Exit if user presses CTRL+C (Linux) or CMD+C (OSX) |
| 30 | +trap "echo Caught Keyboard Interrupt within script. Exiting now.; exit" INT |
| 31 | + |
| 32 | +start=`date +%s` |
| 33 | + |
| 34 | +# Add missing info to the `info_label.txt` file to account for newly-added levels |
| 35 | +file_info_label=$(realpath "../spinal_levels/info_label.txt") |
| 36 | +extra_spinal_levels="20, Spinal level L1, spinal_level_21.nii.gz |
| 37 | +21, Spinal level L2, spinal_level_22.nii.gz |
| 38 | +22, Spinal level L3, spinal_level_23.nii.gz |
| 39 | +23, Spinal level L4, spinal_level_24.nii.gz |
| 40 | +24, Spinal level L5, spinal_level_25.nii.gz" |
| 41 | +if [[ $(tail -c 23 "$file_info_label") == "spinal_level_20.nii.gz" ]] |
| 42 | +then |
| 43 | + echo "$extra_spinal_levels" >> "$file_info_label" |
| 44 | +fi |
| 45 | + |
| 46 | +# Retrieve input params |
| 47 | +PATH_IN=$PWD |
| 48 | +PATH_OUT="$PATH_IN/spinal_levels_processed" |
| 49 | +for FILE in *.nii.gz; do |
| 50 | + file=${FILE/%".nii.gz"} |
| 51 | + echo $file |
| 52 | + mkdir -p $PATH_OUT/${file}_processed |
| 53 | + rsync -avzh $FILE $PATH_OUT/${file}_processed |
| 54 | + cd $PATH_OUT/${file}_processed |
| 55 | + # Change file type |
| 56 | + sct_image -i ${file}.nii.gz -type float32 -o ${file}_float32.nii.gz |
| 57 | + file="${file}_float32" |
| 58 | + # Copy header of SCT PAM50 template |
| 59 | + sct_image -i $SCT_DIR/data/PAM50/spinal_levels/spinal_level_02.nii.gz -copy-header $file.nii.gz -o ${file}_header.nii.gz |
| 60 | + file="${file}_header" |
| 61 | + # Rename the file to the filename corresponding to the level (specified by `info_label.txt`) |
| 62 | + level=$(echo "$file" | cut -d '_' -f 3) |
| 63 | + file_out=$(grep -F "$level," $file_info_label | cut -d "," -f 3) |
| 64 | + cp $file.nii.gz $file_out |
| 65 | + cd "$PATH_IN" |
| 66 | + echo $PATH_IN |
| 67 | +done |
| 68 | + |
| 69 | +# Display useful info for the log |
| 70 | +end=`date +%s` |
| 71 | +runtime=$((end-start)) |
| 72 | +echo |
| 73 | +echo "~~~" |
| 74 | +echo "SCT version: `sct_version`" |
| 75 | +echo "Ran on: `uname -nsr`" |
| 76 | +echo "Duration: $(($runtime / 3600))hrs $((($runtime / 60) % 60))min $(($runtime % 60))sec" |
| 77 | +echo "~~~" |
| 78 | +``` |
0 commit comments