-
Notifications
You must be signed in to change notification settings - Fork 0
/
dg_update_scan_id_and_make_nifti.pl~
252 lines (149 loc) · 7.4 KB
/
dg_update_scan_id_and_make_nifti.pl~
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
#!/usr/bin/perl
use Text::CSV;
$connect_params = " -host http://xnat.cci.psy.emory.edu:8080/xnat -u nbia -p nbia ";
$BASE_COMMAND = " /home/dgutman/xnat_tools/XNATRestClient $connect_params ";
$current_project="DG_TESTING";
my $csv = Text::CSV->new();
#####
### SO I am going to specify a subject ID... and then get the corresponding URI...
## I am then going to get the correspidning EXPERIMENT ID for htat aubject... so first things' first...
update_scan_name('/REST/experiments/CCIXNAT_E00456','800','DTI_FU');
update_scan_name('/REST/experiments/CCIXNAT_E00456','801','DTI_B0');
update_scan_name('/REST/experiments/CCIXNAT_E00456','802','DTI_MD');
exit;
$SUBJECT_ID_TO_LOOK_FOR="TCGA_06-0130";
##LIST SUBJET EXPERIMENTS
###http://xnat.cci.psy.emory.edu:8080/xnat/REST/projects/DG_TESTING/subjects/TCGA_06-0130/experiments
$GET_SUBJECT_STRING = "\"/REST/projects/$current_project/subjects/${SUBJECT_ID_TO_LOOK_FOR}/experiments?format=csv\"";
$FULL_SYNTAX = $BASE_COMMAND . " -m GET -remote " . $GET_SUBJECT_STRING;
print $FULL_SYNTAX. "\n";
@FULL_SUBJECT_EXPERIMENT_LIST_INFO = `$FULL_SYNTAX`;
#http://xnat.cci.psy.emory.edu:8080/xnat/REST/experiments?format=html&columns=xnat:mrSessionData/ID,xnat:imageScanData/type,xnat:imageScanData/ID,ID,label,subject_ID,subject_label
#--list subjects
#GET http://xnat.cci.psy.emory.edu:8080/xnat/REST/projects/NBIA_TCGA/subjects?format=html
#--list experiments
#GET http://xnat.cci.psy.emory.edu:8080/xnat/REST/projects/NBIA_TCGA/subjects/CCIXNAT_S00001/experiments?format=html
#--indivdual session
#GET http://xnat.cci.psy.emory.edu:8080/xnat/REST/experiments/CCIXNAT_E00001?format=html
#-list scans
#GET http://xnat.cci.psy.emory.edu:8080/xnat/REST/experiments/CCIXNAT_E00001/scans?format=html
#--modify scan typePUT
#http://xnat.cci.psy.emory.edu:8080/xnat/REST/experiments/CCIXNAT_E00001/scans/1?quality=unusable&type=SOMETHING
undef @EXPERIMENT_URI_FOR_PATIENT;
exit;
for($x=0; $x<=$#FULL_SUBJECT_EXPERIMENT_LIST_INFO; $x++)
{
#print $FULL_SUBJECT_EXPERIMENT_LIST_INFO[$x];
$csv->parse($FULL_SUBJECT_EXPERIMENT_LIST_INFO[$x]);
my @columns = $csv->fields();
print "@columns\n";
push(@EXPERIMENT_URI_FOR_PATIENT, $columns[7]);
}
print "Now listing the experiment URI's for the patient... this is really only a single column of values...\n";
for($x=1;$x<=$#EXPERIMENT_URI_FOR_PATIENT;$x++)
{
print $EXPERIMENT_URI_FOR_PATIENT[$x] . "\n";
### now that I have the URI... I am going to query the server again...
$GET_SCAN_STRING = $EXPERIMENT_URI_FOR_PATIENT[$x] . "/scans?format=csv";
print $GET_SCAN_STRING . "\n";
$FULL_SYNTAX = $BASE_COMMAND . " -m GET -remote " . $GET_SUBJECT_STRING;
print $FULL_SYNTAX. "\n";
@FULL_SCAN_LIST_INFO = `$FULL_SYNTAX`;
for($y=0;$y<=$#FULL_SCAN_LIST_INFO;$y++)
{
$csv->parse($FULL_SCAN_LIST_INFO[$x]);
my @columns = $csv->fields();
print "@columns\n";
### I am going to try and pull the data for a dicom session using the rest command...
###-user_session AAAABBBBCCCC00001111222233334444
###$ /home/dgutman/usr/bin/mcverter -o TCGA-06-0130/NIFTI_TEST -d -v -n -f nifti CRAP0/*.dcm
}
}
###ernode1 CRAP0]$ unzip -j bigmama this is how i will do it
#rnode1 xnat_tools]$
#[dgutman@trauma-computernode1 xnat_tools]$
#[dgutman@trauma-computernode1 xnat_tools]$ ./XNATRestClient -host "http://xnat.cci.psy.emory.edu:8080/xnat" -u nbia -p nbia -m GET -remote
#"/REST/experiments/CCIXNAT_E0045
#6/scans/801/files?format=zip" > bigmama
#[dgutman@trauma-computernode1 xnat_tools]$ unzi pbi
#[dgutman@trauma-computernode1 xnat_too
my $DICOM_CACHE = "/IMAGING_SCRATCH/TCGA_DICOM_CACHE";
###### NEXT THING I AM GOING TO DO IS FOR A GIVEN EXPERIMENT... LIST ALL THE SCAN INFO...
sub pull_dicom_session( $EXPERIMENT_ROOT_URI, $SCAN_ID )
{
### This will attempt to pull all of the dicom files associated with a given scan id.. i.e. "scan701 for experiment1234")
### note in this scenario I am pulling my the NUMBER.. not by the name... I may actually want to try and pull by name.. as it may make more sense
### for now to make my life easier ill just pull by the scan...
$EXPERIMENT_URI = $_[0];
$SCAN_ID = $_[1];
### TRYING TO DO A PUT
#http://xnat.cci.psy.emory.edu:8080/xnat/REST/experiments/CCIXNAT_E00001/scans/1?quality=unusable&type=SOMETHING
### UPDATE SCANTYPE given a scan id..
### TRYING TO DO A PUT
#http://xnat.cci.psy.emory.edu:8080/xnat/REST/experiments/CCIXNAT_E00001/scans/1?quality=unusable&type=SOMETHING
}
sub update_scan_name ( $EXPERIMENT_ROOT_URI, $SCAN_ID, $NEW_NAME )
{
### This will attempt to pull all of the dicom files associated with a given scan id.. i.e. "scan701 for experiment1234")
### note in this scenario I am pulling my the NUMBER.. not by the name... I may actually want to try and pull by name.. as it may make more sense
### for now to make my life easier ill just pull by the scan...
$EXPERIMENT_URI = $_[0];
$SCAN_ID = $_[1];
$NEW_NAME = $_[2];
$QUALITY = "unusable";
print "Received $EXPERIMENT_URI for $SCAN_ID and want to make it $NEW_NAME \n";
$UPDATE_SCAN_ID = "$EXPERIMENT_URI/scans/$SCAN_ID?quality=$QUALITY&type=$NEW_NAME";
$FULL_SYNTAX = $BASE_COMMAND . " -m PUT -remote \"" . $UPDATE_SCAN_ID ."\"";;
print "update string should be $FULL_SYNTAX \n";
`$FULL_SYNTAX`;
### TRYING TO DO A PUT
#http://xnat.cci.psy.emory.edu:8080/xnat/REST/experiments/CCIXNAT_E00001/scans/1?quality=unusable&type=SOMETHING
### UPDATE SCANTYPE given a scan id..
### TRYING TO DO A PUT
#http://xnat.cci.psy.emory.edu:8080/xnat/REST/experiments/CCIXNAT_E00001/scans/1?quality=unusable&type=SOMETHING
}
exit;
###
### EXAMPLE COMMANDS:::
## THIS WILL GET ALL THE SUBJECTS FOR THE NBIA_TCGA PROJECT...
$REST_PART = "\"/REST/projects/$current_project/subjects?format=csv\"";
$FULL_SYNTAX = $BASE_COMMAND . " -m GET -remote " . $REST_PART;
@FULL_SUBJECT_LIST_INFO = `$FULL_SYNTAX`;
print @FULL_SUBJECT_LIST_INFO;
exit;
### I NNOW HAVE AN ARRAY LISTING the csv output from the above command as a line
#print $FULL_SUBJECT_LIST_INFO;
for($i=1;$i<=$#FULL_SUBJECT_LIST_INFO;$i++)
{
$line = $FULL_SUBJECT_LIST_INFO[$i];
chomp($line);
$line =~ s/\"//g;
($ID,$project,$label,$insert_date,$insert_user,$URI) = split(/,/,$line);
#print "$i;$ID,$label,$URI\n";
# print $line . "\n";
### NOW FOR EACH PATIENT/LABEL I WANT TO GET SOME MORE INFO... LIKE THE SCAN IDS or more importantly.. the LABELS for the individuals..
## THIS STATEMENT WILL GET ALL OF THE INIDIVUDAL SCAN SESSIONS FOR THAT PATIENT.. WOO HOO..
$new_rest_statement = "\"/REST/projects/$current_project/subjects/$label/experiments?format=csv\"";
$FULL_SYNTAX = $BASE_COMMAND . " -m GET -remote ". $new_rest_statement;
# print $FULL_SYNTAX ."\n";
@EXPERIMENT_STATUS = `$FULL_SYNTAX`;
if($#EXPERIMENT_STATUS == 0 ) { print "We ain't found shit\n";}
elsif ($#EXPERIMENT_STATUS > 0 )
{
#print "YEAH!!! THIS SUBJECT ACTUALLY HAS EXPERIMENTS... IVE NEVER BEEN MORE EXCITED!!!!! $label!!! \n";
for($j=0;$j<=$#EXPERIMENT_STATUS;$j++)
{
$EXPERIMENT_STATUS[$j] =~ s/\"//g;
$other_line = $EXPERIMENT_STATUS[$j];
chomp($other_line);
($subjectasseor,$ID_2,$project_2,$date,$type,$label_2, $ins_date, $URI ) = split(/,/,$other_line);
print "$j;$ID_2;$label_2;$URI\n";
}
}
$new_new_rest_statement = "\"/REST/projects/$current_project/subjects/$label/experiments/$label_2/scans?format=csv\"";
$FULL_SYNTAX = $BASE_COMMAND . " -m GET -remote ". $new_new_rest_statement;
@sessions = `$label_2`;
print @sessions
# system($FULL_SYNTAX);
# exit;
}