participant_job 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/bin/bash
  2. # the job assumes that it is a good idea to run everything in PWD
  3. # the job manager should make sure that is true
  4. # fail whenever something is fishy, use -x to get verbose logfiles
  5. set -e -u -x
  6. dssource="$1"
  7. pushgitremote="$2"
  8. subd="$3"
  9. subid=$(basename $3)
  10. # get the analysis dataset, which includes the inputs as well
  11. # importantly, we do not clone from the lcoation that we want to push the
  12. # results too, in order to avoid too many jobs blocking access to
  13. # the same location and creating a throughput bottleneck
  14. datalad clone "${dssource}" ds
  15. # all following actions are performed in the context of the superdataset
  16. cd ds
  17. # in order to avoid accumulation temporary git-annex availability information
  18. # and to avoid a syncronization bottleneck by having to consolidate the
  19. # git-annex branch across jobs, we will only push the main tracking branch
  20. # back to the output store (plus the actual file content). Final availability
  21. # information can be establish via an eventual "git-annex fsck -f cat12.8.1_out-storage".
  22. # this remote is never fetched, it accumulates a larger number of branches
  23. # and we want to avoid progressive slowdown. Instead we only ever push
  24. # a unique branch per each job (subject AND process specific name)
  25. git remote add outputstore "$pushgitremote"
  26. # all results of this job will be put into a dedicated branch
  27. git checkout -b "job-${JOBID}"
  28. # we pull down the input subject manually in order to discover relevant
  29. # files. We do this outside the recorded call, because on a potential
  30. # re-run we want to be able to do fine-grained recomputing of individual
  31. # outputs. The recorded calls will have specific paths that will enable
  32. # recomputation outside the scope of the original Condor setup
  33. datalad get -n "inputs/CORR/${subd}"
  34. # the meat of the matter
  35. # look for T1w files in the input data for the given participant
  36. # it is critical for reproducibility that the command given to
  37. # "containers-run" does not rely on any property of the immediate
  38. # computational environment (env vars, services, etc)
  39. find \
  40. inputs/CORR/${subd} \
  41. -name "${subid}*T1w.nii.gz" \
  42. -exec sh -c '
  43. odir=$(echo {} | cut -d / -f3-5);
  44. datalad containers-run \
  45. -m "Compute $odir" \
  46. -n cat12-8-1\
  47. --explicit \
  48. -o $odir \
  49. -i {} \
  50. sh -e -u -x -c "
  51. rm -rf {outputs[0]} ;
  52. mkdir -p {outputs[0]} \
  53. && cp {inputs[0]} {outputs[0]} \
  54. && /singularity -b code/cat_standalone_segment_enigma_subdir_rp_MSA.m {outputs[0]}/*.nii.gz \
  55. && /singularity -b code/pipeline/batches/cat_standalone_batch-surfext.m {outputs[0]}/surf/lh.central.* \
  56. && /singularity -b code/pipeline/batches/cat_standalone_batch-thick1.m {outputs[0]}/surf/lh.thickness.* \
  57. && /singularity -b code/pipeline/batches/cat_standalone_batch-thick2.m {outputs[0]}/surf/lh.thickness.* \
  58. && rm -f {outputs[0]}/*.nii* \
  59. && gzip {outputs[0]}/*/*.nii \
  60. " \
  61. ' \;
  62. # remove big files from results after hashing before pushing to ria
  63. datalad drop --what filecontent --reckless kill */sub-*/*/mri/iy* */sub-*/*/mri/y* */sub-*/*/mri/anon_m* */sub-*/*/*/*.pdf */sub-*/*/surf/*sphere*
  64. #### Maybe remove simlinks without data and commit ???
  65. # rm -f */sub-*/*/mri/iy* */sub-*/*/mri/y* # */sub-*/*/mri/anon_m* */sub-*/*/*/*.pdf # */sub-*/*/surf/*sphere*
  66. # datalad save -m "remove simlinks without data"
  67. # file content first -- does not need a lock, no interaction with Git
  68. datalad push --to cat12.8.1_out-storage
  69. # and the output branch
  70. flock --verbose $DSLOCKFILE git push outputstore
  71. echo SUCCESS
  72. # job handler should clean up workspace