Skip to content

Commit

Permalink
Merge pull request #7 from sct-pipeline/jv/try_cp_instead_of_rsync
Browse files Browse the repository at this point in the history
Try `cp` instead of `rsync`
valosekj authored Nov 19, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents 499a53a + bcce2c3 commit 6f50c7e
Showing 3 changed files with 18 additions and 11 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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:
4 changes: 2 additions & 2 deletions file_loader.py
Original file line number Diff line number Diff line change
@@ -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
22 changes: 13 additions & 9 deletions process_data.sh
Original file line number Diff line number Diff line change
@@ -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
@@ -121,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
@@ -150,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
@@ -171,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."
@@ -198,8 +201,9 @@ 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
echo -e "Spinal cord segmentation saved as:\n${bids_folder}/derivatives/labels/${SUBJECT}/anat/${file_t2_seg}.nii.gz"
}

main_analysis()
@@ -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

0 comments on commit 6f50c7e

Please sign in to comment.