-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path0_anat_template.sh
83 lines (47 loc) · 4.21 KB
/
0_anat_template.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
bids_base='/project/4180000.41'
bids_original=$bids_base'/bids'
bids_template=$bids_base'/tmp/DI1/anat_template'
template='/project/4180000.41/SIGMA_Wistar_Rat_Brain_TemplatesAndAtlases_Version1.1/SIGMA_Rat_Anatomical_Imaging/SIGMA_Rat_Anatomical_InVivo_Template/SIGMA_InVivo_Brain_Template.nii'
template_brain='/project/4180000.41/SIGMA_Wistar_Rat_Brain_TemplatesAndAtlases_Version1.1/SIGMA_Rat_Anatomical_Imaging/SIGMA_Rat_Anatomical_InVivo_Template/SIGMA_InVivo_Brain_Template_Masked.nii'
template_mask='/project/4180000.41/SIGMA_Wistar_Rat_Brain_TemplatesAndAtlases_Version1.1/SIGMA_Rat_Anatomical_Imaging/SIGMA_Rat_Anatomical_InVivo_Template/SIGMA_InVivo_Brain_Template_Masked.nii'
anat_base='*_T2w.nii.gz'
mkdir -p $bids_template'/data'
mkdir -p $bids_template'/script'
cd $bids_original
ls -d */ | while read subject
do
cd $subject
echo "now doing subject "$subject
anat=$(ls ${PWD}/anat/$anat_base 2>/dev/null)
if [ "$anat" ]; then
anat=${anat[0]}
fi
cp $anat $bids_template'/data/'${subject%/}'.nii.gz'
3drefit -overwrite -deoblique $bids_template'/data/'${subject%/}'.nii.gz'
cd ..
done
cd $bids_template'/data'
ls . | while read line
do
line_noext="$(remove_ext $line)"
N4BiasFieldCorrection -d 3 -i $line -o $line_noext'_N4.nii.gz'
done
/opt/MouseANTs/buildtemplateparallel_short.sh -d 3 -n 0 -c o -j 10 -t RA -i 1 -z ${template} -o 00 *_N4.nii.gz
mv 00template.nii.gz init_template.nii.gz
rm -r 00*
/opt/MouseANTs/buildtemplateparallel_short.sh -d 3 -n 0 -c o -j 10 -m 24x16x8 -z init_template.nii.gz -o 01 *_N4.nii.gz
cp 01template.nii.gz ../template.nii.gz
cd ..
/opt/MouseANTs/antsBrainExtraction_short.sh -d 3 -a template.nii.gz -e ${template} -m ${template_mask} -o ./
mv BrainExtractionMask.nii.gz template_mask.nii.gz
#alternative to antsBrainExtraction using RATS
#RATS_MM -t 70 -v 450 template.nii.gz template_mask.nii.gz
mkdir -p transform
antsRegistration --dimensionality 3 --float 0 -a 0 -v 1 --output transform/std2abi --interpolation Linear --winsorize-image-intensities [0.005,0.995] --use-histogram-matching 0 --initial-moving-transform [${template},template.nii,1] --transform Rigid[0.1] --metric MI[${template},template.nii,1,32,Regular,0.25] --convergence [1x1x1x1,1e-6,10] --shrink-factors 8x4x2x1 --smoothing-sigmas 3x2x1x0vox --transform Affine[0.1] --metric MI[${template},template.nii,1,32,Regular,0.25] --convergence [1x1x1x1,1e-6,10] --shrink-factors 8x4x2x1 --smoothing-sigmas 3x2x1x0vox -x [${template_mask},template_mask.nii]
antsApplyTransforms -i template.nii -r ${template} -t transform/std2abi0GenericAffine.mat -o template_lin.nii.gz -v
antsApplyTransforms -i template_mask.nii -r ${template} -t transform/std2abi0GenericAffine.mat -o template_mask_lin.nii.gz -v -n NearestNeighbor
antsRegistration --dimensionality 3 --float 0 -a 0 -v 1 --output transform/std2abi --transform SyN[0.1,3,0] --metric CC[${template},template_lin.nii.gz,1,4] --convergence [1x1x1x1,1e-6,10] --shrink-factors 8x4x2x1 --smoothing-sigmas 3x2x1x0vox -x [${template_mask},template_mask_lin.nii.gz]
antsApplyTransforms -i template.nii -r ${template} -t transform/std2abi0GenericAffine.mat -t transform/std2abi0Warp.nii.gz -o template_nlin.nii.gz -v
antsApplyTransforms -i template_mask.nii -r ${template} -t transform/std2abi0GenericAffine.mat -t transform/std2abi0Warp.nii.gz -o template_nlin_mask.nii.gz -v -n NearestNeighbor
slicer template_nlin.nii.gz ${template} -s 2 -x 0.35 sla.png -x 0.45 slb.png -x 0.55 slc.png -x 0.65 sld.png -y 0.35 sle.png -y 0.45 slf.png -y 0.55 slg.png -y 0.65 slh.png -z 0.35 sli.png -z 0.45 slj.png -z 0.55 slk.png -z 0.65 sll.png ; pngappend sla.png + slb.png + slc.png + sld.png + sle.png + slf.png + slg.png + slh.png + sli.png + slj.png + slk.png + sll.png highres2standard1.png ; slicer ${template} template_nlin.nii.gz -s 2 -x 0.35 sla.png -x 0.45 slb.png -x 0.55 slc.png -x 0.65 sld.png -y 0.35 sle.png -y 0.45 slf.png -y 0.55 slg.png -y 0.65 slh.png -z 0.35 sli.png -z 0.45 slj.png -z 0.55 slk.png -z 0.65 sll.png ; pngappend sla.png + slb.png + slc.png + sld.png + sle.png + slf.png + slg.png + slh.png + sli.png + slj.png + slk.png + sll.png highres2standard2.png ; pngappend highres2standard1.png - highres2standard2.png anat2standard.png; rm -f sl?.png highres2standard2.png
rm highres2standard1.png