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.

highspeed-heudiconv-cluster.sh 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #!/usr/bin/bash
  2. # ==============================================================================
  3. # SCRIPT INFORMATION:
  4. # ==============================================================================
  5. # SCRIPT: PARALLELIZE BIDS CONVERSION USING HEUDICONV ON THE MPIB CLUSTER
  6. # PROJECT NAME: HIGHSPEED
  7. # WRITTEN BY LENNART WITTKUHN, 2018 - 2020
  8. # CONTACT: WITTKUHN AT MPIB HYPHEN BERLIN DOT MPG DOT DE
  9. # MAX PLANCK RESEARCH GROUP NEUROCODE
  10. # MAX PLANCK INSTITUTE FOR HUMAN DEVELOPMENT
  11. # MAX PLANCK UCL CENTRE FOR COMPUTATIONAL PSYCHIATRY AND AGEING RESEARCH
  12. # LENTZEALLEE 94, 14195 BERLIN, GERMANY
  13. # ==============================================================================
  14. # DEFINE ALL PATHS:
  15. # ==============================================================================
  16. PATH_BASE="${HOME}"
  17. # path to the project root directory
  18. PATH_ROOT="${PATH_BASE}/highspeed"
  19. # define the name of the project:
  20. PROJECT_NAME="highspeed-bids"
  21. # define the path to the project folder:
  22. PATH_PROJECT="${PATH_ROOT}/${PROJECT_NAME}"
  23. # define the path to the input directory:
  24. PATH_INPUT="${PATH_PROJECT}/input/mri"
  25. # define the path to the output directory
  26. PATH_OUTPUT="${PATH_PROJECT}"
  27. # define the path to the singularity container:
  28. PATH_CONTAINER="${PATH_PROJECT}/tools/heudiconv/heudiconv_0.6.0.sif"
  29. # define the path to the code main directory:
  30. PATH_CODE="${PATH_PROJECT}/code/heudiconv"
  31. # path to the heudiconv heuristic file:
  32. HEURISTIC_FILE="highspeed-heudiconv-heuristic.py"
  33. # define path to the python executable file that anonymizes the subject ids:
  34. ANON_FILE="highspeed-heudiconv-anonymizer.py"
  35. # make the anonymizer file executable:
  36. chmod +x "${PATH_CODE}/$ANON_FILE"
  37. # path to the directory where error and out path_logs of cluster jobs are saved:
  38. PATH_LOGS="${PATH_PROJECT}/logs/heudiconv/$(date '+%Y%m%d_%H%M%S')"
  39. # path to the text file with all subject ids:
  40. PATH_SUB_LIST="${PATH_CODE}/highspeed-participant-list.txt"
  41. # ==============================================================================
  42. # CREATE RELEVANT DIRECTORIES:
  43. # ==============================================================================
  44. # create directory for log files:
  45. if [ ! -d ${PATH_LOGS} ]; then
  46. mkdir -p ${PATH_LOGS}
  47. echo "created ${PATH_LOGS}"
  48. fi
  49. # ==============================================================================
  50. # DEFINE PARAMETERS:
  51. # ==============================================================================
  52. # maximum number of cpus per process:
  53. N_CPUS=1
  54. # memory demand in *GB*
  55. MEM_GB=5
  56. # memory demand in *MB*
  57. MEM_MB="$((${MEM_GB} * 1000))"
  58. # read subject ids from the list of the text file
  59. SUB_LIST=$(cat ${PATH_SUB_LIST} | tr '\n' ' ')
  60. # ==============================================================================
  61. # RUN HEUDICONV:
  62. # ==============================================================================
  63. # initalize a subject counter:
  64. SUB_COUNT=0
  65. # loop over all subjects:
  66. for SUB in ${SUB_LIST}; do
  67. # update the subject counter:
  68. let SUB_COUNT=SUB_COUNT+1
  69. # get the subject number with zero padding:
  70. SUB_PAD=$(printf "%02d\n" $SUB_COUNT)
  71. # loop over all sessions:
  72. for SES in `seq 1 2`; do
  73. # get the session number with zero padding:
  74. SES_PAD=$(printf "%02d\n" $SES)
  75. # define the dicom template for the heudiconv command:
  76. DICOM_DIR_TEMPLATE="HIGHSPEED_{subject}_HIGHSPEED_{subject}_${SES}*/*/*/*IMA"
  77. # check the existence of the input files and continue if data is missing:
  78. if [ ! -d ${PATH_INPUT}/HIGHSPEED_${SUB}_HIGHSPEED_${SUB}_${SES}_* ]; then
  79. echo "No data input available for sub-${SUB} ses-${SES_PAD}!"
  80. continue
  81. fi
  82. # start slurm job file:
  83. echo "#!/bin/bash" > job
  84. # name of the job:
  85. echo "#SBATCH --job-name heudiconv_sub-${SUB_PAD}_ses-${SES_PAD}" >> job
  86. # select partition:
  87. echo "#SBATCH --partition gpu" >> job
  88. # set the expected maximum running time for the job:
  89. echo "#SBATCH --time 12:00:00" >> job
  90. # determine how much RAM your operation needs:
  91. echo "#SBATCH --mem ${MEM_GB}GB" >> job
  92. # request multiple cpus
  93. echo "#SBATCH --cpus-per-task ${N_CPUS}" >> job
  94. # write output and error log to log folder:
  95. echo "#SBATCH --output ${PATH_LOGS}/slurm-%j.out" >> job
  96. # email notification on abort/end, use 'n' for no notification:
  97. echo "#SBATCH --mail-type NONE" >> job
  98. # set working directory
  99. echo "#SBATCH --workdir ." >> job
  100. # define the heudiconv command:
  101. echo "singularity run -B ${PATH_INPUT}:/input:ro \
  102. -B ${PATH_OUTPUT}:/output:rw -B ${PATH_CODE}:/code:ro \
  103. ${PATH_CONTAINER} -d /input/${DICOM_DIR_TEMPLATE} -s ${SUB} \
  104. --ses ${SES_PAD} -o /output -f /code/${HEURISTIC_FILE} \
  105. --anon-cmd /code/${ANON_FILE} -c dcm2niix -b --overwrite" >> job
  106. # submit job to cluster queue and remove it to avoid confusion:
  107. sbatch job
  108. rm -f job
  109. done
  110. done