-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrac_2_tckgen_backup
164 lines (125 loc) · 5.3 KB
/
trac_2_tckgen_backup
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
154
155
156
157
158
159
160
161
162
163
164
#! /bin/bash
## usage: trac_2_tckgen -t 12 -b 0
while [ $1 != -- ] ; do
case $1 in
-t)
nthreads=$2;
shift;;
-b)
nbatch=$2;
shift;;
esac
shift
done
logdir=/lus/theta-fs0/projects/AD_Brain_Imaging/anal/adni/adni_on_alcf/job
CMD1_batch=$logdir/batch${nbatch}_5ttgen
CMD2_batch=$logdir/batch${nbatch}_tckgen
rm -rf $CMD1_batch
rm -rf $CMD2_batch
#nthreadsX2=$((${nthreads}*2))
subjectlist=/ifs/scratch/pimri/posnerlab/1anal/adni/data/nii/list_dti
for s in `cat $subjectlist`
do
CMD1=$logdir/cmd.5ttgen.${s}
rm -rf $CMD1
echo "#!/bin/bash
source ~/.bashrc
#FREESURFER_HOME=$WORK/freesurfer_dev/freesurfer
#source /ifs/scratch/pimri/posnerlab/freesurfer_dev/freesurfer/FreeSurferEnv.sh
ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS=256
#SUBJECT=${s}_1mm_flair
SUBJECT=${s}
cd $adni/fs/\${SUBJECT}/dmri2
mkdir xfm
### flirt
echo *****NOW GENERATING ANAT2DIFF.FLT.MAT *****
mri_convert ../mri/brain.mgz brain_anat_orig.nii.gz
sleep 5
#/ifs/scratch/pimri/posnerlab/freesurfer_dev/freesurfer/bin/flip4fsl brain_anat_orig.nii.gz brain_anat.nii.gz
orientLAS brain_anat_orig.nii.gz brain_anat.nii.gz
sleep 5
mrconvert mr_meanb0.mif.gz mr_meanb0.nii.gz -force
sleep 5
flirt -in brain_anat.nii.gz -ref mr_meanb0.nii.gz -out brain_anat2diff -omat anat2diff.flt.mat -v
sleep 5
### 5TTGEN
echo ***** NOW 5TTGEN *****
mri_convert ../mri/T1.mgz /tmp/tmp.nii.gz && /ifs/scratch/pimri/posnerlab/freesurfer_dev/freesurfer/bin/flip4fsl /tmp/tmp.nii.gz T1_flip.nii.gz
sleep 5
flirt -in T1_flip.nii.gz -out T1_2diff_flt.nii.gz -ref mr_meanb0.nii.gz -applyxfm -init anat2diff.flt.mat -v
sleep 5
5ttgen fsl T1_2diff_flt.nii.gz 5tt2.mif.gz -force -nthreads $nthreads
mrconvert 5tt2.mif.gz 5tt2.nii.gz -force
sleep 5
5tt2gmwmi 5tt2.mif.gz 5tt2_gmwmi_mask.mif.gz -nthreads $nthreads -force
sleep 5
### APARC+ASEG to diff
for im in aparc+aseg aparc.a2009s+aseg
do
echo ****NOW CONVERTING MGZ TO NII
mri_convert ../mri/\${im}.mgz \${im}.nii.gz
sleep 5
echo ****FLIPING FOR FSL
/ifs/scratch/pimri/posnerlab/freesurfer_dev/freesurfer/bin/flip4fsl \${im}.nii.gz \${im}_flip.nii.gz
sleep 5
echo ****NOW FLIRTING
flirt -in \${im}_flip.nii.gz -out \${im}_2_diff_flt.nii.gz -ref mr_meanb0.nii.gz -applyxfm -init anat2diff.flt.mat -interp nearestneighbour
sleep 5
done
### labelconvert for aparc+aseg and aparc.a2009+aseg
labelconvert aparc+aseg_2_diff_flt.nii.gz $FREESURFER_HOME/FreeSurferColorLUT.txt /ifs/scratch/pimri/posnerlab/app/mrtrix3/src/connectome/tables/fs_default.txt nodes_aparc+aseg2.mif.gz -force
sleep 5
labelconvert aparc.a2009s+aseg_2_diff_flt.nii.gz $FREESURFER_HOME/FreeSurferColorLUT.txt /ifs/scratch/pimri/posnerlab/app/mrtrix3/src/connectome/tables/fs_a2009s.txt nodes_aparc.a2009s+aseg2.mif.gz -force
sleep 5
#labelsgmfix nodes.mif.gz T1_diff.nii.gz fs_default.txt nodes_fixSGM.mif.gz -sgm_amyg_hipp -premasked -verbose -nthreads 12
############
" >$CMD1
#batch submission
echo $CMD1 >> $CMD1_batch
done
#prepid=`$code/fsl_sub_hpc_1 -s smp,$nthreads -l $logdir -t ${CMD1_batch}`
echo ${CMD1_batch}
for s in `cat $subjectlist`
do
CMD2=$logdir/cmd.tckgensift.${s}
rm -rf $CMD2
echo "#!/bin/bash
source ~/.bashrc
ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS=$nthreads
echo NOW WARPING FOR SUBJECT ${s}
SUBJECT=${s}_1mm_flair
cd /ifs/scratch/pimri/posnerlab/1anal/IDP/fs/\${SUBJECT}/dmri2
#### tckgen
#rm -rf mr_track_10M_SIFT2.tck
if [ -e /tmp/mr_track_10M_SIFT2.tck ]; then
tracknum=\`tckinfo mr_track_10M_SIFT2.tck | grep max_num_tracks | grep -o 10000000\`
if [ \$tracknum != 10000000 ]; then
tckgen WM_FODs.mif.gz /tmp/mr_track_20M2.tck -act 5tt2.mif.gz -backtrack -crop_at_gmwmi -seed_dynamic WM_FODs.mif.gz -maxlength 250 -minlength 30 -select 20M -force -nthreads $nthreads
tcksift -act 5tt2.mif.gz /tmp/mr_track_20M2.tck WM_FODs.mif.gz /tmp/mr_track_10M_SIFT2.tck -term_number 10M -force -nthreads $nthreads && echo 'sift done'*******
else
echo 'sift done'*******
fi
else
tckgen WM_FODs.mif.gz /tmp/mr_track_20M2.tck -act 5tt2.mif.gz -backtrack -crop_at_gmwmi -seed_dynamic WM_FODs.mif.gz -maxlength 250 -minlength 30 -select 20M -force -nthreads $nthreads
tcksift -act 5tt2.mif.gz /tmp/mr_track_20M2.tck WM_FODs.mif.gz /tmp/mr_track_10M_SIFT2.tck -term_number 10M -force -nthreads $nthreads && echo 'sift done'*******
fi
#### tck2connectome
for im in aparc+aseg aparc.a2009s+aseg
do
tck2connectome -force -zero_diagonal -nthreads $nthreads /tmp/mr_track_10M_SIFT2.tck nodes_\${im}2.mif.gz mr_sift_10M_connectome_\${im}_count.csv
tck2connectome -force -zero_diagonal -scale_length -stat_edge mean -nthreads $nthreads /tmp/mr_track_10M_SIFT2.tck nodes_\${im}2.mif.gz mr_sift_10M_connectome_\${im}_length.csv
tck2connectome -force -zero_diagonal -scale_invnodevol -nthreads $nthreads /tmp/mr_track_10M_SIFT2.tck nodes_\${im}2.mif.gz mr_sift_10M_connectome_\${im}_volumeadj.csv
done
### save scratch space
# if [ -e mr_sift_10M_connectome_aparc+aseg_count.csv ] ; then rm mr_track_100M.tck
# else echo SIFT WAS NOT SUCCESSFUL
# fi
echo "END OF TCKGEN AND SIFT"
" > $CMD2
echo $CMD2 >> $CMD2_batch
chmod +x $CMD2
done
#$code/fsl_sub_hpc_36 $monk/data/cmd/cmd2_${s}
#echo $jobid >> $monk/data/cmd/jobid
#$code/fsl_sub_hpc_1 -N connectome -s smp,$nthreads -j $prepid -l $logdir -t ${CMD2_batch}
$code/fsl_sub_hpc_1 -N connectome -s smp,$nthreads -l $logdir -t ${CMD2_batch}