-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconnectome_modules.sh
executable file
·129 lines (100 loc) · 4 KB
/
connectome_modules.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
#!/bin/bash
set -e
#define
codedir=${HOME}/Dropbox/Github/tractography/
basedir="$(pwd -P)"
usage()
{
cat<<EOF
usage: $0 options
=============================================================================================
connectome_modules.sh template
- performs a connectomics modularity analysis (connectome_modules.m)
- makes a folder with each modules nifti image (combined parcels)
- creates a .txt list of module image paths
- compares module similarity with sensori -motor region ROIs
- performs tractography based segmentation based on modules
Runs with: connectome_modules.m
Written by Michael Hart, University of British Columbia, May 2021
=============================================================================================
EOF
exit 1
}
basedir=`pwd`
template=$1
echo ${template}
#outname=`basename ${atlas} .nii.gz` #for parsing outputs
mkdir connectome_modules_${template}
#1. Connectome modularity matlab analysis
file_matlab=test_modules
echo "connectome_modules('${template}');exit" > ${file_matlab}.m
matlab -nodisplay -nosplash -nodesktop -r "${file_matlab}"
#2-4.Form modules from parcels, generate a .txt list of module image paths, perform cross-correlation of module with cortico-spinal seed
cd connectome_modules_${template}
touch cross_correlation.txt
touch modules_targets_list.txt
nModules=`ls module_* | wc -l` #number of modules in directory
echo "nModules = ${nModules}"
for iModule in module_*.txt; #for each module
do
echo "doing module: ${iModule}"
moduleName=`basename ${iModule} .txt`
nParcels=`wc -l ${iModule} | awk '{print $1}'` #number of lines (parcels) in module_*.txt
echo "nParcels = ${nParcels}"
topparcel=`cat ${iModule} | awk 'FNR == 1 {print $1}'` #first parcel in module
topparcel=`head -n ${topparcel} ${basedir}/${template}_seeds/seeds_targets_list.txt | tail -1` #.nii.gz image of parcel
echo "topparcel is: ${topparcel}"
cp ${topparcel} ${moduleName}.nii.gz
echo "cp ${topparcel} ${moduleName}.nii.gz"
while read line;
do
echo "doing parcel: ${line}"
parcel=`head -n ${line} ${basedir}/${template}_seeds/seeds_targets_list.txt | tail -1`
echo "parcel is: ${parcel}"
fslmaths ${moduleName}.nii.gz -add ${parcel} ${moduleName}.nii.gz
done < ${iModule}
#doing cross correlation
echo "cross correlation of ${moduleName}" >> cross_correlation.txt
echo "cst_l" >> cross_correlation.txt
echo `fslcc ${moduleName}.nii.gz ${codedir}/templates/cst_l_MNI.nii.gz` >> cross_correlation.txt
echo "cst_r" >> cross_correlation.txt
echo `fslcc ${moduleName}.nii.gz ${codedir}/templates/cst_r_MNI.nii.gz` >> cross_correlation.txt
#make text list (for probtrackx call)
echo `pwd`/${moduleName}.nii.gz >> modules_targets_list.txt
done
#5. Tractography
#Left - seed to target
probtrackx2 --samples=${basedir}/bpx.bedpostX/merged \
--mask=${basedir}/bpx.bedpostX/nodif_brain_mask \
--xfm=${basedir}/bpx.bedpostX/xfms/standard2diff \
--invxfm=${basedir}/bpx.bedpostX/xfms/diff2standard \
--seedref=${FSLDIR}/data/standard/MNI152_T1_2mm_brain.nii.gz \
--seed=${basedir}/segmentation/thalamus_left_MNI.nii.gz \
--targetmasks=modules_targets_list.txt \
--dir=connectome_modules_left \
--loopcheck \
--onewaycondition \
--forcedir \
--opd \
--os2t \
--nsamples=5000
#find_the_biggest
find_the_biggest connectome_modules_left/seeds_to_* connectome_modules_left/biggest_segmentation
#Right - seed to target
probtrackx2 --samples=${basedir}/bpx.bedpostX/merged \
--mask=${basedir}/bpx.bedpostX/nodif_brain_mask \
--xfm=${basedir}/bpx.bedpostX/xfms/standard2diff \
--invxfm=${basedir}/bpx.bedpostX/xfms/diff2standard \
--seedref=${FSLDIR}/data/standard/MNI152_T1_2mm_brain.nii.gz \
--seed=${basedir}/segmentation/thalamus_right_MNI.nii.gz \
--targetmasks=modules_targets_list.txt \
--dir=connectome_modules_right \
--loopcheck \
--onewaycondition \
--forcedir \
--opd \
--os2t \
--nsamples=5000
#find_the_biggest
find_the_biggest connectome_modules_right/seeds_to_* connectome_modules_right/biggest_segmentation
#all done