Singularity_r2042 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. Bootstrap: docker
  2. From: debian:buster-slim
  3. %setup
  4. mkdir -p ${SINGULARITY_ROOTFS}/batch
  5. mkdir -p ${SINGULARITY_ROOTFS}/code
  6. mkdir -p ${SINGULARITY_ROOTFS}/downloads
  7. chmod -R 777 ${SINGULARITY_ROOTFS}/code
  8. %post
  9. apt-get update
  10. apt-get -y install wget unzip libxext6 libxt6 moreutils
  11. # download software & unzip
  12. MCRURL="https://ssd.mathworks.com/supportfiles/downloads/R2017b/deployment_files/R2017b/installers/glnxa64/MCR_R2017b_glnxa64_installer.zip"
  13. # SPMURL="http://www.neuro.uni-jena.de/cat12/CAT12.8.1_r2042_R2017b_MCR_Linux.zip"
  14. SPMURL="http://141.35.69.218/cat12/CAT12.8.1_r2042_R2017b_MCR_Linux.zip"
  15. cd /downloads
  16. wget "${MCRURL}" && unzip -d /downloads/MCR MCR_R2017b_glnxa64_installer.zip
  17. wget "${SPMURL}" && unzip -d /code/SPM CAT12.8.1_r2042_R2017b_MCR_Linux.zip
  18. # install MCR
  19. /downloads/MCR/install -mode silent -agreeToLicense yes
  20. # generalize CAT12 version
  21. mv /code/SPM/CAT12.8.1_r2042_R2017b_MCR_Linux/ /code/SPM/MCR_Linux/
  22. # install SPM
  23. /code/SPM/MCR_Linux/run_spm12.sh /usr/local/MATLAB/MATLAB_Runtime/v93 quit
  24. cd /code/SPM/MCR_Linux && chmod +rx run_spm12.sh spm12.sh spm12 spm12.ctf
  25. # install CAT standalone interface
  26. STANDALONE="/code/SPM/MCR_Linux/standalone"
  27. cd ${STANDALONE} && chmod +rx *.sh
  28. cd /code && ln -s ${STANDALONE}/*.sh .
  29. cd /batch && ln -s ${STANDALONE}/*.m .
  30. # set permissions
  31. find /code -type f -print0 | xargs -0 chmod +r
  32. find /code/SPM/MCR_Linux/spm12_mcr/ -name 'CAT.glnx86' -print0 | xargs -0 chmod +rx -R
  33. rm -f code/cat_standalone_segment_enigma.m
  34. wget https://raw.githubusercontent.com/juaml/CAT_stacking_container/refs/heads/bax24-patch-1/cat_standalone_segment_enigma.m?token=GHSAT0AAAAAACX63A3JYCV6T6VTYPTUXO5MZX2SXMQ -O /code/cat_standalone_segment_enigma.m
  35. chmod -R 777 /code*
  36. rm -fr /downloads
  37. apt-get clean
  38. apt-get autoremove
  39. %environment
  40. export SPMROOT=/code/SPM/MCR_Linux
  41. export MCRROOT=/usr/local/MATLAB/MATLAB_Runtime/v93
  42. export MCR_INHIBIT_CTF_LOCK=1
  43. %runscript
  44. NOW=$(date +%s)
  45. exec /code/cat_standalone.sh "$@" 2>&1 |tee cat_$NOW.log
  46. %labels
  47. Authors Malgorzata Wierzba (m.wierzba@fz-juelich.de)
  48. Felix Hoffstaedter (f.hoffstaedter@fz-juelich.de)
  49. Version 1.1
  50. %help
  51. This container allows to run the standalone, compiled version of the
  52. Computational Anatomy Toolbox (CAT), which is an extension to SPM
  53. software. Using the container does not require the availability of a
  54. MATLAB licence.
  55. The container includes:
  56. - MATLAB Compiler Runtime (R2017b, 9.3)
  57. - Standalone version of SPM software (SPM12, r7771)
  58. - Computational Anatomy Toolbox (CAT12.8 r2042)
  59. - CAT interface scripts (cat_standalone.sh, cat_parallelize.sh).
  60. For more details on the exact version of the software used in this
  61. container, please refer to the README file.
  62. HOW TO USE:
  63. In principle this container allows you to perform the very same types
  64. of analysis that are possible with the standalone version of CAT. It
  65. is assumed that the user is familiar with the content of the batch
  66. files dedicated for the use with the standalone version of CAT
  67. (cat_standalone_segment.m, cat_standalone_simple.m,
  68. cat_standalone_resample.m, cat_standalone_smooth.m) and can modify
  69. their content according to his/her needs. For more details, please
  70. refer to the CAT12 documentation and manual.
  71. -- Available batch files --
  72. The content of the batch files can be explored by using the 'view' and
  73. 'copy' subcommands:
  74. singularity run <container> <subcommand> <batch file> <arguments>
  75. To view a batch file, use the 'view' subcommand:
  76. singularity run container.simg view cat_standalone_smooth.m
  77. To copy a batch file to your computer, use the 'copy' subcommand and
  78. specify destination path as an additional argument:
  79. singularity run container.simg copy cat_standalone_smooth.m $HOME
  80. Make sure that the specified path is mounted to the container (more
  81. information on this can be found below) and that you have write access
  82. to this path!
  83. To copy all available batch files, use the 'all' argument:
  84. singularity run container.simg copy all $HOME
  85. -- Running CAT --
  86. Run the CAT analysis with the following command:
  87. singularity run --cleanenv <container> <batch file> <arguments>
  88. To use a default batch file, use one of the files included in the
  89. container ('/batch'):
  90. singularity run --cleanenv container.simg \
  91. -b /batch/cat_standalone_segment.m \
  92. T1.nii
  93. To use your own, customised batch file, simply specify its path:
  94. singularity run --cleanenv container.simg \
  95. -b $HOME/cat_standalone_segment.m \
  96. T1.nii
  97. -- Bind paths --
  98. Please note that most of the host files remain inaccessible from within
  99. the container. By default the following directories are mounted within
  100. the container: '$HOME', '/tmp', '/proc', '/sys', '/dev', and '$PWD'
  101. (see the Singularity documentation for more details).
  102. If you want the container to be able to access other locations,
  103. specify a bind path of your choice. For instance, to make the contents
  104. of the '/data' folder on your computer available in the '/mnt' folder
  105. inside the container, specify the mount point in the following way:
  106. singularity run --cleanenv --bind /data:/mnt container.simg \
  107. -b /batch/cat_standalone_segment.m \
  108. /mnt/T1.nii
  109. EXAMPLES:
  110. USAGE:
  111. cat_standalone.sh filename(s) [-s spm_standalone_folder] [-m mcr_folder] [-b batch_file]
  112. [-a1 additional_argument1] [-a2 additional_argument2]
  113. [-a add_to_batch]
  114. -s <DIR> | --spm <DIR> SPM12 folder of standalone version (can be also defined by SPMROOT)
  115. -m <DIR> | --mcr <DIR> Matlab Compiler Runtime (MCR) folder (can be also defined by MCRROOT)
  116. -b <FILE> | --batch <FILE> batch file to execute
  117. -a1 <STRING>| --arg1 <STRING> 1st additional argument (otherwise use defaults or batch)
  118. -a2 <STRING>| --arg2 <STRING> 2nd additional argument (otherwise use defaults or batch)
  119. -a <STRING> | --add <STRING> add option to batch file
  120. The first occurance of the parameter "<UNDEFINED>" in the batch file will be replaced by the
  121. list of input files. You can use the existing batch files in this folder or create your own batch
  122. file with the SPM12 batch editor and leave the data field undefined. Please note that for creating
  123. your own batch file CAT12 has to be called in expert mode because the CAT12 standalone installation
  124. will only run in expert mode to allow more options.
  125. See cat_standalone_segment.m for an example.
  126. You can also define one or two optional arguments to change other parameters that are indicated by
  127. "<UNDEFINED>" in the batch file. Please take care of the order of the "<UNDEFINED>" fields in the
  128. batch file! If no additional arguments are defined the default values are used.
  129. Also, you must use multiple quotes if the argument is a string (e.g. " 'your_string' ").
  130. If you use a computer cluster it is recommended to use the batch files to only process one data set
  131. and use a job or queue tool to call the (single) jobs on the cluster.
  132. PURPOSE:
  133. Command line call of (CAT12) batch files for SPM12 standalone installation
  134. EXAMPLES
  135. -----------------------------------------------------------------------------------------------
  136. Segmentation
  137. -a1 TPM
  138. -a2 Shooting template
  139. -----------------------------------------------------------------------------------------------
  140. cat_standalone.sh -s $SPMROOT -m /Applications/MATLAB/MATLAB_Runtime/v93 \
  141. -b ${cwd}/cat_standalone_segment.m sTRIO0001.nii
  142. Preprocess (segment) the single file sTRIO0001.nii using the default CAT12 preprocessing batch.
  143. SPM12 standalone version is located in $SPMROOT and Matlab Compiler Runtime in
  144. /Applications/MATLAB/MATLAB_Runtime/v93.
  145. cat_standalone.sh -s $SPMROOT -m /Applications/MATLAB/MATLAB_Runtime/v93 \
  146. -b ${cwd}/cat_standalone_segment.m sTRIO000*.nii.gz \
  147. -a1 " '${cat12_dir}/templates_MNI152NLin2009cAsym/TPM_Age11.5.nii' " \
  148. -a2 " '${cat12_dir}/templates_MNI152NLin2009cAsym/Template_0_GS1mm.nii' "
  149. Unzip and preprocess (segment) the files sTRIO0001.nii.gz using the default CAT12 preprocessing
  150. batch, but use the children TPM provided with CAT12 and a 1mm Shooting template (not provided
  151. with CAT12). Please note that zipped file can only be handled with this standalone batch and also
  152. note the multiple quotes for parameter a1 and a2.
  153. cat_standalone.sh -s $SPMROOT -m /Applications/MATLAB/MATLAB_Runtime/v93 \
  154. -b ${cwd}/cat_standalone_segment.m sTRIO0001.nii \
  155. -a "matlabbatch{1}.spm.tools.cat.estwrite.output.surface = 0;"
  156. Preprocess (segment) the single file sTRIO0001.nii using the default CAT12 preprocessing batch,
  157. but skip surface estimation.
  158. -----------------------------------------------------------------------------------------------
  159. Longitudinal Segmentation
  160. -a1 longitudinal model (0 - developmental; 1 - plasticity/learning; 2 - aging; 3 - save models 1 and 2)
  161. -a2 TPM
  162. -----------------------------------------------------------------------------------------------
  163. cat_standalone.sh -s $SPMROOT -m /Applications/MATLAB/MATLAB_Runtime/v93 \
  164. -b ${cwd}/cat_standalone_segment_long.m sTRIO000*.nii \
  165. -a1 "2"
  166. Preprocess (segment) the files sTRIO000*.nii with the longitudinal pipeline optimized for
  167. detecting aging/developmental effects. In order to choose the longitudinal model optimized for
  168. detecting small changes due to plasticity/learning change the a1 parameter to "1".
  169. cat_standalone.sh -s $SPMROOT -m /Applications/MATLAB/MATLAB_Runtime/v93 \
  170. -b ${cwd}/cat_standalone_segment_long.m sTRIO000*.nii \
  171. -a1 "1" -a2 " '${cat12_dir}/templates_MNI152NLin2009cAsym/TPM_Age11.5.nii' "
  172. Preprocess (segment) the files sTRIO000*.nii with the longitudinal pipeline optimized for
  173. detecting plasticity/learning effects and use the children TPM provided with CAT12.
  174. Please note the multiple quotes for parameter a2.
  175. -----------------------------------------------------------------------------------------------
  176. Segmentation (Simple Mode)
  177. -----------------------------------------------------------------------------------------------
  178. cat_standalone.sh -s $SPMROOT -m /Applications/MATLAB/MATLAB_Runtime/v93 \
  179. -b ${cwd}/cat_standalone_simple.m sTRIO0001.nii
  180. Process the single file sTRIO0001.nii using the simple processing batch.
  181. -----------------------------------------------------------------------------------------------
  182. Resample & Smooth Surfaces
  183. -a1 smoothing filter size surface values
  184. -a2 use 32k mesh from HCP (or 164k mesh from Freesurfer)
  185. -----------------------------------------------------------------------------------------------
  186. cat_standalone.sh -s $SPMROOT -m /Applications/MATLAB/MATLAB_Runtime/v93 \
  187. -b ${cwd}/cat_standalone_resample.m lh.thickness.sTRIO0001 \
  188. -a1 "12" -a2 "1"
  189. Resample and smooth the single thickness file lh.thickness.sTRIO0001 with 12mm and save the
  190. resampled mesh as 32k mesh (HCP conform mesh). Only the left surface file has to be defined.
  191. The right hemisphere is processed automatically.
  192. -----------------------------------------------------------------------------------------------
  193. Smoothing
  194. -a1 smoothing filter size
  195. -a2 prepending string for smoothed file (e.g. 's6')
  196. -----------------------------------------------------------------------------------------------
  197. cat_standalone.sh -s $SPMROOT -m /Applications/MATLAB/MATLAB_Runtime/v93 \
  198. -b ${cwd}/cat_standalone_smooth.m sTRIO*nii \
  199. -a1 "[6 6 6]" -a2 " 's6' "
  200. Smooth the volume files sTRIO*nii with 6mm and prepend the string "s6" to the smoothed files.
  201. Please note the multiple quotes for parameter a2.
  202. -----------------------------------------------------------------------------------------------
  203. Dicom Import
  204. -a1 directory structure
  205. -a2 output directory
  206. -----------------------------------------------------------------------------------------------
  207. cat_standalone.sh -s $SPMROOT -m /Applications/MATLAB/MATLAB_Runtime/v93 \
  208. -b ${cwd}/cat_standalone_dicom2nii.m *.dcm \
  209. -a1 " 'patid_date' " -a2 "{'converted'}"
  210. Import DICOM files *.dcm and save converted nifti files in directory "converted" with structure
  211. ./<PatientID>/<StudyDate-StudyTime>/<ProtocollName>
  212. Other options for directory structure are:
  213. 'flat' No directory hierarchy
  214. 'series' ./<ProtocollName>
  215. 'patid_date' ./<PatientID>/<StudyDate-StudyTime>/<ProtocollName>
  216. 'patid' ./<PatientID>/<ProtocollName>
  217. 'date_time' ./<StudyDate-StudyTime>/<ProtocollName>
  218. Please note the multiple quotes for parameter a1.
  219. -----------------------------------------------------------------------------------------------
  220. De-Facing
  221. -----------------------------------------------------------------------------------------------
  222. cat_standalone.sh -s $SPMROOT -m /Applications/MATLAB/MATLAB_Runtime/v93 \
  223. -b ${cwd}/cat_standalone_deface.m sTRIO*.nii
  224. Apply de-facing to sTRIO*.nii and save the files prefixed by "anon_".
  225. -----------------------------------------------------------------------------------------------
  226. Estimate and Save Quality Measures for Volumes or Surfaces
  227. -a1 csv output filename
  228. -a2 enable global scaling with TIV (only for volumes meaningful)
  229. -----------------------------------------------------------------------------------------------
  230. cat_standalone.sh -s $SPMROOT -m /Applications/MATLAB/MATLAB_Runtime/v93 \
  231. -b ${cwd}/cat_standalone_get_quality.m mwp1sTRIO*nii \
  232. -a1 " 'Quality_measures.csv' " -a2 "1"
  233. Estimate mean z-scores using global scaling with TIV for the files mwp1sTRIO*nii and save quality
  234. measures in Quality_measures.csv for external analysis. Processing of surface meshes is also
  235. supported.
  236. Please note the multiple quotes for parameter a1.
  237. -----------------------------------------------------------------------------------------------
  238. Estimate mean/volume inside ROI
  239. -a1 output-file string
  240. -----------------------------------------------------------------------------------------------
  241. cat_standalone.sh -s $SPMROOT -m /Applications/MATLAB/MATLAB_Runtime/v93 \
  242. -b ${cwd}/cat_standalone_get_ROI_values.m catROI_*.xml \
  243. -a1 " 'ROI' "
  244. Save mean volume values in mL (e.g. GM volume) or the mean surface values (e.g. thickness) for
  245. all data catROI_*.xml in a csv-file. The csv-file is named "ROI_" followed by the atlas name
  246. and the name of the measure (e.g. Vgm).
  247. Please note the multiple quotes for parameter a1.
  248. -----------------------------------------------------------------------------------------------
  249. TFCE Statistical Estimation
  250. -a1 contrast number
  251. -a2 number of permutations
  252. -----------------------------------------------------------------------------------------------
  253. cat_standalone.sh -s $SPMROOT -m /Applications/MATLAB/MATLAB_Runtime/v93 \
  254. -b ${cwd}/cat_standalone_tfce.m SPM.mat \
  255. -a1 "2" -a2 "20000"
  256. Call estimation of TFCE statistics for the given SPM.mat file for contrast number 2 with 20000
  257. permutations.
  258. -----------------------------------------------------------------------------------------------
  259. Parallelization
  260. -----------------------------------------------------------------------------------------------
  261. cat_parallelize.sh -p 8 -l /tmp \
  262. -c "cat_standalone.sh -s $SPMROOT -m /Applications/MATLAB/MATLAB_Runtime/v93 -b ${cwd}/cat_standalone_segment.m" sTRIO*.nii
  263. Parallelize CAT12 preprocessing by splitting all sTRIO*.nii files into 8 jobs
  264. (processes) and save log file in /tmp folder.
  265. The parameters SPMROOT and MCRROOT have to be defined (exported) to skip the use of the flags -s -m.
  266. INPUT:
  267. nifti files or surface data
  268. OUTPUT:
  269. processed images and optionally surfaces according to settings in cat_standalone_*.m
  270. USED FUNCTIONS:
  271. cat_parallelize.sh
  272. SPM12 standalone version (compiled)
  273. CAT12 toolbox (compiled within SPM12 if installed)
  274. MATLAB Compiler Runtime R2017b (Version 9.3)
  275. This script was written by Christian Gaser (christian.gaser@uni-jena.de).
  276. This is ${version}.
  277. Known issues:
  278. - Parallelization with cat_parallelize.sh is not implemented yet.
  279. - Longitudinal segmentation with cat_standalone_segment_long.m
  280. is not tested yet.
  281. Contact information:
  282. Any problems or concerns regarding this container should be reported
  283. to Malgorzata Wierzba (m.wierzba@fz-juelich.de), Michael Hanke
  284. (m.hanke@fz-juelich.de) or Felix Hoffstaedter (f.hoffstaedter@fz-juelich.de)
  285. Acknowledgements:
  286. The CAT toolbox (http://www.neuro.uni-jena.de/cat) is developed by
  287. Christian Gaser and Robert Dahnke (Jena University Hospital,
  288. Departments of Psychiatry and Neurology) and is free but copyright
  289. software, distributed under the terms of the GNU General Public
  290. Licence.
  291. The SPM software (https://www.fil.ion.ucl.ac.uk/spm/) is developed by
  292. the Wellcome Trust Centre for Neuroimaging and is free but copyright
  293. software, distributed under the terms of the GNU General Public
  294. Licence.
  295. MATLAB Compiler Runtime
  296. (https://uk.mathworks.com/products/compiler/matlab-runtime.html) is
  297. developed by the The MathWorks, Inc. and is subject to the MATLAB
  298. Runtime licence.