Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

run_brainageR.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/usr/bin/env bash
  2. # v 1.0
  3. DEBUG=1
  4. # sub_file=/data/project/brainage_underrepresented/data/ds004107/sub-mind010/ses-01/anat/sub-mind010_ses-01_T1w.nii.gz
  5. sub_path=$1
  6. # check that this is a file
  7. if [ -e "$sub_path" ] || [ -L "$sub_path" ]; then
  8. echo "Input file exists or is a symbolic link."
  9. else
  10. echo "Input file does not exist, exiting."
  11. exit 1
  12. fi
  13. # dir_sub
  14. dir_path=$(dirname "${sub_path}")
  15. # sub_file=sub-mind010_ses-01_T1w.nii.gz (or .nii, or .mgz)
  16. sub_file=$(basename "${sub_path}")
  17. # sub_name=sub-mind010_ses-01_T1w
  18. sub_name="${sub_file%%.*}"
  19. # out_dir=derivatives/brainageR/sub-01490270a/ses-BLT11
  20. out_dir=$2
  21. # Container path
  22. container_path=$3
  23. # Save or no the intermidiate files
  24. save=$4
  25. # Raw file ?
  26. raw=$5
  27. if [ $DEBUG -eq 1 ]; then
  28. echo "sub_file = $sub_path"
  29. echo "dir_path = $dir_path"
  30. echo "sub_file = $sub_file"
  31. echo "sub_name = $sub_name"
  32. echo "out_dir = $out_dir"
  33. echo "save = $save"
  34. echo "raw = $raw"
  35. fi
  36. # create result folder and move the results in there
  37. if [ -e "$out_dir/${sub_name}_brainageR.csv" ]; then
  38. echo "output file exists, exiting"
  39. exit
  40. else
  41. mkdir -p $out_dir
  42. fi
  43. cd "${dir_path}"
  44. datalad get "${sub_file}"
  45. # define working dir, create a 'data' folder in it and copy the subject in.
  46. work_dir=$(mktemp -d)
  47. mkdir ${work_dir}/data
  48. cp "${sub_path}" "${work_dir}/data"
  49. datalad drop "${sub_path}"
  50. cd ${work_dir}
  51. # unzip as SPM/CAT work with .nii files. Remove the nii.gz file and rename sub
  52. # gunzip only if gz file and then delete .gz file
  53. if [[ "$sub_file" == *.gz ]]; then
  54. echo "The file is a .gz file."
  55. gunzip data/${sub_file}
  56. rm -f data/${sub_file}
  57. sub_file=${sub_file%".gz"}
  58. else
  59. echo "The file is not a .gz file."
  60. fi
  61. # make sure permissions are ok
  62. chmod +rwx ${work_dir}/data/$sub_file
  63. # run singularity with brainageR code
  64. # ----------------------------------------------------------
  65. echo "Running the container"
  66. #singularity exec /data/project/BrainAge4AD/tools/brainageR_dockerfile/brainageR2.1.sif brainageR -f ${work_dir}/data/${sub_file} -o ${sub_name}_brain_predicted.age.csv
  67. singularity exec ${container_path} brainageR -f ${work_dir}/data/${sub_file} -o ${sub_name}_brain_predicted.age.csv
  68. # Check the exit status of the previous command
  69. if [ $? -ne 0 ]; then
  70. echo "Singularity container failed, exiting." >&2
  71. exit 1
  72. fi
  73. # ----------------------------------------------------------
  74. # Moving the prediction into the output dir
  75. mv $work_dir/${sub_name}_brain_predicted.age.csv $out_dir/${sub_name}_brainageR.csv
  76. echo "Prediction file sub${sub_name} saved in $out_dir"
  77. # If user wants to save intermidiate files, moving everything into output dir
  78. if [ $save == "yes" ]; then
  79. mkdir -p $out_dir/${sub_name}_brainageR
  80. mv -r $work_dir/* $out_dir/${sub_name}_brainageR/
  81. echo "All files of ${sub_name} saved in $out_dir/${sub_name}_brainageR"
  82. fi
  83. echo "Cleaning tmp files"
  84. rm -rf $work_dir
  85. exit