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.

copy-to-bids_template.sh 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. #!/bin/bash
  2. # ==========================================================================
  3. # ___ _ _
  4. # | __(_) |___ ___
  5. # | _|| | / -_|_-<
  6. # |_| |_|_\___/__/
  7. #
  8. # ==========================================================================
  9. # NB! This should be the only area where you need to make changes ----
  10. # files with get run numbers in the order they are in the array
  11. # for functionals (+ beh/eye), run numbers should be explixitly defined
  12. # subfolder where the scan files are located
  13. SF=MRI
  14. # ==========================================================================
  15. # STRUCTURAL
  16. # ==========================================================================
  17. # leave array empty if there are no such files
  18. # T1 ----
  19. declare -a T1s=(\
  20. T1.nii.gz
  21. )
  22. # T2 ----
  23. declare -a T2s=(\
  24. T2.nii.gz
  25. )
  26. # Fieldmap ----
  27. declare -a fmap_mag=(\
  28. B0_e1a.nii.gz
  29. )
  30. declare -a fmap_phase=(\
  31. B0_e1.nii.gz
  32. )
  33. # DWI ----
  34. declare -a DWI=(\
  35. DTI64.nii.gz
  36. )
  37. # ==========================================================================
  38. # FUNCTIONAL
  39. # ==========================================================================
  40. # leave array empty if there are no such files
  41. # NB corresponding array-positions should correspond!
  42. declare -a func_runnr=( 01 02 03 )
  43. # tasks:
  44. # curvetracing / curvetracinginccentral / ctcheckerboard
  45. # prf / rest / figgnd / figgndloc / checkerHRF / naturalmovie
  46. declare -a task=( \
  47. xxx
  48. xxx
  49. )
  50. # MRI-data functional runs
  51. declare -a funcs=( \
  52. xxx
  53. xxx
  54. )
  55. # Corresponding topup-scans
  56. # when these exist there should be the same number of entries as the functional runs
  57. declare -a topup=( \
  58. xxx
  59. xxx
  60. )
  61. # behavioral log folders
  62. declare -a behs=( \
  63. xxx
  64. xxx
  65. )
  66. # eye tracking files
  67. declare -a eyes=( \
  68. xxx
  69. xxx
  70. )
  71. # ==========================================================================
  72. # ___ _ _ _
  73. # | __|__| |__| |___ _ _ ___ ___| |_ _ _ _ __
  74. # | _/ _ \ / _` / -_) '_| (_-</ -_) _| || | '_ \
  75. # |_|\___/_\__,_\___|_| /__/\___|\__|\_,_| .__/
  76. # |_|
  77. # ==========================================================================
  78. # check if we have the right permissions ----
  79. SCRIPT_PATH="`dirname \"$0\"`" # relative
  80. SCRIPT_PATH="`( cd \"$SCRIPT_PATH\" && pwd )`" # absolutized and normalized
  81. if [ -z "$SCRIPT_PATH" ] ; then
  82. exit 1 # fail
  83. fi
  84. # local path ----
  85. BIDS_DEST=$SCRIPT_PATH
  86. # raw to BIDS ----
  87. BIDS_DEST="${BIDS_DEST/Data_raw/NHP-BIDS}"
  88. # subjects ----
  89. BIDS_DEST="${BIDS_DEST/MXXX/sub-MXXX}"
  90. BIDS_DEST="${BIDS_DEST/MXXX/sub-MXXX}"
  91. BIDS_DEST="${BIDS_DEST/MXXX/sub-MXXX}"
  92. # sessions ----
  93. BIDS_DEST="${BIDS_DEST/2016/ses-2016}"
  94. BIDS_DEST="${BIDS_DEST/2017/ses-2017}"
  95. BIDS_DEST="${BIDS_DEST/2018/ses-2018}"
  96. BIDS_DEST="${BIDS_DEST/2019/ses-2019}"
  97. BIDS_DEST="${BIDS_DEST/2019/ses-2019}"
  98. BIDS_DEST="${BIDS_DEST/2020/ses-2020}"
  99. BIDS_DEST="${BIDS_DEST/2021/ses-2021}"
  100. BIDS_DEST="${BIDS_DEST/2022/ses-2022}"
  101. # sourcedata ----
  102. BIDS_UNPROC_DEST="${BIDS_DEST/NHP-BIDS/NHP-BIDS/sourcedata}"
  103. # some feedback to terminal ----
  104. echo '=============================================='
  105. echo "Copying BIDS data to"
  106. echo $BIDS_DEST
  107. echo $BIDS_UNPROC_DEST
  108. echo '=============================================='
  109. # create some useful variables ----
  110. date=$(basename $(pwd))
  111. SUBJ=$(basename $(dirname $(pwd)))
  112. subj=$(echo $SUBJ | tr '[:upper:]' '[:lower:]')
  113. bsub="sub-${subj}"
  114. bses="ses-${date}"
  115. # ==========================================================================
  116. # _ _ _ _
  117. # /_\ _ _ __ _| |_ ___ _ __ (_)__ __ _| |
  118. # / _ \| ' \/ _` | _/ _ \ ' \| / _/ _` | |
  119. # /_/ \_\_||_\__,_|\__\___/_|_|_|_\__\__,_|_|
  120. #
  121. # ==========================================================================
  122. echo "Copying anatomicals (if they exist) ---"
  123. runnr=0
  124. if [ ${#T1s[@]} -eq 0 ]; then
  125. echo 'No T1s declared'
  126. else
  127. echo 'T1 scans'
  128. mkdir -p "$BIDS_UNPROC_DEST/anat"
  129. for i in "${!T1s[@]}"; do
  130. runnr=$((runnr + 1))
  131. base=$(basename ${T1s[$i]} .nii.gz)
  132. cp -n ${SF}/${base}.nii.gz "$BIDS_UNPROC_DEST/anat/${bsub}_${bses}_acq-nosense_run-${runnr}_T1w.nii.gz"
  133. # if there are json files copy them too
  134. if [ -f ${SF}/${base}.json ]; then
  135. cp -n ${SF}/${base}.json "$BIDS_UNPROC_DEST/anat/${bsub}_${bses}_acq-nosense_run-${runnr}_T1w.json"
  136. fi
  137. done
  138. fi
  139. runnr=0
  140. if [ ${#T2s[@]} -eq 0 ]; then
  141. echo 'No T2s declared'
  142. else
  143. echo 'T2 scans'
  144. mkdir -p "$BIDS_UNPROC_DEST/anat"
  145. for i in "${!T2s[@]}"; do
  146. runnr=$((runnr + 1))
  147. base=$(basename ${T2s[$i]} .nii.gz)
  148. cp -n ${SF}/${base}.nii.gz "$BIDS_UNPROC_DEST/anat/${bsub}_${bses}_acq-nosense_run-${runnr}_T2w.nii.gz"
  149. # if there are json files copy them too
  150. if [ -f ${SF}/${base}.json ]; then
  151. cp -n ${SF}/${base}.json "$BIDS_UNPROC_DEST/anat/${bsub}_${bses}_acq-nosense_run-${runnr}_T2w.json"
  152. fi
  153. done
  154. fi
  155. # ==========================================================================
  156. # ___ _ _ _
  157. # | __(_)___| |__| |_ __ __ _ _ __
  158. # | _|| / -_) / _` | ' \/ _` | '_ \
  159. # |_| |_\___|_\__,_|_|_|_\__,_| .__/
  160. # |_|
  161. # ==========================================================================
  162. echo "Copying fieldmaps (if they exist) ---"
  163. runnr=0
  164. if [ ${#fmap_mag[@]} -eq 0 ]; then
  165. echo 'No B0 magnitude files declared'
  166. else
  167. echo 'Magnitude'
  168. mkdir -p "$BIDS_UNPROC_DEST/fmap"
  169. for i in "${!fmap_mag[@]}"; do
  170. runnr=$((runnr + 1))
  171. base=$(basename ${fmap_mag[$i]} .nii.gz)
  172. cp -n ${SF}/${base}.nii.gz "$BIDS_UNPROC_DEST/fmap/${bsub}_${bses}_magnitude1.nii.gz"
  173. # if there are json files copy them too
  174. if [ -f ${SF}/${base}.json ]; then
  175. cp -n ${SF}/${base}.json "$BIDS_UNPROC_DEST/fmap/${bsub}_${bses}_magnitude1.json"
  176. fi
  177. done
  178. fi
  179. runnr=0
  180. if [ ${#fmap_phase[@]} -eq 0 ]; then
  181. echo 'No B0 phase files declared'
  182. else
  183. echo 'Phase'
  184. mkdir -p "$BIDS_UNPROC_DEST/fmap"
  185. for i in "${!fmap_phase[@]}"; do
  186. runnr=$((runnr + 1))
  187. base=$(basename ${fmap_phase[$i]} .nii.gz)
  188. cp -n ${SF}/${base}.nii.gz "$BIDS_UNPROC_DEST/fmap/${bsub}_${bses}_phasediff.nii.gz"
  189. # if there are json files copy them too
  190. if [ -f ${SF}/${base}.json ]; then
  191. cp -n ${SF}/${base}.json "$BIDS_UNPROC_DEST/fmap/${bsub}_${bses}_phasediff.json"
  192. fi
  193. done
  194. fi
  195. # ==========================================================================
  196. # ___ _____ ___
  197. # | \_ _|_ _|
  198. # | |) || | | |
  199. # |___/ |_| |___|
  200. #
  201. # ==========================================================================
  202. echo "Copying dwi (if they exist) ---"
  203. runnr=0
  204. if [ ${#DWI[@]} -eq 0 ]; then
  205. echo 'No DWI files declared'
  206. else
  207. echo 'DWIs' mkdir -p "$BIDS_UNPROC_DEST/dwi"
  208. for i in "${!DWI[@]}"; do
  209. runnr=$((runnr + 1))
  210. base=$(basename ${DWI[$i]} .nii.gz)
  211. cp -n ${SF}/${base}.nii.gz "$BIDS_UNPROC_DEST/dwi/${bsub}_${bses}_run-${runnr}_dwi.nii.gz"
  212. cp -n ${SF}/${base}.bval "$BIDS_UNPROC_DEST/dwi/${bsub}_${bses}_run-${runnr}_dwi.bval"
  213. cp -n ${SF}/${base}.bvec "$BIDS_UNPROC_DEST/dwi/${bsub}_${bses}_run-${runnr}_dwi.bvec"
  214. # if there are json files copy them too
  215. if [ -f ${SF}/${base}.json ]; then
  216. cp -n ${SF}/${base}.json "$BIDS_UNPROC_DEST/dwi/${bsub}_${bses}_run-${runnr}_dwi.json"
  217. fi
  218. done
  219. fi
  220. # ==========================================================================
  221. # ___ _ _ _
  222. # | __| _ _ _ __| |_(_)___ _ _ __ _| |___
  223. # | _| || | ' \/ _| _| / _ \ ' \/ _` | (_-<
  224. # |_| \_,_|_||_\__|\__|_\___/_||_\__,_|_/__/
  225. #
  226. # ==========================================================================
  227. echo "Copying functionals (if they exist) ---"
  228. if [ ${#funcs[@]} -eq 0 ]; then
  229. echo 'No functionals declared'
  230. else
  231. echo 'EPIs'
  232. mkdir -p "$BIDS_UNPROC_DEST/func"
  233. for i in "${!funcs[@]}"; do
  234. base=$(basename ${funcs[$i]} .nii.gz)
  235. cp -n ${SF}/${funcs[$i]} \
  236. "$BIDS_UNPROC_DEST/func/${bsub}_${bses}_task-${task[$i]}_run-${func_runnr[$i]}_bold.nii.gz"
  237. # if there are json files copy them too
  238. if [ -f ${SF}/${base}.json ]; then
  239. cp -n ${SF}/${base}.json \
  240. "$BIDS_UNPROC_DEST/func/${bsub}_${bses}_task-${task[$i]}_run-${func_runnr[$i]}_bold.json"
  241. fi
  242. done
  243. fi
  244. echo "Copying topups (if they exist) ---"
  245. if [ ${#topup[@]} -eq 0 ]; then
  246. echo 'No TOPUPS declared'
  247. else
  248. echo 'TOPUPs'
  249. mkdir -p "$BIDS_UNPROC_DEST/fmap"
  250. for i in "${!topup[@]}"; do
  251. base=$(basename ${topup[$i]} .nii.gz)
  252. cp -n ${SF}/${topup[$i]} \
  253. "$BIDS_UNPROC_DEST/fmap/${bsub}_${bses}_run-${func_runnr[$i]}_epi.nii.gz"
  254. # if there are json files copy them too
  255. if [ -f ${SF}/${base}.json ]; then
  256. cp -n ${SF}/${base}.json \
  257. "$BIDS_UNPROC_DEST/fmap/${bsub}_${bses}_run-${func_runnr[$i]}_epi.json"
  258. fi
  259. done
  260. fi
  261. # ==========================================================================
  262. # ___ _ _ _
  263. # | _ ) ___| |_ __ ___ _(_)___ _ _ | |___ __ _ ___
  264. # | _ \/ -_) ' \/ _` \ V / / _ \ '_| | / _ \/ _` (_-<
  265. # |___/\___|_||_\__,_|\_/|_\___/_| |_\___/\__, /__/
  266. # |___/
  267. # ==========================================================================
  268. echo "Copying behavioral logs (if they exist) ---"
  269. if [ ${#behs[@]} -eq 0 ]; then
  270. echo 'No behavioral folders declared'
  271. else
  272. echo 'Behavioral files'
  273. mkdir -p "$BIDS_UNPROC_DEST/func"
  274. for i in "${!behs[@]}"; do
  275. cp -n -r Behavior/${behs[$i]} \
  276. "$BIDS_UNPROC_DEST/func/${bsub}_${bses}_task-${task[$i]}_run-${func_runnr[$i]}_events"
  277. done
  278. fi
  279. # also copy run000 is if exists << This needs to be added manually if needed
  280. # cp -r -n Behavior/xxxx "$BIDS_UNPROC_DEST/func/${bsub}_${bses}_task-xxx_run-00_events"
  281. # ==========================================================================
  282. # ___ _
  283. # | __| _ ___ | |_ _ _ __ _ __ ___ ___
  284. # | _| || / -_) | _| '_/ _` / _/ -_|_-<
  285. # |___\_, \___| \__|_| \__,_\__\___/__/
  286. # |__/
  287. #
  288. # ==========================================================================
  289. echo "Copying eye data (if they exist) ---"
  290. if [ ${#eyes[@]} -eq 0 ]; then
  291. echo 'No Eye files declared'
  292. else
  293. echo 'Eye files'
  294. mkdir -p "$BIDS_DEST/func"
  295. for i in "${!eyes[@]}"; do
  296. cp -n Eye/${eyes[$i]} \
  297. "$BIDS_DEST/func/${bsub}_${bses}_task-${task[$i]}_run-${func_runnr[$i]}_recording-eyetrace_physio.tda"
  298. done
  299. fi