From ef71c3c7dd90943092d9d0140e6e43eb89295e23 Mon Sep 17 00:00:00 2001 From: valosekj <jan.valosek@upol.cz> Date: Tue, 19 Nov 2024 13:36:35 -0500 Subject: [PATCH 1/6] use `os.path.abspath` to save asb paths to log for easier debug --- file_loader.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/file_loader.py b/file_loader.py index 0e02f9e..ba41160 100644 --- a/file_loader.py +++ b/file_loader.py @@ -347,8 +347,8 @@ def main(): """ args = get_parser() - dicom_folder = os.path.expanduser(args.dicom_folder) - bids_folder = os.path.expanduser(args.bids_folder) + dicom_folder = os.path.abspath(os.path.expanduser(args.dicom_folder)) + bids_folder = os.path.abspath(os.path.expanduser(args.bids_folder)) participant_id = args.participant session_id = args.session contrasts = args.contrasts From 432fa9b9573cb8e496666e168b40e109412728aa Mon Sep 17 00:00:00 2001 From: valosekj <jan.valosek@upol.cz> Date: Tue, 19 Nov 2024 13:36:53 -0500 Subject: [PATCH 2/6] Make the process_data.sh script executable by `chmod` --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 88ab1f7..a8d15fc 100644 --- a/README.md +++ b/README.md @@ -167,6 +167,9 @@ unzip balgrist-sci.zip rm balgrist-sci.zip # Rename the unzipped directory to balgrist-sci mv balgrist-sci-r20240918 balgrist-sci +# Make the process_data.sh script executable +cd balgrist-sci +chmod u+x process_data.sh ``` 3. Check that the repository was downloaded correctly: From f953be359ddcc2d9ccbdbaea2f4d591a0b7aae5a Mon Sep 17 00:00:00 2001 From: valosekj <jan.valosek@upol.cz> Date: Tue, 19 Nov 2024 13:37:35 -0500 Subject: [PATCH 3/6] Add `SCRIPT_NAME` var --- process_data.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/process_data.sh b/process_data.sh index 067015b..f74bb42 100755 --- a/process_data.sh +++ b/process_data.sh @@ -26,6 +26,7 @@ # AI assistance: Claude 3.5 Sonnet, ChatGPT-4o, and GitHub Copilot # +SCRIPT_NAME=$(basename "${0}") # Immediately exit if error set -e -o pipefail @@ -42,7 +43,7 @@ DESCRIPTION Requires that SCT, dcm2niix, and FSLeyes to be installed. USAGE - `basename ${0}` -d <dicom folder> -b <bids folder> -r <results folder> -p <participant id> -s <session id> -c <contrasts> [-age <age> -sex <sex>] + ${SCRIPT_NAME} -d <dicom folder> -b <bids folder> -r <results folder> -p <participant id> -s <session id> -c <contrasts> [-age <age> -sex <sex>] MANDATORY ARGUMENTS -d <dicom folder> Path to the folder containing DICOM images. Example: ~/sci-balgrist-study/sourcedata/dir_20230711 @@ -63,6 +64,9 @@ main() { # Get the directory of the current script get_repo_dir + + echo_with_linebreaks "Starting the main analysis using the script: ${REPO_DIR}/${SCRIPT_NAME}" + # Activate the SCT conda environment with dcm2niix installed activate_env @@ -71,7 +75,7 @@ main() main_analysis conda deactivate - echo "Done." + echo_with_linebreaks "${REPO_DIR}/${SCRIPT_NAME} finished successfully." } # Get the directory of the current script @@ -234,7 +238,7 @@ main_analysis() # Print usage if no arguments are provided if [ ! ${#@} -gt 0 ]; then - usage `basename ${0}` + usage ${SCRIPT_NAME} exit 1 fi @@ -303,7 +307,7 @@ variables=(dicom_folder bids_folder results_folder participant_id session_id con for var in "${variables[@]}"; do if [[ -z ${!var} ]]; then echo "Error: Missing argument: -${var:0:1} <$var>." - echo "To print the usage, run: `basename ${0}` -h" + echo "To print the usage, run: ${SCRIPT_NAME} -h" exit 1 fi done From b7f8694ddf5a401705c139b18e4423193cc3ff1e Mon Sep 17 00:00:00 2001 From: valosekj <jan.valosek@upol.cz> Date: Tue, 19 Nov 2024 13:37:51 -0500 Subject: [PATCH 4/6] Extend FSLeyes instructions --- process_data.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/process_data.sh b/process_data.sh index f74bb42..23c324a 100755 --- a/process_data.sh +++ b/process_data.sh @@ -125,7 +125,7 @@ echo_with_linebreaks() echo_fsleyes_instructions() { - echo_with_linebreaks "Opening FSLeyes (close FSLeyes to continue)...\nCheck the quality of the segmentation, correct the segmentation if necessary, and save it by overwriting the existing file. Then close FSLeyes to continue." + echo_with_linebreaks "Opening FSLeyes (close FSLeyes to continue)...\nCheck the quality of the segmentation, correct the segmentation if necessary ('Tools' --> 'Edit mode'),\nand save it by overwriting the existing file ('Overlay' --> 'Save' --> 'Overwrite').\nThen close FSLeyes to continue." } # Convert DICOM files to NIfTI format using the file_loader.py script, which calls the dcm2niix function From c7490e3e8a5347349fe4be9f7741fe4cb09664e0 Mon Sep 17 00:00:00 2001 From: valosekj <jan.valosek@upol.cz> Date: Tue, 19 Nov 2024 13:38:23 -0500 Subject: [PATCH 5/6] Replace `rsync` by `cp` --- process_data.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/process_data.sh b/process_data.sh index 23c324a..86dc4c0 100755 --- a/process_data.sh +++ b/process_data.sh @@ -154,8 +154,7 @@ create_results_folder_and_copy_images() # Go to folder where data will be copied and processed cd "$results_folder" # Copy source images - # Note: we use '/./' in order to include the sub-folder 'ses-0X' - rsync -Ravzh "$bids_folder"/./"$participant_id"/"$session_id" . + cp -r "$bids_folder"/"$participant_id"/"$session_id" . } # Inspiration: https://github.com/spinalcordtoolbox/sct_tutorial_data/blob/master/multi_subject/process_data.sh#L66-L89 @@ -175,7 +174,7 @@ segment_if_does_not_exist() { echo "Looking for manual segmentation: ${FILESEGMANUAL}" if [[ -e "${FILESEGMANUAL}" ]]; then echo "Found! Using manual segmentation." - rsync -avzh "${FILESEGMANUAL}" "${FILESEG}".nii.gz + cp "${FILESEGMANUAL}" "${FILESEG}".nii.gz sct_qc -i "${file}".nii.gz -s "${FILESEG}".nii.gz -p sct_deepseg_sc -qc "${PATH_QC}" -qc-subject "${SUBJECT}" else echo "Not found. Proceeding with automatic segmentation." @@ -202,7 +201,7 @@ process_t2w() echo_fsleyes_instructions fsleyes "$file_t2".nii.gz "${file_t2_seg}.nii.gz" -cm red -a 70.0 # Copy the visually verified segmentation (and potentially manually corrected SC seg) to the derivatives folder - rsync -avzh "${file_t2_seg}".nii.gz "${bids_folder}"/derivatives/labels/"${SUBJECT}"/anat/ + cp "${file_t2_seg}".nii.gz "${bids_folder}"/derivatives/labels/"${SUBJECT}"/anat/ # TODO: continue with the analysis } From bcce2c319d359395efa3a013147e9a6215949f95 Mon Sep 17 00:00:00 2001 From: valosekj <jan.valosek@upol.cz> Date: Tue, 19 Nov 2024 13:38:29 -0500 Subject: [PATCH 6/6] Add echo --- process_data.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/process_data.sh b/process_data.sh index 86dc4c0..b1f7ddc 100755 --- a/process_data.sh +++ b/process_data.sh @@ -203,6 +203,7 @@ process_t2w() # Copy the visually verified segmentation (and potentially manually corrected SC seg) to the derivatives folder cp "${file_t2_seg}".nii.gz "${bids_folder}"/derivatives/labels/"${SUBJECT}"/anat/ # TODO: continue with the analysis + echo -e "Spinal cord segmentation saved as:\n${bids_folder}/derivatives/labels/${SUBJECT}/anat/${file_t2_seg}.nii.gz" } main_analysis()