Jelajahi Sumber

Upload files to 'Enigma'

Lucas Backes 3 minggu lalu
induk
melakukan
4e755964b1

+ 382 - 0
Enigma/Singularity_r2042

@@ -0,0 +1,382 @@
+Bootstrap: docker
+From: debian:buster-slim
+
+%setup
+    mkdir -p ${SINGULARITY_ROOTFS}/batch
+    mkdir -p ${SINGULARITY_ROOTFS}/code
+    mkdir -p ${SINGULARITY_ROOTFS}/downloads
+
+    chmod -R 777 ${SINGULARITY_ROOTFS}/code
+
+%post
+    apt-get update
+    apt-get -y install wget unzip libxext6 libxt6 moreutils
+
+    # download software & unzip
+    MCRURL="https://ssd.mathworks.com/supportfiles/downloads/R2017b/deployment_files/R2017b/installers/glnxa64/MCR_R2017b_glnxa64_installer.zip"
+    # SPMURL="http://www.neuro.uni-jena.de/cat12/CAT12.8.1_r2042_R2017b_MCR_Linux.zip"
+    SPMURL="http://141.35.69.218/cat12/CAT12.8.1_r2042_R2017b_MCR_Linux.zip"
+
+    cd /downloads
+    wget "${MCRURL}" && unzip -d /downloads/MCR MCR_R2017b_glnxa64_installer.zip
+    wget "${SPMURL}" && unzip -d /code/SPM CAT12.8.1_r2042_R2017b_MCR_Linux.zip
+    
+
+    # install MCR
+    /downloads/MCR/install -mode silent -agreeToLicense yes
+
+    # generalize CAT12 version
+    mv /code/SPM/CAT12.8.1_r2042_R2017b_MCR_Linux/ /code/SPM/MCR_Linux/
+
+    # install SPM
+    /code/SPM/MCR_Linux/run_spm12.sh /usr/local/MATLAB/MATLAB_Runtime/v93 quit
+    cd /code/SPM/MCR_Linux && chmod +rx run_spm12.sh spm12.sh spm12 spm12.ctf
+
+    # install CAT standalone interface
+    STANDALONE="/code/SPM/MCR_Linux/standalone"
+    cd ${STANDALONE} && chmod +rx *.sh
+    cd /code && ln -s ${STANDALONE}/*.sh .
+    cd /batch && ln -s ${STANDALONE}/*.m .
+  
+    # set permissions
+    find /code -type f -print0 | xargs -0 chmod +r
+    find /code/SPM/MCR_Linux/spm12_mcr/ -name 'CAT.glnx86' -print0 | xargs -0 chmod +rx -R
+    rm -f code/cat_standalone_segment_enigma.m
+    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
+
+    chmod -R 777 /code*
+
+    rm -fr /downloads
+
+    apt-get clean
+    apt-get autoremove
+
+%environment
+    export SPMROOT=/code/SPM/MCR_Linux
+    export MCRROOT=/usr/local/MATLAB/MATLAB_Runtime/v93
+    export MCR_INHIBIT_CTF_LOCK=1
+
+%runscript
+    NOW=$(date +%s)
+    exec /code/cat_standalone.sh "$@" 2>&1 |tee cat_$NOW.log
+
+%labels
+    Authors Malgorzata Wierzba (m.wierzba@fz-juelich.de)
+            Felix Hoffstaedter (f.hoffstaedter@fz-juelich.de)
+    Version 1.1
+
+%help
+
+This container allows to run the standalone, compiled version of the
+Computational Anatomy Toolbox (CAT), which is an extension to SPM
+software. Using the container does not require the availability of a
+MATLAB licence.
+
+The container includes:
+
+- MATLAB Compiler Runtime (R2017b, 9.3)
+- Standalone version of SPM software (SPM12, r7771)
+- Computational Anatomy Toolbox (CAT12.8 r2042)
+- CAT interface scripts (cat_standalone.sh, cat_parallelize.sh).
+
+For more details on the exact version of the software used in this
+container, please refer to the README file.
+
+
+HOW TO USE:
+
+In principle this container allows you to perform the very same types
+of analysis that are possible with the standalone version of CAT. It
+is assumed that the user is familiar with the content of the batch
+files dedicated for the use with the standalone version of CAT
+(cat_standalone_segment.m, cat_standalone_simple.m,
+cat_standalone_resample.m, cat_standalone_smooth.m) and can modify
+their content according to his/her needs. For more details, please
+refer to the CAT12 documentation and manual.
+
+
+-- Available batch files --
+
+The content of the batch files can be explored by using the 'view' and
+'copy' subcommands:
+
+singularity run <container> <subcommand> <batch file> <arguments>
+
+To view a batch file, use the 'view' subcommand:
+
+singularity run container.simg view cat_standalone_smooth.m
+
+To copy a batch file to your computer, use the 'copy' subcommand and
+specify destination path as an additional argument:
+
+singularity run container.simg copy cat_standalone_smooth.m $HOME
+
+Make sure that the specified path is mounted to the container (more
+information on this can be found below) and that you have write access
+to this path!
+
+To copy all available batch files, use the 'all' argument:
+
+singularity run container.simg copy all $HOME
+
+
+-- Running CAT --
+
+Run the CAT analysis with the following command:
+singularity run --cleanenv <container> <batch file> <arguments>
+
+To use a default batch file, use one of the files included in the
+container ('/batch'):
+singularity run --cleanenv container.simg \
+	-b /batch/cat_standalone_segment.m \
+	T1.nii
+
+To use your own, customised batch file, simply specify its path:
+singularity run --cleanenv container.simg \
+	-b $HOME/cat_standalone_segment.m \
+	T1.nii
+
+
+-- Bind paths --
+
+Please note that most of the host files remain inaccessible from within
+the container. By default the following directories are mounted within
+the container: '$HOME', '/tmp', '/proc', '/sys', '/dev', and '$PWD'
+(see the Singularity documentation for more details).
+
+If you want the container to be able to access other locations,
+specify a bind path of your choice. For instance, to make the contents
+of the '/data' folder on your computer available in the '/mnt' folder
+inside the container, specify the mount point in the following way:
+
+singularity run --cleanenv --bind /data:/mnt container.simg \
+	-b /batch/cat_standalone_segment.m \
+	/mnt/T1.nii
+
+
+EXAMPLES:
+
+USAGE:
+   cat_standalone.sh filename(s) [-s spm_standalone_folder] [-m mcr_folder] [-b batch_file]
+                                 [-a1 additional_argument1] [-a2 additional_argument2]
+                                 [-a add_to_batch]
+
+   -s <DIR>    | --spm <DIR>     SPM12 folder of standalone version (can be also defined by SPMROOT)
+   -m <DIR>    | --mcr <DIR>     Matlab Compiler Runtime (MCR) folder (can be also defined by MCRROOT)
+   -b <FILE>   | --batch <FILE>  batch file to execute
+   -a1 <STRING>| --arg1 <STRING> 1st additional argument (otherwise use defaults or batch)
+   -a2 <STRING>| --arg2 <STRING> 2nd additional argument (otherwise use defaults or batch)
+   -a <STRING> | --add  <STRING> add option to batch file
+
+   The first occurance of the parameter "<UNDEFINED>" in the batch file will be replaced by the
+   list of input files. You can use the existing batch files in this folder or create your own batch
+   file with the SPM12 batch editor and leave the data field undefined. Please note that for creating
+   your own batch file CAT12 has to be called in expert mode because the CAT12 standalone installation
+   will only run in expert mode to allow more options.
+   See cat_standalone_segment.m for an example.
+
+   You can also define one or two optional arguments to change other parameters that are indicated by
+   "<UNDEFINED>" in the batch file. Please take care of the order of the "<UNDEFINED>" fields in the
+   batch file! If no additional arguments are defined the default values are used.
+   Also, you must use multiple quotes if the argument is a string (e.g. " 'your_string' ").
+
+   If you use a computer cluster it is recommended to use the batch files to only process one data set
+   and use a job or queue tool to call the (single) jobs on the cluster.
+
+PURPOSE:
+   Command line call of (CAT12) batch files for SPM12 standalone installation
+
+EXAMPLES
+   -----------------------------------------------------------------------------------------------
+   Segmentation
+     -a1 TPM
+     -a2 Shooting template
+   -----------------------------------------------------------------------------------------------
+   cat_standalone.sh -s $SPMROOT -m /Applications/MATLAB/MATLAB_Runtime/v93 \
+       -b ${cwd}/cat_standalone_segment.m sTRIO0001.nii
+   Preprocess (segment) the single file sTRIO0001.nii using the default CAT12 preprocessing batch.
+   SPM12 standalone version is located in $SPMROOT and Matlab Compiler Runtime in
+   /Applications/MATLAB/MATLAB_Runtime/v93.
+
+   cat_standalone.sh -s $SPMROOT -m /Applications/MATLAB/MATLAB_Runtime/v93 \
+       -b ${cwd}/cat_standalone_segment.m sTRIO000*.nii.gz \
+       -a1 " '${cat12_dir}/templates_MNI152NLin2009cAsym/TPM_Age11.5.nii' " \
+       -a2 " '${cat12_dir}/templates_MNI152NLin2009cAsym/Template_0_GS1mm.nii' "
+   Unzip and preprocess (segment) the files sTRIO0001.nii.gz using the default CAT12 preprocessing
+   batch, but use the children TPM provided with CAT12 and a 1mm Shooting template (not provided
+   with CAT12). Please note that zipped file can only be handled with this standalone batch and also
+   note the multiple quotes for parameter a1 and a2.
+
+   cat_standalone.sh -s $SPMROOT -m /Applications/MATLAB/MATLAB_Runtime/v93 \
+       -b ${cwd}/cat_standalone_segment.m sTRIO0001.nii \
+       -a "matlabbatch{1}.spm.tools.cat.estwrite.output.surface = 0;"
+   Preprocess (segment) the single file sTRIO0001.nii using the default CAT12 preprocessing batch,
+   but skip surface estimation.
+
+   -----------------------------------------------------------------------------------------------
+   Longitudinal Segmentation
+     -a1 longitudinal model (0 - developmental; 1 - plasticity/learning; 2 - aging; 3 - save models 1 and 2)
+     -a2 TPM
+   -----------------------------------------------------------------------------------------------
+   cat_standalone.sh -s $SPMROOT -m /Applications/MATLAB/MATLAB_Runtime/v93 \
+       -b ${cwd}/cat_standalone_segment_long.m sTRIO000*.nii \
+       -a1 "2"
+   Preprocess (segment) the files sTRIO000*.nii with the longitudinal pipeline optimized for
+   detecting aging/developmental effects. In order to choose the longitudinal model optimized for
+   detecting small changes due to plasticity/learning change the a1 parameter to "1".
+
+   cat_standalone.sh -s $SPMROOT -m /Applications/MATLAB/MATLAB_Runtime/v93 \
+       -b ${cwd}/cat_standalone_segment_long.m sTRIO000*.nii \
+       -a1 "1" -a2 " '${cat12_dir}/templates_MNI152NLin2009cAsym/TPM_Age11.5.nii' "
+   Preprocess (segment) the files sTRIO000*.nii with the longitudinal pipeline optimized for
+   detecting plasticity/learning effects and use the children TPM provided with CAT12.
+   Please note the multiple quotes for parameter a2.
+
+   -----------------------------------------------------------------------------------------------
+   Segmentation (Simple Mode)
+   -----------------------------------------------------------------------------------------------
+   cat_standalone.sh -s $SPMROOT -m /Applications/MATLAB/MATLAB_Runtime/v93 \
+       -b ${cwd}/cat_standalone_simple.m sTRIO0001.nii
+   Process the single file sTRIO0001.nii using the simple processing batch.
+
+   -----------------------------------------------------------------------------------------------
+   Resample & Smooth Surfaces
+     -a1 smoothing filter size surface values
+     -a2 use 32k mesh from HCP (or 164k mesh from Freesurfer)
+   -----------------------------------------------------------------------------------------------
+   cat_standalone.sh -s $SPMROOT -m /Applications/MATLAB/MATLAB_Runtime/v93 \
+       -b ${cwd}/cat_standalone_resample.m lh.thickness.sTRIO0001 \
+       -a1 "12" -a2 "1"
+   Resample and smooth the single thickness file lh.thickness.sTRIO0001 with 12mm and save the
+   resampled mesh as 32k mesh (HCP conform mesh). Only the left surface file has to be defined.
+   The right hemisphere is processed automatically.
+
+   -----------------------------------------------------------------------------------------------
+   Smoothing
+     -a1 smoothing filter size
+     -a2 prepending string for smoothed file (e.g. 's6')
+   -----------------------------------------------------------------------------------------------
+   cat_standalone.sh -s $SPMROOT -m /Applications/MATLAB/MATLAB_Runtime/v93 \
+       -b ${cwd}/cat_standalone_smooth.m sTRIO*nii \
+       -a1 "[6 6 6]" -a2 " 's6' "
+   Smooth the volume files sTRIO*nii with 6mm and prepend the string "s6" to the smoothed files.
+   Please note the multiple quotes for parameter a2.
+
+   -----------------------------------------------------------------------------------------------
+   Dicom Import
+     -a1 directory structure
+     -a2 output directory
+   -----------------------------------------------------------------------------------------------
+   cat_standalone.sh -s $SPMROOT -m /Applications/MATLAB/MATLAB_Runtime/v93 \
+       -b ${cwd}/cat_standalone_dicom2nii.m *.dcm \
+       -a1 " 'patid_date' " -a2 "{'converted'}"
+   Import DICOM files *.dcm and save converted nifti files in directory "converted" with structure
+   ./<PatientID>/<StudyDate-StudyTime>/<ProtocollName>
+   Other options for directory structure are:
+     'flat'       No directory hierarchy
+     'series'     ./<ProtocollName>
+     'patid_date' ./<PatientID>/<StudyDate-StudyTime>/<ProtocollName>
+     'patid'      ./<PatientID>/<ProtocollName>
+     'date_time'  ./<StudyDate-StudyTime>/<ProtocollName>
+   Please note the multiple quotes for parameter a1.
+
+   -----------------------------------------------------------------------------------------------
+   De-Facing
+   -----------------------------------------------------------------------------------------------
+   cat_standalone.sh -s $SPMROOT -m /Applications/MATLAB/MATLAB_Runtime/v93 \
+       -b ${cwd}/cat_standalone_deface.m sTRIO*.nii
+   Apply de-facing to sTRIO*.nii and save the files prefixed by "anon_".
+
+   -----------------------------------------------------------------------------------------------
+   Estimate and Save Quality Measures for Volumes or Surfaces
+     -a1 csv output filename
+     -a2 enable global scaling with TIV (only for volumes meaningful)
+   -----------------------------------------------------------------------------------------------
+   cat_standalone.sh -s $SPMROOT -m /Applications/MATLAB/MATLAB_Runtime/v93 \
+       -b ${cwd}/cat_standalone_get_quality.m mwp1sTRIO*nii \
+       -a1 " 'Quality_measures.csv' " -a2 "1"
+   Estimate mean z-scores using global scaling with TIV for the files mwp1sTRIO*nii and save quality
+   measures in Quality_measures.csv for external analysis. Processing of surface meshes is also
+   supported.
+   Please note the multiple quotes for parameter a1.
+
+   -----------------------------------------------------------------------------------------------
+   Estimate mean/volume inside ROI
+     -a1 output-file string
+   -----------------------------------------------------------------------------------------------
+   cat_standalone.sh -s $SPMROOT -m /Applications/MATLAB/MATLAB_Runtime/v93 \
+       -b ${cwd}/cat_standalone_get_ROI_values.m catROI_*.xml \
+       -a1 " 'ROI' "
+   Save mean volume values in mL (e.g. GM volume) or the mean surface values (e.g. thickness) for
+   all data catROI_*.xml in a csv-file. The csv-file is named "ROI_" followed by the atlas name
+   and the name of the measure (e.g. Vgm).
+   Please note the multiple quotes for parameter a1.
+
+   -----------------------------------------------------------------------------------------------
+   TFCE Statistical Estimation
+     -a1 contrast number
+     -a2 number of permutations
+   -----------------------------------------------------------------------------------------------
+   cat_standalone.sh -s $SPMROOT -m /Applications/MATLAB/MATLAB_Runtime/v93 \
+       -b ${cwd}/cat_standalone_tfce.m SPM.mat \
+       -a1 "2" -a2 "20000"
+   Call estimation of TFCE statistics for the given SPM.mat file for contrast number 2 with 20000
+   permutations.
+
+   -----------------------------------------------------------------------------------------------
+   Parallelization
+   -----------------------------------------------------------------------------------------------
+   cat_parallelize.sh -p 8 -l /tmp \
+       -c "cat_standalone.sh  -s $SPMROOT -m /Applications/MATLAB/MATLAB_Runtime/v93 -b ${cwd}/cat_standalone_segment.m" sTRIO*.nii
+   Parallelize CAT12 preprocessing by splitting all sTRIO*.nii files into 8 jobs
+   (processes) and save log file in /tmp folder.
+
+   The parameters SPMROOT and MCRROOT have to be defined (exported) to skip the use of the flags -s -m.
+
+INPUT:
+   nifti files or surface data
+
+OUTPUT:
+   processed images and optionally surfaces according to settings in cat_standalone_*.m
+
+USED FUNCTIONS:
+   cat_parallelize.sh
+   SPM12 standalone version (compiled)
+   CAT12 toolbox (compiled within SPM12 if installed)
+   MATLAB Compiler Runtime R2017b (Version 9.3)
+
+This script was written by Christian Gaser (christian.gaser@uni-jena.de).
+This is ${version}.
+
+
+Known issues:
+
+- Parallelization with cat_parallelize.sh is not implemented yet.
+- Longitudinal segmentation with cat_standalone_segment_long.m
+  is not tested yet.
+
+
+Contact information:
+
+Any problems or concerns regarding this container should be reported
+to Malgorzata Wierzba (m.wierzba@fz-juelich.de), Michael Hanke
+(m.hanke@fz-juelich.de) or Felix Hoffstaedter (f.hoffstaedter@fz-juelich.de)
+
+
+Acknowledgements:
+
+The CAT toolbox (http://www.neuro.uni-jena.de/cat) is developed by
+Christian Gaser and Robert Dahnke (Jena University Hospital,
+Departments of Psychiatry and Neurology) and is free but copyright
+software, distributed under the terms of the GNU General Public
+Licence.
+
+The SPM software (https://www.fil.ion.ucl.ac.uk/spm/) is developed by
+the Wellcome Trust Centre for Neuroimaging and is free but copyright
+software, distributed under the terms of the GNU General Public
+Licence.
+
+MATLAB Compiler Runtime
+(https://uk.mathworks.com/products/compiler/matlab-runtime.html) is
+developed by the The MathWorks, Inc. and is subject to the MATLAB
+Runtime licence.

+ 195 - 0
Enigma/cat_standalone_segment_enigma.m

@@ -0,0 +1,195 @@
+% Batch file of CAT12 segmentation for SPM12 standalone installation
+% modified parameters for ENIGMA
+%
+%_______________________________________________________________________
+% $Id: cat_standalone_segment_enigma.m 1842 2021-06-01 14:41:58Z gaser $
+
+% first undefined data field, that will be dynamically replaced by cat_standalone.sh
+matlabbatch{1}.spm.tools.cat.estwrite.data = '<UNDEFINED>';
+
+% Entry for choosing TPM
+% Remove comments and edit entry if you would like to change the parameter.
+% Otherwise the default value from cat_defaults.m is used.
+% Or use 1st parameter field, that will be dynamically replaced by cat_standalone.sh
+%matlabbatch{1}.spm.tools.cat.estwrite.opts.tpm = '<UNDEFINED>';
+
+% Entry for choosing shooting template
+% Remove comments and edit entry if you would like to change the parameter.
+% Otherwise the default value from cat_defaults.m is used.
+% Or use 2nd parameter field, that will be dynamically replaced by cat_standalone.sh
+%matlabbatch{1}.spm.tools.cat.estwrite.extopts.registration.regmethod.shooting.shootingtpm = '<UNDEFINED>';
+
+% Strength of Shooting registration: 0 - Dartel, eps (fast), 0.5 (default) to 1 (accurate) optimized Shooting, 4 - default Shooting; default 0.5
+%matlabbatch{1}.spm.tools.cat.estwrite.extopts.registration.regmethod.shooting.regstr = 0.5;
+
+% voxel size for normalized data (EXPERIMENTAL: inf - use Tempate values)
+matlabbatch{1}.spm.tools.cat.estwrite.extopts.registration.vox = 1.5;
+
+% additional bounding box
+matlabbatch{1}.spm.tools.cat.estwrite.extopts.registration.bb = 12;
+
+% Affine regularisation (SPM12 default = mni) - '';'mni';'eastern';'subj';'none';'rigid'
+matlabbatch{1}.spm.tools.cat.estwrite.opts.affreg = 'mni';
+
+% Strength of the bias correction that controls the biasreg and biasfwhm parameter (CAT only!)
+% 0 - use SPM parameter; eps - ultralight, 0.25 - light, 0.5 - medium, 0.75 - strong, and 1 - heavy corrections
+% job.opts.biasreg	= min(  10 , max(  0 , 10^-(job.opts.biasstr*2 + 2) ));
+% job.opts.biasfwhm	= min( inf , max( 30 , 30 + 60*job.opts.biasstr ));
+matlabbatch{1}.spm.tools.cat.estwrite.opts.biasstr = 0.5;
+
+% Affine PreProcessing (APP) with rough bias correction and brain extraction for special anatomies (nonhuman/neonates)
+% 0 - none; 1070 - default; [1 - light; 2 - full; 1144 - update of 1070, 5 - animal (no affreg)]
+matlabbatch{1}.spm.tools.cat.estwrite.extopts.segmentation.APP = 1070;
+
+% Strength of the local adaptation: 0 to 1; default 0.5
+matlabbatch{1}.spm.tools.cat.estwrite.extopts.segmentation.LASstr = 0.5;
+
+% Strength of the noise correction: 0 to 1; 0 - no filter, -Inf - auto, 1 - full, 2 - ISARNLM (else SANLM), default -Inf
+matlabbatch{1}.spm.tools.cat.estwrite.extopts.segmentation.NCstr = -Inf;
+
+% Strength of skull-stripping: 0 - SPM approach; eps to 1  - gcut; 2 - new APRG approach; -1 - no skull-stripping (already skull-stripped); default = 2
+matlabbatch{1}.spm.tools.cat.estwrite.extopts.segmentation.gcutstr = 2;
+
+% Strength of the cleanup process: 0 to 1; default 0.5
+matlabbatch{1}.spm.tools.cat.estwrite.extopts.segmentation.cleanupstr = 0.5;
+
+% resolution handling: 'native','fixed','best', 'optimal'
+matlabbatch{1}.spm.tools.cat.estwrite.extopts.segmentation.restypes.optimal = [1 0.3];
+
+% use center-of-mass approach for estimating origin
+matlabbatch{1}.spm.tools.cat.estwrite.extopts.segmentation.setCOM = 1;
+
+% modify affine scaling
+matlabbatch{1}.spm.tools.cat.estwrite.extopts.segmentation.affmod = 0;
+
+% use k-means AMAP approach or SPM segmentation for initial segmentation
+matlabbatch{1}.spm.tools.cat.estwrite.extopts.segmentation.spm_kamap = 0;
+
+% Correction of WM hyperintensities: 0 - no correction, 1 - only for Dartel/Shooting
+% 2 - also correct segmentation (to WM), 3 - handle as separate class; default 1
+matlabbatch{1}.spm.tools.cat.estwrite.extopts.segmentation.WMHC = 2;
+
+% Stroke lesion correction (SLC): 0 - no correction, 1 - handling of manual lesion that have to be set to zero!
+% 2 - automatic lesion detection (in development)
+matlabbatch{1}.spm.tools.cat.estwrite.extopts.segmentation.SLC = 0;
+
+% surface options
+matlabbatch{1}.spm.tools.cat.estwrite.extopts.surface.pbtres = 0.5;
+matlabbatch{1}.spm.tools.cat.estwrite.extopts.surface.pbtmethod = 'pbt2x';
+matlabbatch{1}.spm.tools.cat.estwrite.extopts.surface.reduce_mesh = 1;
+matlabbatch{1}.spm.tools.cat.estwrite.extopts.surface.scale_cortex = 0.7;
+matlabbatch{1}.spm.tools.cat.estwrite.extopts.surface.add_parahipp = 0.1;
+matlabbatch{1}.spm.tools.cat.estwrite.extopts.surface.close_parahipp = 0;
+matlabbatch{1}.spm.tools.cat.estwrite.extopts.surface.SRP = 22;
+
+% set this to 1 for skipping preprocessing if already processed data exist
+matlabbatch{1}.spm.tools.cat.estwrite.extopts.admin.lazy = 0;
+
+% catch errors: 0 - stop with error (default); 1 - catch preprocessing errors (requires MATLAB 2008 or higher);
+matlabbatch{1}.spm.tools.cat.estwrite.extopts.admin.ignoreErrors = 1;
+
+% verbose output: 1 - default; 2 - details; 3 - write debugging files
+matlabbatch{1}.spm.tools.cat.estwrite.extopts.admin.verb = 2;
+
+% display and print out pdf-file of results: 0 - off, 2 - volume only, 2 - volume and surface (default)
+matlabbatch{1}.spm.tools.cat.estwrite.extopts.admin.print = 2;
+
+% surface and thickness creation:   0 - no (default), 1 - lh+rh, 2 - lh+rh+cerebellum,
+% 3 - lh, 4 - rh, 5 - lh+rh (fast, no registration, only for quick quality check and not for analysis),
+% 6 - lh+rh+cerebellum (fast, no registration, only for quick quality check and not for analysis)
+% 9 - thickness only (for ROI analysis, experimental!)
+% +10 to estimate WM and CSF width/depth/thickness (experimental!)
+matlabbatch{1}.spm.tools.cat.estwrite.output.surface = 0;
+
+% BIDS output
+matlabbatch{1}.spm.tools.cat.estwrite.output.BIDS.BIDSno = 1;
+
+% define here volume atlases
+matlabbatch{1}.spm.tools.cat.estwrite.output.ROImenu.atlases.neuromorphometrics = 0;
+matlabbatch{1}.spm.tools.cat.estwrite.output.ROImenu.atlases.lpba40 = 0;
+matlabbatch{1}.spm.tools.cat.estwrite.output.ROImenu.atlases.cobra = 0;
+matlabbatch{1}.spm.tools.cat.estwrite.output.ROImenu.atlases.hammers = 0;
+matlabbatch{1}.spm.tools.cat.estwrite.output.ROImenu.atlases.ibsr = 0;
+matlabbatch{1}.spm.tools.cat.estwrite.output.ROImenu.atlases.aal3 = 0;
+matlabbatch{1}.spm.tools.cat.estwrite.output.ROImenu.atlases.mori = 0;
+matlabbatch{1}.spm.tools.cat.estwrite.output.ROImenu.atlases.thalamus = 0;
+matlabbatch{1}.spm.tools.cat.estwrite.output.ROImenu.atlases.anatomy3 = 0;
+matlabbatch{1}.spm.tools.cat.estwrite.output.ROImenu.atlases.julichbrain = 0;
+matlabbatch{1}.spm.tools.cat.estwrite.output.ROImenu.atlases.Schaefer2018_100Parcels_17Networks_order = 0;
+matlabbatch{1}.spm.tools.cat.estwrite.output.ROImenu.atlases.Schaefer2018_200Parcels_17Networks_order = 0;
+matlabbatch{1}.spm.tools.cat.estwrite.output.ROImenu.atlases.Schaefer2018_400Parcels_17Networks_order = 0;
+matlabbatch{1}.spm.tools.cat.estwrite.output.ROImenu.atlases.Schaefer2018_600Parcels_17Networks_order = 0;
+matlabbatch{1}.spm.tools.cat.estwrite.output.ROImenu.atlases.ownatlas = {''};
+
+% Writing options (see cat_defaults for the description of parameters)
+%   native    0/1     (none/yes)
+%   warped    0/1     (none/yes)
+%   mod       0/1/2/3 (none/affine+nonlinear/nonlinear only/both)
+%   dartel    0/1/2/3 (none/rigid/affine/both)
+
+% GM/WM/CSF/WMH
+matlabbatch{1}.spm.tools.cat.estwrite.output.GM.native = 1;
+matlabbatch{1}.spm.tools.cat.estwrite.output.GM.warped = 1;
+matlabbatch{1}.spm.tools.cat.estwrite.output.GM.mod = 1;
+matlabbatch{1}.spm.tools.cat.estwrite.output.GM.dartel = 2;
+matlabbatch{1}.spm.tools.cat.estwrite.output.WM.native = 1;
+matlabbatch{1}.spm.tools.cat.estwrite.output.WM.warped = 0;
+matlabbatch{1}.spm.tools.cat.estwrite.output.WM.mod = 0;
+matlabbatch{1}.spm.tools.cat.estwrite.output.WM.dartel = 2;
+matlabbatch{1}.spm.tools.cat.estwrite.output.CSF.native = 0;
+matlabbatch{1}.spm.tools.cat.estwrite.output.CSF.warped = 0;
+matlabbatch{1}.spm.tools.cat.estwrite.output.CSF.mod = 0;
+matlabbatch{1}.spm.tools.cat.estwrite.output.CSF.dartel = 0;
+matlabbatch{1}.spm.tools.cat.estwrite.output.WMH.native = 0;
+matlabbatch{1}.spm.tools.cat.estwrite.output.WMH.warped = 0;
+matlabbatch{1}.spm.tools.cat.estwrite.output.WMH.mod = 0;
+matlabbatch{1}.spm.tools.cat.estwrite.output.WMH.dartel = 0;
+
+% stroke lesion tissue maps (only for opt.extopts.SLC>0) - in development
+matlabbatch{1}.spm.tools.cat.estwrite.output.SL.native = 0;
+matlabbatch{1}.spm.tools.cat.estwrite.output.SL.warped = 0;
+matlabbatch{1}.spm.tools.cat.estwrite.output.SL.mod = 0;
+matlabbatch{1}.spm.tools.cat.estwrite.output.SL.dartel = 0;
+
+% Tissue classes 4-6 to create own TPMs
+matlabbatch{1}.spm.tools.cat.estwrite.output.TPMC.native = 0;
+matlabbatch{1}.spm.tools.cat.estwrite.output.TPMC.warped = 0;
+matlabbatch{1}.spm.tools.cat.estwrite.output.TPMC.mod = 0;
+matlabbatch{1}.spm.tools.cat.estwrite.output.TPMC.dartel = 0;
+
+% atlas maps (for evaluation)
+matlabbatch{1}.spm.tools.cat.estwrite.output.atlas.native = 0;
+
+% label
+% background=0, CSF=1, GM=2, WM=3, WMH=4 (if opt.extopts.WMHC==3), SL=1.5 (if opt.extopts.SLC>0)
+matlabbatch{1}.spm.tools.cat.estwrite.output.label.native = 1;
+matlabbatch{1}.spm.tools.cat.estwrite.output.label.warped = 0;
+matlabbatch{1}.spm.tools.cat.estwrite.output.label.dartel = 0;
+
+% bias and noise corrected, global intensity normalized
+matlabbatch{1}.spm.tools.cat.estwrite.output.bias.native = 0;
+matlabbatch{1}.spm.tools.cat.estwrite.output.bias.warped = 0;
+matlabbatch{1}.spm.tools.cat.estwrite.output.bias.dartel = 0;
+
+% bias and noise corrected, (locally - if LAS>0) intensity normalized
+matlabbatch{1}.spm.tools.cat.estwrite.output.las.native = 0;
+matlabbatch{1}.spm.tools.cat.estwrite.output.las.warped = 0;
+matlabbatch{1}.spm.tools.cat.estwrite.output.las.dartel = 0;
+
+% jacobian determinant 0/1 (none/yes)
+matlabbatch{1}.spm.tools.cat.estwrite.output.jacobianwarped = 0;
+
+% deformations, order is [forward inverse]
+matlabbatch{1}.spm.tools.cat.estwrite.output.warps = [0 0];
+
+% registration matrix
+matlabbatch{1}.spm.tools.cat.estwrite.output.rmat = 1;
+
+% deface native intensity normalized images in native space
+matlabbatch{2}.spm.util.deface.images(1) = cfg_dep('CAT12: Segmentation: Native Bias Corr. Image', substruct('.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('()',{1}, '.','biascorr', '()',{':'}));
+matlabbatch{2}.spm.util.deface.images(2) = cfg_dep('CAT12: Segmentation: Native LAS Bias Corr. Image', substruct('.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('()',{1}, '.','ibiascorr', '()',{':'}));
+
+% and remove images that are not defaced
+matlabbatch{3}.cfg_basicio.file_dir.file_ops.file_move.files(1) = cfg_dep('CAT12: Segmentation: Native Bias Corr. Image', substruct('.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('()',{1}, '.','biascorr', '()',{':'}));
+matlabbatch{3}.cfg_basicio.file_dir.file_ops.file_move.files(2) = cfg_dep('CAT12: Segmentation: Native LAS Bias Corr. Image', substruct('.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('()',{1}, '.','ibiascorr', '()',{':'}));
+matlabbatch{3}.cfg_basicio.file_dir.file_ops.file_move.action.delete = false;

+ 93 - 0
Enigma/enigma_stacking_pred.def

@@ -0,0 +1,93 @@
+Bootstrap: docker                                                                                                                                                                                              
+FROM: python:3.11.6-slim-bookworm                                                    
+Stage: base   
+
+%setup
+
+#    touch ${SINGULARITY_ROOTFS}/data
+
+%files
+    save_feat.py /codes/
+    predict_age_stacking.py /codes/
+    analysis.sh /codes/
+     
+%environment
+#    
+
+%post
+    pip install --upgrade pip
+    pip install "scikit-learn==1.3.2" \
+                "nibabel==4.0.2" \
+                "nilearn==0.9.0" \
+                "numpy==1.25.2" \
+                "pandas==1.5.3" \
+                "joblib==1.4.2" \
+                "julearn==0.3.1" 
+    mkdir /model/
+    mkdir /data/
+    mkdir /extras
+    # mkdir /codes
+    # cp save_feat.py /codes/
+    # cp predict_age_stacking.py /codes/
+    # cp analysis.sh /codes/
+    chmod +x /codes/* 
+
+    apt-get -y update && apt-get install -y unzip wget
+    apt-get -y --quiet --no-install-recommends install build-essential curl ca-certificates
+    curl https://gin.g-node.org/antogeo/stacking_model/raw/68c8723a15badbac0c26bf3d40aa9ba31264ea4a/extras/mask_4mm_binarized.nii --output /extras/mask_4mm_binarized.nii
+    curl https://gin.g-node.org/antogeo/stacking_model/raw/68c8723a15badbac0c26bf3d40aa9ba31264ea4a/extras/mask_8mm_binarized.nii --output /extras/mask_8mm_binarized.nii
+    curl https://gin.g-node.org/antogeo/stacking_model/raw/68c8723a15badbac0c26bf3d40aa9ba31264ea4a/extras/brainmask_12.8.nii --output /extras/brainmask_12.8.nii
+
+    wget https://gin.g-node.org/antogeo/stacking_model/raw/master/stacking_enigmaModel%281%29.pkl -O /model/stacking_enigmaModel.pkl
+    chmod +rw /extras/*
+
+    # Octave 
+    # add-apt-repository 'http://ftp.debian.org/debian/ stable main contrib non-free'
+    DEBIAN_FRONTEND=noninteractive apt-get --yes --quiet install octave liboctave-dev
+    mkdir /opt/spm12                                                             
+    curl -fsSL --retry 5 https://github.com/spm/spm12/archive/r7771.tar.gz | tar -xzC /opt/spm12 --strip-components 1
+    curl -fsSL --retry 5 https://raw.githubusercontent.com/spm/spm-octave/main/spm12_r7771.patch | patch -p0
+    make -C /opt/spm12/src PLATFORM=octave distclean                             
+    make -C /opt/spm12/src PLATFORM=octave                                       
+    make -C /opt/spm12/src PLATFORM=octave install                               
+    ln -s /opt/spm12/bin/spm12-octave /usr/local/bin/spm12
+    rm -f /opt/spm12/src/*.{mex,o,a}                                             
+    apt-get --yes remove build-essential curl liboctave-dev                      
+    apt-get --yes autoremove                                                     
+    apt-get --yes clean
+
+%environment                                                                     
+    export SPM_HOME=/opt/spm12
+
+%runscript
+    # # cp $1 /data
+    # echo "Starting age prediction for following subject/subjects"
+    # echo "predict subject's : $1"
+    # exec echo "$1"
+    bash /codes/analysis.sh "$@"
+
+%startscript
+    
+
+%test
+    grep -q NAME=\"Ubuntu\" /etc/os-release
+    if [ "$(ls -A /data/)" ]; then
+        echo "No data provided"
+    else
+        echo "Data found in data"
+    fi
+
+%labels
+    Author: Antonopoulos Georgios https://github.com/antogeo
+    Version v0.0.1
+
+%help
+    This def file builds a Singularity container with a brain-age prediction model based on
+    "BrainAGE: Revisited and reframed machine learning workflow", Polona Kalc et al.
+    It gets GMV and WMV nifti as inputs and predicts the age of the subject.
+    You need to run the following command prior to building the container:
+    > chmod -R 777 /tmp                                                                                                                                                                                          255 !
+
+    At first, it extracts the features by performing resampling (4mm and 8mm) and smoothing
+    (4mm and 8mm) to the image. Four different combinations of resampling and smoothing of 
+    the two tissue images result in 8 different groups of features.