-
Notifications
You must be signed in to change notification settings - Fork 1
/
dl.data
executable file
·194 lines (190 loc) · 5.49 KB
/
dl.data
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/bin/tcsh
# This script will save you some time downloading data from fmri.umd.edu
# written by dmoracze on 9/21/2015
#
# Initialize variables and set defaults
set count = 1
set dir = `pwd`
set opt = 1
set uname = $user
set subj = ()
set scan = all
# parse the inputs
if ($#argv == 0) then
echo " "
echo "**** No options given ****"
echo " "
echo "Here, this may help you:"
set argv = (-h)
endif
while ($count <= $#argv)
switch("$argv[$count]")
case "-h":
echo " "
echo "Usage: dl.data [options] -s subjectname"
echo " "
echo "[options]:"
echo "-h show this help file"
echo "-s felix felix will be the subject ID that you want to download"
echo " to download more than one subject, use -s before every ID"
echo "-dir ../study_dir directory to download data to (absolute or relative path)"
echo " default is current directory"
echo "-study My Study study ID directory from fmri server, quotes and escaped"
echo " spaces are essential"
echo " default is RED Social Communication"
echo "-PI Jane Doe PI diretory from the fmri server, quotes and escaped"
echo " spaces are essential"
echo " default is Elizabeth Redcay"
echo "-user dmitri dmitri is the user who will log on to fmri (if not you,"
echo " it will ask for password)"
echo " default is current user"
echo "-opt 1 choose from different options that will customize the -study"
echo " and PI for you, for added convenience"
echo " opt 1: PI = Elizabeth Redcay, study = RED"
echo " opt 2: PI = Stefanie Kuchinsky, study = TVI"
echo " default is -opt 1"
echo "-scan all choose which DICOM directory you want, only really applicable"
echo " if the subject has multiple scans (e.g. CMNT and CHT) on fmri"
echo " use a Run Identifier that will be unique to the specific DICOM"
echo " directory that you want. For example, 'CMNT' and 'CHT' are good"
echo " but 'T1' is not because there will be typically a T1 protocol"
echo " all DICOM folders. "all" will download the entire subject"
echo " default is -scan all"
echo " "
exit
case "-s":
@ count++
set subj = ($subj $argv[$count])
breaksw
case "-dir":
@ count++
set dir = $argv[$count]
breaksw
case "-study":
@ count++
set study = "$argv[$count]"
breaksw
case "-user":
@ count++
set uname = $argv[$count]
breaksw
case "-PI":
@ count++
set PI = "$argv[$count]"
breaksw
case "-opt":
@ count++
set opt = $argv[$count]
breaksw
case "-scan":
@ count ++
set scan = $argv[$count]
breaksw
endsw
shift
end
# check for subject IDs
if ($#subj == 0) then
echo " "
echo "No subject IDs given\!!"
echo "dl.data -h for help file"
echo " "
exit
endif
# parse predefined options
if ($opt == 1) then
set study = "RED\ Social\ Communication"
set PI = "Elizabeth\ Redcay"
else if ($opt == 2) then
set study = "TVI\ Timbre\ VS\ ID"
set PI = "Stefanie\ Kuchinsky"
else
echo " "
echo "-opt not understood"
echo "dl.data -h for help file"
echo " "
exit
endif
# download data and change permissions
foreach s ($subj)
echo " "
echo "PI: $PI"
echo "Study: $study"
echo "Subject: $s"
echo "Scan: $scan"
echo " "
if (-d $dir/$s) then
echo " "
echo "Subject's folder already exists!"
echo " "
continue
endif
sleep 2
# find the correct DICOM folder
set dl_dir = "/export/software/fmri/massstorage/$PI/$study/$s/"
set dl = ()
if ($scan != "all") then
echo " "
echo "Searching $s for $scan..."
set dcm = (`ssh -q ${uname}@fmri.umd.edu ls /export/software/fmri/massstorage/$PI/$study/$s/`)
alias calc 'awk "BEGIN{ print \!* }" '
foreach d ($dcm)
set temp = (`ssh -q ${uname}@fmri.umd.edu ls /export/software/fmri/massstorage/$PI/$study/$s/$d/`)
set temp = `echo $temp | grep -c $scan`
if ($temp) then
set dl = ($dl $d)
endif
end
# Check to ensure only 1 directory was chosen
if ($#dl == 1) then
echo " Found!"
echo " "
else if ($#dl > 1) then
echo " "
echo "More that one DICOM directory matches the criteria"
echo "I don't know how to choose, perhaps I should download the whole directory?"
echo " "
echo " Failing..."
echo " "
exit
else if ($#dl == 0) then
echo " "
echo "$s does not have $scan"
echo " "
echo " Failing..."
echo " "
exit
endif
endif
# prepare the directory structure (if needed) and download the data
if ($#dl > 0) then
mkdir $dir/$s
scp -r ${uname}@fmri.umd.edu:"/export/software/fmri/massstorage/$PI/$study/$s/$dl" $dir/$s
chgrp -R psyc-dscn-data $dir/$s
chmod -R ug+w $dir/$s
find $dir/$s -type d -exec chmod g+s {} \;
else
scp -r ${uname}@fmri.umd.edu:"/export/software/fmri/massstorage/$PI/$study/$s/" $dir
chgrp -R psyc-dscn-data $dir/$s
chmod -R ug+w $dir/$s
find $dir/$s -type d -exec chmod g+s {} \;
endif
# check if it downloaded
if (-d $dir/$s) then
echo " "
echo "$s downloaded!"
echo " "
sleep 2
else
echo " "
echo "$s failed..."
echo " "
sleep 2
endif
end
echo " "
echo "============================================"
echo "A long time ago on a server far, far away..."
echo "============================================"
echo " "
exit