-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmribrew_dwi_tbss.sh
78 lines (61 loc) · 2.09 KB
/
mribrew_dwi_tbss.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
# Set FSL environment
. ${FSLDIR}/etc/fslconf/fsl.sh
# Directory structure
BASE_DIR="data/proc/dwi_proc"
OUTDIR="data/res/tbss"
mkdir -p ${OUTDIR}
# Find all subject directories
for subject_dir in ${BASE_DIR}/*/; do
subject=$(basename ${subject_dir})
date_dir=$(ls -d ${subject_dir}/*/ | head -n 1)
# Define input paths for each subject
DWI_PATH="${date_dir}/dwi/eddy_corrected.nii.gz"
MASK_PATH="${date_dir}/dwi/dwi_mask.nii.gz"
BVEC_PATH="${date_dir}/dwi/gradChecked.bvecs"
BVAL_PATH="${date_dir}/dwi/gradChecked.bvals"
# Check if all required files exist
if [ ! -f ${DWI_PATH} ] || [ ! -f ${MASK_PATH} ] || [ ! -f ${BVEC_PATH} ] || [ ! -f ${BVAL_PATH} ]; then
echo "Warning: Missing required files for subject ${subject}"
continue
fi
# Fit diffusion tensor
echo "Processing subject: ${subject}"
dtifit --data=${DWI_PATH} \
--mask=${MASK_PATH} \
--bvecs=${BVEC_PATH} \
--bvals=${BVAL_PATH} \
--out=${OUTDIR}/${subject}
# Remove all files except FA
rm -f ${OUTDIR}/${subject}_L1.* \
${OUTDIR}/${subject}_L2.* \
${OUTDIR}/${subject}_L3.* \
${OUTDIR}/${subject}_MD.* \
${OUTDIR}/${subject}_MO.* \
${OUTDIR}/${subject}_S0.* \
${OUTDIR}/${subject}_V1.* \
${OUTDIR}/${subject}_V2.* \
${OUTDIR}/${subject}_V3.*
done
cd ${OUTDIR}
# ls -1 FA/*_FA.nii.gz
# Prepare FA images
echo "Running tbss_1_preproc..."
tbss_1_preproc *_FA.nii.gz
# Create FA target and skeleton
echo "Running tbss_2_reg..."
tbss_2_reg -T
# Project all FA images onto mean FA skeleton
echo "Running tbss_3_postreg..."
tbss_3_postreg -S
# Create mean FA mask and apply threshold
tbss_4_prestats 0.3
cd stats
# Run statistics (modify design.mat and design.con as needed)
randomise -i all_FA_skeletonised -o tbss \
-m mean_FA_skeleton_mask \
-d design.mat -t design.con \
-n 5000 --T2
tbss_fill tbss_clustere_corrp_tstat1 0.25 \
mean_FA tbss_clustere_corrp_tstat1_filled
echo "TBSS analysis completed!"