-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnalysis_Pipeline.do
502 lines (389 loc) · 17.1 KB
/
Analysis_Pipeline.do
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
************************************************
* ANALYSIS_PIPELINE.DO
************************************************
* Analyses the three methods on a site by site basis; creates summary tables agraphs
*Inputs: pipeline_clean_all_values_wide (from clean_predict.do)
* Outputs : method_disagreements_all.wmf ( graph comparing the differences in the methods in three pairs: typewriter vs. genefinder, genefinder vs mykrobe, and mykrobe vs typewriter
* graphs saved to Graph folder
* Written by: Amy Mason
set li 130
cap log close
log using analysis1.log, replace
noi di "Run by AMM on $S_DATE $S_TIME"
cd E:\users\amy.mason\Pipeline_27_07_2016\Datasets
*************************************************
cd E:\users\amy.mason\Pipeline_27_07_2016\Datasets
use pipeline_clean_all_values_wide, clear
****************************************
******************************************************
noi di _n(5) _dup(80) "=" _n " Overall summary" _n _dup(80) "="
******************************************************
* tables summarizing the % agreements between methods
* look at log file to read summary
noi di "Recall order is Mykrobe Mykrobe Genefinder"
noi tab site ValueA, m
gen agree = (ValueA=="AAA"| ValueA=="PPP" )
summ agree
noi di r(sum) " out of " r(N) " site predictions agree"
noi di r(sum)/_N*100
noi di "largest disagreements"
noi tab site if agree!=1, sort
noi tab site ValueA if agree!=1
summ agree if strpos(type, "Aqu") |strpos(type, "Chro")
noi di r(sum) " out of " r(N) " aquired or chromosonal resistance site predictions agree"
noi di r(sum)/r(N)*100
noi tab ValueAll if strpos(type, "Aquired"), sort
summ agree if strpos(type, "Aquired")
noi di r(sum) " out of " r(N) " predictions are identical between all three methods on aquired resistance prediction"
noi tab ValueAll if strpos(type, "Chrom"), sort
summ agree if strpos(type, "Chrom")
noi di r(sum) " out of " r(N) " predictions are identical between all three methods on chromosonal resistance prediction"
noi tab ValueAll if strpos(type, "ccr"), sort
summ agree if strpos(type, "ccr")
noi di r(sum) " out of " r(N) " predictions are identical between all three methods on ccr prediction"
noi tab ValueAll if strpos(type, "viru"), sort
summ agree if strpos(type, "viru")
noi di r(sum) " out of " r(N) " predictions are identical between all three methods on virulence prediction"
noi tab ValueAll if strpos(type, "Chrom")|strpos(type, "Aquired"), sort
summ agree if strpos(type, "Chrom")|strpos(type, "Aquired")
noi di r(sum) " out of " r(N) " predictions are identical between all three methods on antibiotic prediction"
*which samples have the most discrenpacies
noi di "site discrenpacies by sample"
noi tab sample if agree!=1, sort
noi list sample site Value if agree!=1
*which set have the most discrenpacies
noi di "site discrenpacies by set"
noi tab set if agree!=1, sort
noi tab set agree, row
noi tab set agree, chi2
noi list set site Value if agree!=1
*which set and type have the most discrenpacies
noi di "site discrenpacies by set and type"
gen new = set + type
noi tab new if agree!=1, sort
noi tab new agree, row
noi tab new agree, chi2
*Kappa statistics for paper
noi di "Kappa statistics site by site"
gen gf = ( valuegenefinder=="P")
gen tw = ( valuet=="P")
gen mk = ( valuez=="P")
noi di "genefinder compared with typewriter"
noi kap gf tw
noi di "typewriter compared to mykrobe"
noi kap tw mk
noi di "mykrobe compared to genefinder"
noi kap mk gf
noi di "all three"
noi kap tw mk gf
drop gf tw mk
*********************************************************
noi di _n(5) _dup(80) "=" _n "Site by site predictions" _n _dup(80) "="
*********************************************************
* which sites have the most discrepancies, also table for paper
noi tab site ValueAll, m
noi di _n(5) _dup(80) "=" _n "McNemar relative differences, site by site" _n _dup(80) "="
********************************************************************************
noi di "three ways tables"
use pipeline_clean_all_values_wide, clear
*keep if strpos(type, "viru")
noi bysort site: table valuegenefinder valuetypewriter valuezam
noi di "site == all"
noi table valuegenefinder valuetypewriter valuezam
***********************************************************************
* Compare typewriter with genefinder
**********************************************************************
noi di "typewriter vs genefinder"
use pipeline_clean_all_values_wide, clear
*keep if strpos(type, "viru")
table valuegenefinder valuetypewriter
gen match = ( valuetypewriter== valuegen)
gen AA=( valuegenefinder=="A" & valuetypewriter=="A")
gen AP=( valuegenefinder=="A" & valuetypewriter=="P")
gen PA=( valuegenefinder=="P" & valuetypewriter=="A")
gen PP=( valuegenefinder=="P" & valuetypewriter=="P")
sort site
* calculate mcnemar chi, is there a significant bias in which was discrepancies go
preserve
noi di "McNemar chi"
collapse (count) match (sum) AA AP PA PP summatch= match
for any McNchi pvalue chi95:gen X=.
replace McNchi = ((abs(AP - PA)-1)^2)/(AP+PA)
replace pvalue = 1- chi2(1,McNchi)
replace chi95 = 3.841
gen sig = "Significant" if McNchi> chi95 & McNchi!=.
noi list McNchi pvalue sig if sig!=""
restore
gen GY = ( valuegenefinder=="P")
gen TY = ( valuet=="P")
gen ZY = ( valuez=="P")
mcc GY TY
* collapse to produce graph
collapse (count) match (sum) AA AP PA PP summatch= match, by(site type)
for any lci uci diff:gen X=.
local max=_N
* create difference intervals
forvalues i=1(1)`max'{
display site[`i']
local a= AA[`i']
local b= AP[`i']
local c= PA[`i']
local d= PP[`i']
mcci `a' `b' `c' `d'
replace diff = r(D_f) if _n==`i'
replace lci = r(lb_D_f) if _n==`i'
replace uci = r(ub_D_f) if _n==`i'
}
* create size of difference ordering for graph
gen prop = abs(diff)
gsort -prop
gen num =_n
gen method= "tg"
labmask num, values(site)
save tgdata, replace
gsort type -prop
gen num2=_n
labmask num2, values(site)
* draw graph
#delimit ;
twoway rcapsym lci uci num2 if method=="tg", s(i) ||
scatter diff num2 if method=="tg" & strpos(type, "Aqu") ,mcolor(red) msize(small)
xlabel(1(1)85, valuelabel angle(90)) ylabel(-0.05(0.05)0.05,angle(0)) ||
scatter diff num2 if method=="tg" & strpos(type, "Chromo") ,mcolor(blue) msize(small)
xlabel(1(1)85, valuelabel angle(90)) ylabel(-0.05(0.05)0.05,angle(0)) ||
scatter diff num2 if method=="tg" & strpos(type, "viru") ,mcolor(green) msize(small)
xlabel(1(1)85, valuelabel angle(90)) ylabel(-0.05(0.05)0.05,angle(0)) ||
scatter diff num2 if method=="tg" & strpos(type, "ccr") ,mcolor(black) msize(small)
xlabel(1(1)85, valuelabel angle(90) labsize(tiny)) ylabel(-0.05(0.05)0.05,angle(0))
title("Genefinder vs. Typewriter agreement",size(small) )
subtitle("More cases where Genefinder=A and Typewriter=P is positive", size(small))
graphregion(fcolor(white)) xtitle("")
legend(order( 2 3 4 5) label(2 "Aquired Resistance sites") label(3 "Chromosonal mutation sites")
label(4 "Virulence sites") label(5 "Ccr sites" ));
#delimit cr
* save graph
graph export "E:\users\amy.mason\Pipeline_27_07_2016\Graphs_Outputs\method_disagreements_tg.wmf", as(wmf) replace
***********************************************************************
* Compare mykrobe with typewriter
**********************************************************************
noi di "typewriter vs mykrobe"
use pipeline_clean_all_values_wide, clear
* summary table of results
table valuezam valuetypewriter
* totals for calculating mcnemar
gen match = ( valuetypewriter== valuezam)
gen AA=( valuezam=="A" & valuetypewriter=="A")
gen AP=( valuezam=="A" & valuetypewriter=="P")
gen PA=( valuezam=="P" & valuetypewriter=="A")
gen PP=( valuezam=="P" & valuetypewriter=="P")
sort site
* calculate mcnemar chi, is there a significant bias in results
preserve
noi di "McNemar chi"
collapse (count) match (sum) AA AP PA PP summatch= match
for any McNchi pvalue chi95:gen X=.
replace McNchi = ((abs(AP - PA)-1)^2)/(AP+PA)
replace pvalue = 1- chi2(1,McNchi)
replace chi95 = 3.841
gen sig = "Significant" if McNchi> chi95 & McNchi!=.
noi list McNchi pvalue sig if sig!=""
restore
* collapse to produce graph
collapse (count) match (sum) AA AP PA PP summatch= match, by(site type)
* create difference confidence intervals
for any lci uci diff:gen X=.
local max=_N
forvalues i=1(1)`max'{
display site[`i']
local a= AA[`i']
local b= AP[`i']
local c= PA[`i']
local d= PP[`i']
mcci `a' `b' `c' `d'
replace diff = r(D_f) if _n==`i'
replace lci = r(lb_D_f) if _n==`i'
replace uci = r(ub_D_f) if _n==`i'
}
* order by size of difference
gen prop = abs(diff)
gsort -prop
gen num =_n
gen method= "tz"
labmask num, values(site)
save tzdata, replace
* make ordered labels for graph; inverse size of difference
gsort type - prop
gen num2=_n
labmask num2, values(site)
* make graph
#delimit ;
twoway rcapsym lci uci num2 if method=="tz", s(i) ||
scatter diff num2 if method=="tz" & strpos(type, "Aqu") ,mcolor(red) msize(small)
xlabel(1(1)85, valuelabel angle(90)) ylabel(-0.05(0.05)0.05,angle(0)) ||
scatter diff num2 if method=="tz" & strpos(type, "Chromo") ,mcolor(blue) msize(small)
xlabel(1(1)85, valuelabel angle(90)) ylabel(-0.05(0.05)0.05,angle(0)) ||
scatter diff num2 if method=="tz" & strpos(type, "viru") ,mcolor(green) msize(small)
xlabel(1(1)85, valuelabel angle(90)) ylabel(-0.05(0.05)0.05,angle(0)) ||
scatter diff num2 if method=="tz" & strpos(type, "ccr") ,mcolor(black) msize(small)
xlabel(1(1)85, valuelabel angle(90) labsize(tiny)) ylabel(-0.05(0.05)0.05,angle(0))
title("Mykrobe vs. Typewriter agreement",size(small) )
subtitle("More cases where Mykrobe=A and Typewriter=P is positive", size(small) )
graphregion(fcolor(white)) xtitle("")
legend(order( 2 3 4 5) label(2 "Aquired Resistance sites") label(3 "Chromosonal mutation sites")
label(4 "Virulence sites") label(5 "Ccr sites" ));
#delimit cr
* save graph
graph export "E:\users\amy.mason\Pipeline_27_07_2016\Graphs_Outputs\method_disagreements_tz.wmf", as(wmf) replace
***********************************************************************
* Compare mykrobe with genefinder
**********************************************************************
noi di "mykrobe vs genefinder"
use pipeline_clean_all_values_wide, clear
* create summary table
table valuegenefinder valuezam
* create markers to total for mcnemar
gen match = ( valuezam== valuegen)
gen AA=( valuegenefinder=="A" & valuezam=="A")
gen AP=( valuegenefinder=="A" & valuezam=="P")
gen PA=( valuegenefinder=="P" & valuezam=="A")
gen PP=( valuegenefinder=="P" & valuezam=="P")
sort site
* calculate mcnemar chi, is there a significant bias in results
preserve
noi di "McNemar chi"
collapse (count) match (sum) AA AP PA PP summatch= match
for any McNchi pvalue chi95:gen X=.
replace McNchi = ((abs(AP - PA)-1)^2)/(AP+PA)
replace pvalue = 1- chi2(1,McNchi)
replace chi95 = 3.841
gen sig = "Significant" if McNchi> chi95 & McNchi!=.
noi list McNchi pvalue sig if sig!=""
restore
* collapse instead to produce site by site graph
collapse (count) match (sum) AA AP PA PP summatch= match, by(site type)
for any lci uci diff:gen X=.
local max=_N
* calculate confidence intervals for difference
forvalues i=1(1)`max'{
display site[`i']
local a= AA[`i']
local b= AP[`i']
local c= PA[`i']
local d= PP[`i']
mcci `a' `b' `c' `d'
replace diff = r(D_f) if _n==`i'
replace lci = r(lb_D_f) if _n==`i'
replace uci = r(ub_D_f) if _n==`i'
}
* order in by size of difference
gen prop = abs(diff)
gsort -prop
gen num =_n
gen method= "zg"
labmask num, values(site)
save zgdata, replace
* order by reverse difference
gsort type -prop
gen num2=_n
labmask num2, values(site)
* make graph
#delimit ;
twoway rcapsym lci uci num2 if method=="zg", s(i) ||
scatter diff num2 if method=="zg" & strpos(type, "Aqu") ,mcolor(red) msize(small)
xlabel(1(1)85, valuelabel angle(90)) ylabel(-0.05(0.05)0.05,angle(0)) ||
scatter diff num2 if method=="zg" & strpos(type, "Chromo") ,mcolor(blue) msize(small)
xlabel(1(1)85, valuelabel angle(90)) ylabel(-0.05(0.05)0.05,angle(0)) ||
scatter diff num2 if method=="zg" & strpos(type, "viru") ,mcolor(green) msize(small)
xlabel(1(1)85, valuelabel angle(90)) ylabel(-0.05(0.05)0.05,angle(0)) ||
scatter diff num2 if method=="zg" & strpos(type, "ccr") ,mcolor(black) msize(small)
xlabel(1(1)85, valuelabel angle(90) labsize(tiny)) ylabel(-0.05(0.05)0.05,angle(0))
title("Genefinder vs. Mykrobe agreement",size(small) )
subtitle("More cases where Genefinder=A and Mykrobe=P is positive", size(small) )
graphregion(fcolor(white)) xtitle("")
legend(order( 2 3 4 5) label(2 "Aquired Resistance sites") label(3 "Chromosonal mutation sites")
label(4 "Virulence sites") label(5 "Ccr sites" ));
#delimit cr
*save graph
graph export "E:\users\amy.mason\Pipeline_27_07_2016\Graphs_Outputs\method_disagreements_zg.wmf", as(wmf) replace
********************************************************************
*combine the three comparision graphs
********************************************************************
noi di "combine graphs"
* import graph data from above
use tgdata, clear
append using tzdata
append using zgdata
* order sites by abs max diff
sort site
by site: egen ordervalue = total(abs(diff) )
gsort -ordervalue
* create variable to order on graph
gsort method type -ordervalue site
by method: gen newid=_n
order newid
gsort -ordervalue site
labmask newid, values(site)
* change values to percentage (as Sarah's request)
replace diff= diff*100
replace lci = lci *100
replace uci = uci *100
* create graphs for combining so that orders match
#delimit ;
twoway rcapsym lci uci newid if method=="zg", s(i) ||
scatter diff newid if method=="zg" & strpos(type, "Aqu") ,mcolor(red) msize(vsmall)
xlabel(1(1)83, valuelabel angle(90)) ylabel(-5(5)5,angle(0)) ||
scatter diff newid if method=="zg" & strpos(type, "Chromo") ,mcolor(blue) msize(vsmall)
xlabel(1(1)83, valuelabel angle(90)) ylabel(-5(5)5,angle(0)) ||
scatter diff newid if method=="zg" & strpos(type, "viru") ,mcolor(green) msize(vsmall)
xlabel(1(1)83, valuelabel angle(90)) ylabel(-5(5)5,angle(0)) ||
scatter diff newid if method=="zg" & strpos(type, "ccr") ,mcolor(black) msize(vsmall)
xlabel(1(1)83, valuelabel angle(90) labsize(tiny)) ylabel(-5(5)5,angle(0))
title("Genefinder vs. Mykrobe agreement",size(small) )
graphregion(fcolor(white)) xtitle("Gene")
legend(order( 2 3 4 5) label(2 "Genes with aquired resistance") label(3 "Genes with chromosonal mutation")
label(4 "Genes with virulence") label(5 "Genes with CCR" ))
fysize(55)
ytitle("Percentage", size(small)) ;
#delimit cr
*subtitle("More cases where Genefinder=P and Mykrobe=A is positive", size(small) )
graph save graph3, replace
#delimit ;
twoway rcapsym lci uci newid if method=="tg", s(i) ||
scatter diff newid if method=="tg" & strpos(type, "Aqu") ,mcolor(red) msize(vsmall)
xlabel(none) xtitle("") ylabel(-5(5)5,angle(0)) ||
scatter diff newid if method=="tg" & strpos(type, "Chromo") ,mcolor(blue) msize(vsmall)
xlabel(none) xtitle("") ylabel(-5(5)5,angle(0)) ||
scatter diff newid if method=="tg" & strpos(type, "viru") ,mcolor(green) msize(vsmall)
xlabel(none) xtitle("") ylabel(-5(5)5,angle(0))||
scatter diff newid if method=="tg" & strpos(type, "ccr") ,mcolor(black) msize(vsmall)
xlabel(none) xtitle("") ylabel(-5(5)5,angle(0))
title("Genefinder vs. Typewriter agreement",size(small) )
ytitle("Percentage", size(small))
graphregion(fcolor(white)) xtitle("") legend(off) fysize(30);
#delimit cr
graph save graph2, replace
*subtitle("More cases where Genefinder=P and Typewriter=A is positive", size(small) )
#delimit ;
twoway rcapsym lci uci newid if method=="tz", s(i) ||
scatter diff newid if method=="tz" & strpos(type, "Aqu") ,mcolor(red) msize(vsmall)
xlabel(none) xtitle("") ylabel(-5(5)5,angle(0)) ||
scatter diff newid if method=="tz" & strpos(type, "Chromo") ,mcolor(blue) msize(vsmall)
xlabel(none) xtitle("") ylabel(-5(5)5,angle(0)) ||
scatter diff newid if method=="tz" & strpos(type, "viru") ,mcolor(green) msize(vsmall)
xlabel(none) xtitle("") ylabel(-5(5)5,angle(0)) ||
scatter diff newid if method=="tz" & strpos(type, "ccr") ,mcolor(black) msize(vsmall)
xlabel(none) xtitle("") ylabel(-5(5)5,angle(0))
title("Mykrobe vs. Typewriter agreement",size(small) )
ytitle("Percentage", size(small))
graphregion(fcolor(white)) xtitle("")
legend(off)
fysize(30);
#delimit cr
graph save graph1, replace
*subtitle("More cases where Mykrobe=P and Typewriter=A is positive", size(small) )
* combine the graphs
graph combine graph1.gph graph2.gph graph3.gph, cols(1) ycommon
*save the graph
graph export "E:\users\amy.mason\Pipeline_27_07_2016\Graphs_Outputs\method_disagreements_all.wmf", as(wmf) replace
graph export "E:\users\amy.mason\Pipeline_27_07_2016\Graphs_Outputs\method_disagreements_all.eps", as(eps) replace
graph export "E:\users\amy.mason\Pipeline_27_07_2016\Graphs_Outputs\method_disagreements_all_0205.tif", as(tif) width(2880) replace