|
@@ -0,0 +1,318 @@
|
|
|
+#!/bin/bash
|
|
|
+#$ -N halfpipe
|
|
|
+#$ -q compute7.q
|
|
|
+#$ -j y
|
|
|
+#$ -o halfpipe.log.txt
|
|
|
+#$ -cwd
|
|
|
+#$ -pe smp 2 -binding linear
|
|
|
+#$ -l h_rt=48:0:0
|
|
|
+#$ -l virtual_free=20480M
|
|
|
+
|
|
|
+#$ -t 101-10000
|
|
|
+
|
|
|
+set -e
|
|
|
+set -x
|
|
|
+
|
|
|
+base_directory=/ifs/loni/faculty/njahansh/collaborators/lea/ukbiobank
|
|
|
+clinical_directory=${base_directory}/clinical_data
|
|
|
+
|
|
|
+dataset_directory=$(mktemp -d)
|
|
|
+bids_directory=$(mktemp -d)
|
|
|
+synthseg_directory=$(mktemp -d)
|
|
|
+halfpipe_directory=$(mktemp -d)
|
|
|
+
|
|
|
+synthseg_container=${base_directory}/synthseg.sif
|
|
|
+halfpipe_container=${base_directory}/halfpipe-latest-240307.sif
|
|
|
+
|
|
|
+read -r -a files < <(sed -n "${SGE_TASK_ID}p" ${base_directory}/tasks.txt)
|
|
|
+
|
|
|
+for file in "${files[@]}"; do
|
|
|
+ ln -s "${file}" "${dataset_directory}"
|
|
|
+done
|
|
|
+
|
|
|
+mamba run --name clinica \
|
|
|
+ clinica convert ukb-to-bids \
|
|
|
+ "${dataset_directory}" \
|
|
|
+ "${clinical_directory}" \
|
|
|
+ "${bids_directory}"
|
|
|
+
|
|
|
+t1w_file=$(find "${bids_directory}" -name "*_T1w.nii.gz" -print -quit)
|
|
|
+mv -v "${t1w_file}" "${synthseg_directory}/t1w.nii.gz"
|
|
|
+
|
|
|
+singularity run \
|
|
|
+ --bind "${synthseg_directory}" \
|
|
|
+ ${synthseg_container} \
|
|
|
+ --i "${synthseg_directory}/t1w.nii.gz" \
|
|
|
+ --o "${synthseg_directory}/synthseg.nii.gz" \
|
|
|
+ --robust \
|
|
|
+ --cpu --threads 1
|
|
|
+
|
|
|
+singularity exec \
|
|
|
+ --bind "${synthseg_directory}" \
|
|
|
+ ${halfpipe_container} \
|
|
|
+ antsApplyTransforms \
|
|
|
+ --dimensionality 3 \
|
|
|
+ --input "${synthseg_directory}/synthseg.nii.gz" \
|
|
|
+ --reference-image "${synthseg_directory}/t1w.nii.gz" \
|
|
|
+ --output "${synthseg_directory}/synthseg_in_t1w_space.nii.gz" \
|
|
|
+ --interpolation MultiLabel \
|
|
|
+ --verbose
|
|
|
+
|
|
|
+singularity exec \
|
|
|
+ --bind "${base_directory}" \
|
|
|
+ --bind "${synthseg_directory}" \
|
|
|
+ ${halfpipe_container} \
|
|
|
+ ${base_directory}/apply_mask.py \
|
|
|
+ "${synthseg_directory}/t1w.nii.gz" \
|
|
|
+ "${synthseg_directory}/synthseg_in_t1w_space.nii.gz" \
|
|
|
+ "${t1w_file}"
|
|
|
+
|
|
|
+cat <<EOF >"${halfpipe_directory}/spec.json"
|
|
|
+{
|
|
|
+ "halfpipe_version": "1.2.2.post1.dev535+gc31d205",
|
|
|
+ "schema_version": "3.0",
|
|
|
+ "timestamp": "2023-08-08_16-01",
|
|
|
+ "global_settings": {
|
|
|
+ "dummy_scans": 0,
|
|
|
+ "slice_timing": true,
|
|
|
+ "use_bbr": null,
|
|
|
+ "skull_strip_algorithm": "none",
|
|
|
+ "run_mriqc": false,
|
|
|
+ "run_fmriprep": true,
|
|
|
+ "run_halfpipe": true,
|
|
|
+ "fd_thres": 0.5,
|
|
|
+ "anat_only": false,
|
|
|
+ "write_graph": false,
|
|
|
+ "hires": false,
|
|
|
+ "run_reconall": false,
|
|
|
+ "t2s_coreg": false,
|
|
|
+ "medial_surface_nan": false,
|
|
|
+ "bold2t1w_dof": 9,
|
|
|
+ "fmap_bspline": true,
|
|
|
+ "force_syn": false,
|
|
|
+ "longitudinal": false,
|
|
|
+ "regressors_all_comps": false,
|
|
|
+ "regressors_dvars_th": 1.5,
|
|
|
+ "regressors_fd_th": 0.5,
|
|
|
+ "skull_strip_fixed_seed": false,
|
|
|
+ "skull_strip_template": "OASIS30ANTs",
|
|
|
+ "aroma_err_on_warn": false,
|
|
|
+ "aroma_melodic_dim": -200,
|
|
|
+ "sloppy": false
|
|
|
+ },
|
|
|
+ "files": [
|
|
|
+ {
|
|
|
+ "metadata": {},
|
|
|
+ "datatype": "bids",
|
|
|
+ "path": "${bids_directory}"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "suffix": "events",
|
|
|
+ "path": "${bids_directory}/task-{task}_events.tsv",
|
|
|
+ "extension": ".tsv",
|
|
|
+ "datatype": "func"
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ "settings": [
|
|
|
+ {
|
|
|
+ "ica_aroma": true,
|
|
|
+ "smoothing": {
|
|
|
+ "fwhm": 6.0
|
|
|
+ },
|
|
|
+ "grand_mean_scaling": {
|
|
|
+ "mean": 10000.0
|
|
|
+ },
|
|
|
+ "bandpass_filter": {
|
|
|
+ "hp_width": 125.0,
|
|
|
+ "lp_width": null,
|
|
|
+ "type": "gaussian"
|
|
|
+ },
|
|
|
+ "name": "icaAromaSetting",
|
|
|
+ "filters": [
|
|
|
+ {
|
|
|
+ "type": "tag",
|
|
|
+ "action": "include",
|
|
|
+ "values": [
|
|
|
+ "facesshapesemotion"
|
|
|
+ ],
|
|
|
+ "entity": "task"
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ "output_image": false
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "ica_aroma": false,
|
|
|
+ "smoothing": {
|
|
|
+ "fwhm": 6.0
|
|
|
+ },
|
|
|
+ "grand_mean_scaling": {
|
|
|
+ "mean": 10000.0
|
|
|
+ },
|
|
|
+ "bandpass_filter": {
|
|
|
+ "hp_width": 125.0,
|
|
|
+ "lp_width": null,
|
|
|
+ "type": "gaussian"
|
|
|
+ },
|
|
|
+ "confounds_removal": [
|
|
|
+ "(trans|rot)_[xyz]"
|
|
|
+ ],
|
|
|
+ "name": "motionParametersSetting",
|
|
|
+ "filters": [
|
|
|
+ {
|
|
|
+ "type": "tag",
|
|
|
+ "action": "include",
|
|
|
+ "values": [
|
|
|
+ "facesshapesemotion"
|
|
|
+ ],
|
|
|
+ "entity": "task"
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ "output_image": false
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "ica_aroma": false,
|
|
|
+ "smoothing": {
|
|
|
+ "fwhm": 6.0
|
|
|
+ },
|
|
|
+ "grand_mean_scaling": {
|
|
|
+ "mean": 10000.0
|
|
|
+ },
|
|
|
+ "bandpass_filter": {
|
|
|
+ "hp_width": 125.0,
|
|
|
+ "lp_width": null,
|
|
|
+ "type": "gaussian"
|
|
|
+ },
|
|
|
+ "name": "noConfoundsSetting",
|
|
|
+ "filters": [
|
|
|
+ {
|
|
|
+ "type": "tag",
|
|
|
+ "action": "include",
|
|
|
+ "values": [
|
|
|
+ "facesshapesemotion"
|
|
|
+ ],
|
|
|
+ "entity": "task"
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ "output_image": false
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ "features": [
|
|
|
+ {
|
|
|
+ "name": "icaAroma",
|
|
|
+ "setting": "icaAromaSetting",
|
|
|
+ "contrasts": [
|
|
|
+ {
|
|
|
+ "type": "t",
|
|
|
+ "name": "faceNegVsControl",
|
|
|
+ "values": {
|
|
|
+ "Face": 1.0,
|
|
|
+ "Shape": -1.0
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ "hrf": "dgamma",
|
|
|
+ "conditions": [
|
|
|
+ "Face",
|
|
|
+ "Shape"
|
|
|
+ ],
|
|
|
+ "type": "task_based",
|
|
|
+ "high_pass_filter_cutoff": 125.0
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "name": "motionParameters",
|
|
|
+ "setting": "motionParametersSetting",
|
|
|
+ "contrasts": [
|
|
|
+ {
|
|
|
+ "type": "t",
|
|
|
+ "name": "faceNegVsControl",
|
|
|
+ "values": {
|
|
|
+ "Face": 1.0,
|
|
|
+ "Shape": -1.0
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ "hrf": "dgamma",
|
|
|
+ "conditions": [
|
|
|
+ "Face",
|
|
|
+ "Shape"
|
|
|
+ ],
|
|
|
+ "type": "task_based",
|
|
|
+ "high_pass_filter_cutoff": 125.0
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "name": "noConfounds",
|
|
|
+ "setting": "noConfoundsSetting",
|
|
|
+ "contrasts": [
|
|
|
+ {
|
|
|
+ "type": "t",
|
|
|
+ "name": "faceNegVsControl",
|
|
|
+ "values": {
|
|
|
+ "Face": 1.0,
|
|
|
+ "Shape": -1.0
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ "hrf": "dgamma",
|
|
|
+ "conditions": [
|
|
|
+ "Face",
|
|
|
+ "Shape"
|
|
|
+ ],
|
|
|
+ "type": "task_based",
|
|
|
+ "high_pass_filter_cutoff": 125.0
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ "models": []
|
|
|
+}
|
|
|
+EOF
|
|
|
+
|
|
|
+singularity run \
|
|
|
+ --contain \
|
|
|
+ --cleanenv \
|
|
|
+ --bind /tmp \
|
|
|
+ ${halfpipe_container} \
|
|
|
+ --workdir "${halfpipe_directory}" \
|
|
|
+ --skip-spec-ui \
|
|
|
+ --nipype-n-procs "$(nproc)" \
|
|
|
+ --keep none
|
|
|
+
|
|
|
+derivatives_directory=${halfpipe_directory}/derivatives
|
|
|
+mask_file=$(find "${derivatives_directory}" -name "*_desc-brain_mask.nii.gz" \( -not -name "*space*" \) -print -quit)
|
|
|
+report_file=$(find "${halfpipe_directory}/reports" -name "*_skull_strip_report*svg" -print -quit)
|
|
|
+
|
|
|
+singularity exec \
|
|
|
+ --bind /tmp \
|
|
|
+ ${halfpipe_container} \
|
|
|
+ python ${base_directory}/plot_skull_strip.py \
|
|
|
+ --mask-file "${mask_file}" \
|
|
|
+ --background-file "${synthseg_directory}/t1w.nii.gz" \
|
|
|
+ --output-file "${report_file}"
|
|
|
+
|
|
|
+subject_id=$(basename "$(find "${derivatives_directory}"/fmriprep/* -maxdepth 0 -print -quit)")
|
|
|
+fmriprep_directory=$(find "${derivatives_directory}"/fmriprep/"${subject_id}"/ses-* -maxdepth 0 -print -quit)
|
|
|
+
|
|
|
+transform_suffix="_from-T1w_to-MNI152NLin2009cAsym_mode-image_xfm.h5"
|
|
|
+transform_file=$(find "${derivatives_directory}" -name "*${transform_suffix}" -print -quit)
|
|
|
+jacobian_file=$(dirname "${transform_file}")/$(basename "${transform_file}" ${transform_suffix})_jacobian.nii.gz
|
|
|
+singularity exec \
|
|
|
+ --cleanenv \
|
|
|
+ --bind /tmp \
|
|
|
+ ${halfpipe_container} \
|
|
|
+ python ${base_directory}/calculate_jacobian.py \
|
|
|
+ --transform-file "${transform_file}" \
|
|
|
+ --output-file "${jacobian_file}"
|
|
|
+
|
|
|
+mapfile -t anat_files < <(find "${fmriprep_directory}"/anat \( -name "*.nii.gz" -o -name "*.json" \) -not -name "*_desc-preproc_T1w.nii.gz" -print)
|
|
|
+
|
|
|
+tar_file="${base_directory}/halfpipe/${subject_id}.tar"
|
|
|
+tar --verbose \
|
|
|
+ --create \
|
|
|
+ --dereference \
|
|
|
+ --file="${tar_file}" \
|
|
|
+ "${halfpipe_directory}"/reports/"${subject_id}" \
|
|
|
+ "${derivatives_directory}"/halfpipe/"${subject_id}" \
|
|
|
+ "${fmriprep_directory}"/func \
|
|
|
+ "${anat_files[@]}"
|
|
|
+zstd --ultra --threads=0 -22 "${tar_file}"
|
|
|
+
|
|
|
+rm "${tar_file}"
|
|
|
+rm -rf "${dataset_directory}" "${bids_directory}" "${halfpipe_directory}"
|