-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathNSPN_Parcellation_PostEdits.sh
executable file
·180 lines (154 loc) · 7.29 KB
/
NSPN_Parcellation_PostEdits.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/bin/bash
#====================================================================
# Created by Kirstie Whitaker on 25th April 2016
#
# DESCRIPTION:
# This code creates a few parcellations for each person in their
# freesurfer space, and should be applied after recon-all edits
# have been completed.
#
# INPUTS:
# study_dir : The directory containing the SUB_DATA folder which
# itself contains directories named by sub_id.
# sub_id : Subject ID. These folders should be inside SUB_DATA
# and themselves contain directories called SURFER
# and MPM.
# occ : The scan occasion. One of baseline, 6_month, 1st_follow_up,
# CBSU, UCL, WBIC, t1 and t2. This directory contains the
# output of recon-all and is found inside the subject's SURFER
# directory.
#
# EXPECTS:
# All the output files from recon-all should exist in the
# realavent occasion directory in the subject's SURFER
# directory.
# All quality control editing should have been conducted.
# The fsaverageSubP directory containing the standard space
# parcellation should exist inside the SUB_DATA directory.
#
# OUTPUTS:
# The following files are created inside the relavent occasion
# directory in the subject's SURFER directory:
#
# parcellation/${parcellation}.nii.gz
# parcellation/${parcellation}_renum.nii.gz
# for example:
# parcellation/500.aparc.nii.gz
# parcellation/500.aparc_renum.nii.gz
# label/${hemi}.${parcellation}.annot
# for example:
# label/lh.500.aparc.annot
# label/rh.500.aparc.annot
#
#====================================================================
#====================================================================
# USAGE: NSPN_Parcellation_PostEdits.sh <study_dir> <sub> <occ>
#====================================================================
function usage {
echo "USAGE: NSPN_Parcellation_PostEdits.sh <study_dir> <sub> <occ>"
echo " <study_dir> is the parent directory to the SUB_DATA"
echo " directory and expects to find SUB_DATA inside it"
echo " and then the standard NSPN directory structure."
echo " <sub> is the subject ID that corresponds to a"
echo " folder in the SUB_DATA directory."
echo " <occ> is the scan occasion and is one of baseline,"
echo " 6_month, 1st_follow_up, CBSU, WBIC, UCL, t1 and t2"
echo ""
echo "DESCRIPTION: This code creates a few different parcellations"
echo " for each person in their freesurfer space, and"
echo " should be applied after recon-all edits have"
echo " been completed"
exit
}
#====================================================================
# READ IN COMMAND LINE ARGUMENTS
#====================================================================
study_dir=$1
sub=$2
occ=$3
if [[ ! -d ${study_dir} ]]; then
echo "**** STUDY DIRECTORY does not exist ****"
usage
fi
if [[ -z ${sub} ]]; then
echo "**** No subject ID given ****"
usage
fi
if [[ -z ${occ} ]]; then
echo "**** No occasion given ****"
usage
fi
#====================================================================
# SET A COUPLE OF USEFUL VARIABLES
#====================================================================
sub_data_dir=${study_dir}/SUB_DATA
fsaverage_subid=fsaverageSubP
#====================================================================
# PRINT TO SCREEN WHAT WE'RE DOING
#====================================================================
echo "==== Create individual parcellations ===="
#====================================================================
# Transform the fsaverage parcellations
#====================================================================
SUBJECTS_DIR=${sub_data_dir}
subjid=${occ}
# Loop through the different parcellations
# Specifically:
# * 500.aparc is the NSPN500 parcellation which splits the brain
# into 308 regions that are constrained to be within
# Deskian-Killiany atlas regions and no more than 500mm^2
# in surface area
# * Yeo2011_7Networks_N1000 is the Yeo parcellation with 7 networks
# that ships with freesurfer (Yeo, 2011, J Neurophysiol)
# * HCP is the parcellation published by the Human Connectome
# Project (Glasser et al, 2016, Nature)
# * economo is the Von Economo parcellation published by the
# Dutch Connectome Lab (lead by Martijn van den Heuvel)
# and available at http://www.dutchconnectomelab.nl/economo/
for parcellation in 500.aparc Yeo2011_7Networks_N1000 HCP economo; do
# Create the surface parcellations in subject space
echo " Transforming ${parcellation} parcellation"
# Loop through both hemispheres
for hemi in lh rh; do
# Check to see if output file already exists
if [[ ! -f ${SUBJECTS_DIR}/${sub}/SURFER/${subjid}/label/${hemi}.${parcellation}.annot ]]; then
echo " Creating ${hemi} ${parcellation} surface in subject space"
# Transform the surface parcellation from fsaverage space
# to indiviual native space
mri_surf2surf --srcsubject ${fsaverage_subid} \
--sval-annot ${SUBJECTS_DIR}/${fsaverage_subid}/label/${hemi}.${parcellation} \
--trgsubject ${sub}/SURFER/${subjid} \
--trgsurfval ${SUBJECTS_DIR}/${sub}/SURFER/${subjid}/label/${hemi}.${parcellation} \
--hemi ${hemi}
else
echo " ${hemi} ${parcellation} surface already in subject space"
fi
done
# Check to see if volume parcellation file already exists
if [[ ! -f ${SUBJECTS_DIR}/${sub}/SURFER/${subjid}/parcellation/${parcellation}.nii.gz ]]; then
# Transform indivual surface parcellation to individual volume parcellation
echo " Creating ${parcellation} volume in subject space"
mkdir -p ${SUBJECTS_DIR}/${sub}/SURFER/${subjid}/parcellation/
mri_aparc2aseg --s ${sub}/SURFER/${subjid} \
--o ${SUBJECTS_DIR}/${sub}/SURFER/${subjid}/parcellation/${parcellation}.nii.gz \
--annot ${parcellation} \
--rip-unknown \
--hypo-as-wm
else
echo " ${parcellation} volume in subject space already in subject space"
fi
# Check to see if renumbered volume parcellation file already exists
if [[ ! -f ${SUBJECTS_DIR}/${sub}/SURFER/${subjid}/parcellation/${parcellation}_renum.nii.gz ]]; then
# Transform indivual surface parcellation to individual volume parcellation
echo " Renumbering ${parcellation} volume to consecutive counters"
scripts_dir=`dirname $0`
${scripts_dir}/NSPN_RenumberParcellationVolume.py \
${SUBJECTS_DIR}/${sub}/SURFER/${subjid}/parcellation/${parcellation}.nii.gz \
${scripts_dir}/FS_SUBJECTS/fsaverageSubP/parcellation/${parcellation}.regionIDs.txt
else
echo " ${parcellation} volume in subject space already renumbered"
fi
done
#====================================================================
# All done!
#====================================================================