-
Notifications
You must be signed in to change notification settings - Fork 3
/
1_main_iter.sh
156 lines (116 loc) · 5.79 KB
/
1_main_iter.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
bids_base='/project/4180000.41'
bids_original=$bids_base'/bids'
bids_template=$bids_base'/tmp/DI1_mask/anat_template'
bids_preprocessing=$bids_base'/tmp/DI1_mask/preprocessing'
script_dir='/home/traaffneu/joagra/code/MouseMRIPrep/prep'
template='/project/4180000.41/sigma_wistar_rat_brain_templatesandatlases_version_2.0/SIGMA_Rat_Anatomical_Imaging/SIGMA_Rat_Anatomical_InVivo_Template/anatomy/SIGMA_InVivo_Anatomical_Brain_template.nii.gz'
template_brain='/project/4180000.41/sigma_wistar_rat_brain_templatesandatlases_version_2.0/SIGMA_Rat_Anatomical_Imaging/SIGMA_Rat_Anatomical_InVivo_Template/anatomy/SIGMA_InVivo_Anatomical_Brain_masked.nii.gz'
template_mask='/project/4180000.41/sigma_wistar_rat_brain_templatesandatlases_version_2.0/SIGMA_Rat_Anatomical_Imaging/SIGMA_Rat_Anatomical_InVivo_Template/anatomy/SIGMA_InVivo_Anatomical_Brain_mask.nii.gz'
template_atlas='/project/4180000.41/sigma_wistar_rat_brain_templatesandatlases_version_2.0/SIGMA_Rat_Brain_Atlases/SIGMA_Anatomical_Atlas/InVivo_Atlas/SIGMA_InVivo_Anatomical_Brain_Atlas.nii.gz'
template_wm='/project/4180000.41/sigma_wistar_rat_brain_templatesandatlases_version_2.0/SIGMA_Rat_Anatomical_Imaging/SIGMA_Rat_Anatomical_InVivo_Template/anatomy/SIGMA_InVivo_Anatomical_Brain_wm_bin.nii.gz'
template_csf='/project/4180000.41/sigma_wistar_rat_brain_templatesandatlases_version_2.0/SIGMA_Rat_Anatomical_Imaging/SIGMA_Rat_Anatomical_InVivo_Template/anatomy/SIGMA_InVivo_Anatomical_Brain_csf_bin.nii.gz'
roi_s1bf_l='/home/traaffneu/joagra/code/MultiRat/assets/nifti/roi/S1bf_l.nii.gz'
roi_s1bf_r='/home/traaffneu/joagra/code/MultiRat/assets/nifti/roi/S1bf_r.nii.gz'
roi_aca_l='/home/traaffneu/joagra/code/MultiRat/assets/nifti/roi/ACA_l.nii.gz'
#Anat parameters
anat_script='anat_norm.sh'
anat_base='*_T2w.nii.gz'
anat_base_mask='*_T2w_mask.nii.gz'
anat2std_lin='anat/reg/anat2std0GenericAffine.mat'
anat2std_nlin='anat/reg/anat2std1Warp.nii.gz'
anat2std_nlin_inv='anat/reg/anat2std1InverseWarp.nii.gz'
anat2temp='reg/anat2std.nii.gz'
anat2temp_inv='reg/std2anat_inv.nii.gz'
#FMRI paramters
func_script='func_norm.sh'
func_script2='func_rs.sh'
func_base='*_task-rest_bold.nii.gz'
func_base_mask='*_task-rest_bold_mask.nii.gz'
TR=1
FWHM=0.45
fbot=0.01
ftop=0.1
cd $bids_original
ls -d */ | while read subject
do
cd $subject
echo "now doing subject "$subject
outdir=$bids_preprocessing'/'$subject
mkdir -p $outdir/script
#set the template
echo "root_dir="${outdir} > $outdir/script/param.txt
echo "template_dir="${bids_template} >> $outdir/script/param.txt
echo "template="${template} >> $outdir/script/param.txt
echo "template_brain="${template_brain} >> $outdir/script/param.txt
echo "template_mask="${template_mask} >> $outdir/script/param.txt
echo "template_atlas="${template_atlas} >> $outdir/script/param.txt
echo "template_wm="${template_atlas} >> $outdir/script/param.txt
echo "template_csf="${template_atlas} >> $outdir/script/param.txt
echo "roi_s1bf_l="${roi_s1bf_l} >> $outdir/script/param.txt
echo "roi_s1bf_r="${roi_s1bf_r} >> $outdir/script/param.txt
echo "roi_aca_l="${roi_aca_l} >> $outdir/script/param.txt
#set subject and session name
echo "subject="${subject%/} >> $outdir/script/param.txt
#other parameters
echo "cd "$outdir > $outdir/script/run.sh
#prepare options for anatomical scans
anat=$(ls ${PWD}/anat/$anat_base 2>/dev/null)
if [ "$anat" ]; then
anat=${anat[0]}
echo "anat="$anat >> $outdir/script/param.txt
cp $script_dir'/'$anat_script $outdir/script/
echo $outdir/script/$anat_script >> $outdir/script/run.sh
echo "anat2std_lin="$outdir$anat2std_lin >> $outdir/script/param.txt
echo "anat2std_nlin="$outdir$anat2std_nlin >> $outdir/script/param.txt
echo "anat2std_nlin_inv="$outdir$anat2std_nlin_inv >> $outdir/script/param.txt
echo "anat2temp="$anat2temp >> $outdir/script/param.txt
echo "anat2temp_inv="$anat2temp_inv >> $outdir/script/param.txt
else
echo "No anatomical scan found for "$subject" and session "$session
fi
#add anat_mask to params
anat_mask=$(ls ${PWD}/anat/$anat_base_mask 2>/dev/null)
if [ "$anat_mask" ]; then
anat_mask=${anat_mask[0]}
echo "anat_mask="$anat_mask >> $outdir/script/param.txt
fi
#prepare options for FUNC scans
func=$(ls ${PWD}/func/$func_base 2>/dev/null)
if [ "$func" ]; then
echo "func=("$func")" >> $outdir/script/param.txt
echo "TR="${TR} >> $outdir/script/param.txt
echo "FWHM="${FWHM} >> $outdir/script/param.txt
echo "fbot="${fbot} >> $outdir/script/param.txt
echo "ftop="${ftop} >> $outdir/script/param.txt
cp $script_dir'/'$func_script $outdir/script/
echo "cd "$outdir > $outdir/script/run.sh
echo $outdir/script/$func_script >> $outdir/script/run.sh
#add func_mask to params
func_mask=$(ls ${PWD}/func/$func_base_mask 2>/dev/null)
if [ "$func_mask" ]; then
func_mask=${func_mask[0]}
echo "func_mask="$func_mask >> $outdir/script/param.txt
fi
#else
#echo "No FUNC scan found for "$subject" and session "$session
fi
chmod +x $outdir/script/run.sh
cd $outdir
#prepare a batch file to run in slurm
echo \#\!/bin/bash > sbatch_file.sh
echo "#SBATCH --job-name="${subject} >> sbatch_file.sh
echo "#SBATCH --nodes=1" >> sbatch_file.sh
echo "#SBATCH --time=0-24:00:00" >> sbatch_file.sh
echo "#SBATCH --mail-type=FAIL" >> sbatch_file.sh
echo "#SBATCH --partition=batch" >> sbatch_file.sh
echo "#SBATCH --mem=16GB" >> sbatch_file.sh
echo "module load apptainer" >> sbatch_file.sh
echo "cd "${PWD} >> sbatch_file.sh
echo "apptainer run -B $""TMPDIR:/tmp_data '/project/4180000.41/to_run/mouseprep.sif' bash ${PWD}/script/run.sh" >> sbatch_file.sh
echo "rm -rf $""TMPDIR" >> sbatch_file.sh
#sbatch sbatch_file.sh
#qsub -N $subject -l 'procs=1,mem=4gb,walltime=01:00:00' ${PWD}/script/run.sh
#module load apptainer; apptainer run '/project/4180000.41/to_run/mouseprep.sif' bash ${PWD}/script/run.sh
#srun --time=2:00:00 --mem=16gb --pty apptainer run '/project/4180000.41/to_run/mouseprep.sif' bash ${PWD}/script/run.sh
cd $bids_original
done