-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_rsem_3rd.r
5049 lines (4221 loc) · 197 KB
/
run_rsem_3rd.r
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
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# exome sequence vlad
# exome sequence
## cnv gene specific
## facets plot gene specific t2 vs t1
## gene level by t2 vs t1
# rnaseq res.david
## res.david heatmap
## res.david gsea
## res.david dotplot
## immuno convolution analysis based on david
## rnaseq based on david
# for grant 12/21/2017
## rnaseq based on rsem, the whole pipeline
## rnaseq based on rsem
## rnaseq my count results with 11 pairs
## top 1000 variant genes, pca
## top 1000 variant genes heatmap
## top 100 bladder genes
##immune gene target heatmap
##basal luminal classifier genes
## concencus clustering
## pamr
library(log4r)
source('~/program/fun/sync.r')
sync = function(loc1, loc2){ ## sync('exon', 'maftools')
base.selene = '/ifs/work/solitlab/huw/solit/study/hiseq/blca_cmo_06155_2016/'
base.mski1925 = 'mski1925:~/solit/study/hiseq/blca_cmo_06155_2016/'
ll1 = paste0(base.selene, loc1, '/', loc2, '/')
ll2 = paste0(base.mski1925, loc1, '/', loc2, '/')
cmd = paste0('rsync -avur ', ll1, ' ', ll2)
cat(cmd, "\n")
system(cmd)
}
# exome sequence vlad
# neoantigen
vlad.neo = fread('exonseq/Results_Scc/neoantigens/SCC.AllBindersPan_wgenes.9.txt')
vlad.neo[, Dif_Rank := MT.H_Avg_Ranks - WT.H_Avg_Ranks]
vlad.neo[, pat.max.wt.score := max(WT.Score), by = list(Sample, CHROM_POS_REF_ALT)]
vlad.neo[, pat.max.mt.score := max(MT.Score), by = list(Sample, CHROM_POS_REF_ALT)]
vlad.neo.v2 = vlad.neo[!duplicated(Sample, CHROM_POS_REF_ALT),]
vlad.neo.v2
tmp = data.table::melt(vlad.neo.v2[, .(Sample, CHROM_POS_REF_ALT, pat.max.wt.score, pat.max.mt.score)])
tmp[, id := paste0(Sample, "_", CHROM_POS_REF_ALT, "_", toupper(substr(variable, 9, 10))) ]
tmp
tmp2 = data.table::dcast(tmp[, .(Sample, id, value)], Sample ~ id)
tmp2[is.na(tmp2)] = 0
rn = tmp2[,1]
tmp2 = tmp2[, -1]
tmp2[1:4,1:4]
tmp3 = as.data.frame(tmp2); tmp3
tmp3[1:4,1:4]
row.names(tmp3) = rn
tmp3 = as.matrix(tmp3)
tmp3[1:4,1:4]
pdf(file='exonseq/maftools/heatmap_neoantigen.pdf', width=10, height=12)
heatmap.2(tmp3,dendrogram='none', Rowv=FALSE, Colv=FALSE,trace='none')
#pheatmap(as.matrix(vlad.neo.v2.w), scale='none', cluster_col = F, cluster_row = F)
dev.off()
sync('exonseq', 'maftools')
## compare vlad with nick's
scc.maf[, tag:=paste0(Hugo_Symbol, ':', Start_Position)]
fread('exonseq/Results_Scc/variants/SCC.MAF.hg19.AutoFilt.txt') -> vlad.maf
fread('exonseq/Results_Scc/variants/SCC.MAF.hg19.merged.txt') -> vlad.maf
vlad.maf[, tag:=paste0(Hugo_Symbol, ':', Start_Position)]
vlad.maf[, Tumor_Sample_Barcode := sub(".bam", "", Tumor_Sample_Barcode)]
as.data.table(as.data.frame(table(vlad.maf$Tumor_Sample_Barcode))) -> cmp
as.data.table(as.data.frame(table(scc.maf$Tumor_Sample_Barcode))) -> tmp
cmp
merge(cmp, tmp, by.x = 'Var1', by.y='Var1') -> cmp; cmp
setnames(cmp, c('Freq.x', 'Freq.y'), c('chan', 'nick'))
cmp[, dif := nick - chan]
cmp[, id := substr(Var1, 10, 12)]
cmp[, chan.t12 := 0]
cmp[, nick.t12 := 0]
for(i in 1:nrow(cmp)){
id = cmp[i, id]
id1 = paste0('s_DS_bla_', id, '_T1')
id2 = paste0('s_DS_bla_', id, '_T2')
cmp[i, nick.t12 := length(intersect(scc.maf[Tumor_Sample_Barcode == id1,tag], scc.maf[Tumor_Sample_Barcode == id2,tag]))]
cmp[i, vlad.t12 := length(intersect(vlad.maf[Tumor_Sample_Barcode == id1,tag], vlad.maf[Tumor_Sample_Barcode == id2,tag]))]
}
tmp = vlad.maf
colnames(vlad.maf)
vlad.maf[, isMutect := F]
vlad.maf[grep('MT', Caller) & Taf > 0.05, ]
tmp = vlad.maf[grep('MT', Caller), ]
tmp = tmp[ Taf > 0.05 & Tcov > 3,]
tmp[, Var1 := sub(".bam", "", Var1)]
tmp
cmp
setkey(tmp, 'Var1')
setkey(cmp, 'Var1')
cmp = merge(cmp, tmp)
setnames(cmp, 'Freq', 'chan.mutect')
cmp
tmp2 = as.data.table(as.data.frame(table(tmp$Tumor_Sample_Barcode)))
tmp[
cbind(cmp, tmp$Freq)
table(vlad.maf$isMutect)
vlad.maf$Caller[1:10]
fread('exonseq/Results_Scc/variants/SCC.CNT.txt') -> vlad.cnt
sum(vlad.cnt$SNV_merged)
colnames(vlad.cnt)
vlad.maf
# exome sequence
setwd('..')
library(data.table)
library(autospy)
library(WriteXLS)
library(readxl)
library(ggplot2)
library(metafolio)
library(VennDiagram)
library(maftools)
library(Hmisc)
options(width=155)
## /ifs/res/share/solit/alahmadh/Proj_07813_DF
pid = "bla_[0-9]+_"
sid = "_[T|M][0-9]?$"
maffile = "exonseq/Proj_07813_DF/r_001/post/Proj_07813_DF___SOMATIC.vep.filtered.facets.V3.maf"
maffile = "exonseq/scc_oncokb.maf"
scc.maf = fread(maffile)
unique(scc.maf$Variant_Classification)
cn = c("Hugo_Symbol", "Chromosome", "Variant_Classification", "Variant_Type", "Reference_Allele",
"Tumor_Seq_Allele1", 'Tumor_Seq_Allele2','Tumor_Sample_Barcode', 't_depth', 't_ref_count', 't_alt_count',
'n_depth', 'n_ref_count', 'n_alt_count', 'HGVSp_Short')
scc.maf[Variant_Classification == 'Frame_Shift_Del', cn, with=F]
colnames(scc.maf)
## mutsig for mc3
cmd = bsub.head('mutsig', mem=180, cpu=4, We='8:26')
cmd = paste0(cmd, ' "', "/opt/common/CentOS_6-dev/mutsig/cv-1.4/run_MutSigCV.sh /opt/common/CentOS_6-dev/matlab/R2013a/v81/ ../Proj_06230/tcga_mc3_20171217_oncokb_facets_lessc1_trinuc.tsv /opt/common/CentOS_6-dev/mutsig/cv-1.4/lib/exome_full192.coverage.txt /opt/common/CentOS_6-dev/mutsig/cv-1.4/lib/gene.covariates.txt mc3_mutsig /opt/common/CentOS_6-dev/mutsig/cv-1.4/lib/mutation_type_dictionary_file.txt /opt/common/CentOS_6-dev/mutsig/cv-1.4/lib/chr_files_hg19", '"')
cmd
system(cmd)
## mutsig
system(" /opt/common/CentOS_6-dev/mutsig/cv-1.4/run_MutSigCV.sh /opt/common/CentOS_6-dev/matlab/R2013a/v81/ scc_oncokb.maf /opt/common/CentOS_6-dev/mutsig/cv-1.4/lib/exome_full192.coverage.txt /opt/common/CentOS_6-dev/mutsig/cv-1.4/lib/gene.covariates.txt myresults /opt/common/CentOS_6-dev/mutsig/cv-1.4/lib/mutation_type_dictionary_file.txt /opt/common/CentOS_6-dev/mutsig/cv-1.4/lib/chr_files_hg19")
fwrite(scc.maf, file='exonseq/scc_oncokb.maf', sep="\t", quote=F)
# missense putative driver #008000
# missense putative passager #53d400
# truncating driver #000000
# truncating passager #708090
# no alteration #bebebe
# duplication #ff0000
# deletion #ff0000
# inframe driver #993404
# inframe passager #fe9929
# fusion #860009
simple_table = data.table(
simple_value = c('Truncating', 'Truncating', 'Inframe', 'Inframe',
'Missense_Mutation', 'Truncating', 'Inframe',
'Silent', 'Splice_Region', 'Inframe', 'Inframe'),
simple_name = c('Frame_Shift_Del', 'Frame_Shift_Ins', 'In_Frame_Del', 'In_Frame_Ins',
'Missense_Mutation','Nonsense_Mutation', 'Nonstop_Mutation',
'Silent', 'Splice_Region', 'Splice_Site', 'Translation_Start_Site')
)
simple_table[, simple_value := factor(simple_value, levels=c('Truncating', 'Missense_Mutation', 'Inframe'))]
simple_table
setkey(simple_table, 'simple_name')
color_table = data.table(
color_index = c("Missense_Mutation Oncogenic",
"Truncating Oncogenic",
"Inframe Oncogenic",
"Missense_Mutation Passage",
"Truncating Passage",
"Inframe Passage",
"AML",
"DEL",
"Multi_Hit"),
color_value = c("forestgreen",
"black",
"brown4",
adjustcolor("forestgreen", alpha.f=0.6),
adjustcolor("black", alpha.f=0.6),
adjustcolor("brown4", alpha.f=0.6),
"red",
"blue",
"magenta3") )
color_table[, color_index := factor(color_index, levels=c("Missense_Mutation Oncogenic", "Truncating Oncogenic", "Inframe Oncogenic", "Missense_Mutation Passage", "Truncating Passage", "Inframe Passage", "AML", "DEL", 'Multi_Hit') )]
color_vector = color_table$color_value
names(color_vector) = color_table$color_index
color_vector
vc.key = c("Missense_Mutation Oncogenic", "Inframe Oncogenic", "Inframe Passage", "Missense_Mutation Passage", "Truncating Passage", "Truncating Oncogenic", "AML", "DEL", 'Multi_Hit')
setkey(color_table, 'color_index')
oncogenic_table = data.table(
oncogenic_name = c('', 'Likely Neutral', 'Inconclusive', 'Predicted Oncogenic', 'Likely Oncogenic', 'Oncogenic'),
oncogenic_value = factor(c('Passage', 'Passage', 'Passage', 'Oncogenic', 'Oncogenic', 'Oncogenic'), levels=c('Oncogenic', 'Passage')))
setkey(oncogenic_table, 'oncogenic_name')
oncogenic_table
maffile
fread(maffile) -> scc.maf
## export bed files for each patient
scc.maf[, {
pat = .BY
poses = .SD[!duplicated(paste0(Chromosome, Start_Position, End_Position)), .(Chromosome, Start_Position, End_Position + 1)]
poses[, name := paste0(Chromosome, ':', Start_Position, ':', V3)]
poses[, score := 100]
poses[, strands := '+']
poses = poses[order(Chromosome, Start_Position),]
txtfile = paste0('pos_', pat, '.txt')
fwrite(poses, quote=F, sep="\t", row.names=F, file=txtfile, col.names=F)
system(paste0('sort -k1,1 -k2,2n ', txtfile, ' > tmp'))
system(paste0('mv tmp ', txtfile))
}, by='patient']
bamfiles = fread("bamlist", header=F)
bamfiles[, group := substr(basename(V1), 41, 48)]
bamfiles$group
# convert bam to bed
bamfiles[, bam2bed.jobname := paste(basename(V1))]
bamfiles[, bedfile := paste0('bed/', basename(V1), '.bed')]
bamfiles[, bam2bed.cmd := bsub.head(jobname=bam2bed.jobname, We='1:11', cpu=1, mem=6, cwd=getwd()), by = 1:nrow(bamfiles)]
bamfiles[, bam2bed.cmd := paste0(bam2bed.cmd, ' " ', bb, '/bamToBed -i ', V1, ' > ', bedfile, ' "')]
bamfiles$bam2bed.cmd[1]
exe.jobs(bamfiles$bam2bed.cmd, logger)
bamfiles$bam2bed.jobname[1]
# sort bed file
bamfiles[, sortbed.jobname := paste0('sortbed.', basename(V1))]
bamfiles[, bedsorted := paste0('bed/', basename(V1), '.sorted.bed')]
bamfiles[, sortbed.cmd := bsub.head(jobname=sortbed.jobname, We='1:11', cpu=10, mem=56, cwd=getwd(), postdone=bam2bed.jobname), by=1:nrow(bamfiles)]
bamfiles[, sortbed.cmd := paste0(sortbed.cmd, ' " sort -k1,1 -k2,2n ', bedfile, ' > ', bedsorted, ' "')]
bamfiles$sortbed.cmd[1]
exe.jobs(bamfiles$sortbed.cmd, logger)
## read counts corresponding positions for each patient
bb = '/home/huw/program/bedtools2/bin'
bamfiles[, countfile := paste0('bed/', basename(V1), '.count')]
bamfiles[, {
pat = .BY
posfile = paste0('pos_', pat, '.txt')
tmp = copy(.SD)
tmp[, jobname := paste0('count.', basename(V1))]
tmp[, cmd := bsub.head(jobname=jobname, We='1:11', cpu=1, mem=63, cwd=getwd())]
#tmp[, cmd := paste0(cmd, ' " ', bb, '/bedtools coverage -counts -sorted -g ', genomeFasta, '.fai -a ', posfile, ' -b ', V1, ' > ', countfile, '"')]
tmp[, cmd := paste0(cmd, ' " ', bb, '/bedtools coverage -counts -a ', posfile, ' -b ', bedsorted, ' > ', countfile, '"')]
exe.jobs(tmp$cmd, logger)
}, by='group']
bamfiles[, cov.jobname := paste0(basename(V1))]
bamfiles[, outfile := paste0('stats/', basename(V1), '.txt')]
bamfiles
bamfiles[, cmd := bsub.head(jobname=cov.jobname, We='1:11', cpu=1, mem=63, cwd=getwd()), by=1:nrow(bamfiles)]
bamfiles[, cmd := paste0(cmd, ' " ', bb, '/bedtools coverage -a a.bed -b ', V1, ' > ', outfile, '"')]
#bamfiles[,cmd := paste0(cmd, ' " ', BEDTOOLS, '/bedtools coverage -a pos.txt -b ', V1, ' > ', outfile, '"')]
bamfiles$cmd[1]
exe.jobs(bamfiles$cmd[1], logger)
bamfiles[, {
pat = .BY
posfile = paste0('pos_', pat, '.txt')
tmp = copy(.SD)
tmp[, jobname := paste0('count.', basename(V1))]
tmp[, cmd := bsub.head(jobname=jobname, We='1:11', cpu=1, mem=63, cwd=getwd())]
#tmp[, cmd := paste0(cmd, ' " ', bb, '/bedtools coverage -counts -sorted -g ', genomeFasta, '.fai -a ', posfile, ' -b ', V1, ' > ', countfile, '"')]
tmp[, cmd := paste0(cmd, ' " ', bb, '/bedtools coverage -counts -a ', posfile, ' -b ', bedsorted, ' > ', countfile, '"')]
exe.jobs(tmp$cmd, logger)
}, by='group']
#fread(maffile) -> bak
IMPACT468 <- scan("/ifs/depot/resources/dmp/data/mskdata/interval-lists/VERSIONS/cv6/genelist", what = "")
scc.maf[, IMPACT_468 := Hugo_Symbol %in% IMPACT468]
## reassign Variant_Classification for simple version
scc.maf[, id := paste(Variant_Classification, oncogenic, sep=" ")]
setkey(scc.maf, 'Variant_Classification')
scc.maf = scc.maf[simple_table,]
table(scc.maf$simple_value)
## reassign oncogenic value
setkey(scc.maf, 'oncogenic')
scc.maf = scc.maf[oncogenic_table, ]
table(scc.maf$oncogenic_value)
## assign color
scc.maf[, id := paste(simple_value, oncogenic_value, sep=' ')]
setkey(scc.maf, 'id')
scc.maf = scc.maf[color_table,]
table(scc.maf$color_value)
scc.maf[, Variant_Classification_old := Variant_Classification]
scc.maf[, Variant_Classification := id]
scc.maf[t_alt_count > 3 & t_alt_count / t_depth >0.05,] -> scc.maf.fil
scc.maf.fil
fwrite(scc.maf.fil, file='scc_maf_fil.txt', sep="\t")
## gene level facets copy number results
cn.table = fread('exonseq/autospy/genelevel_facets_cnv.txt')
cn.table = cn.table[, .(Hugo_Symbol, Tumor_Sample_Barcode, Variant_Type)]
fwrite(cn.table, file='cntable.txt', sep="\t", quote=F)
head(cn.table)
cn.table[Hugo_Symbol == 'BRCA',]
## clinical data
clin = data.table(Tumor_Sample_Barcode = unique(scc.maf.fil[,Tumor_Sample_Barcode]))
clin[, Cell_Type := sub(".*_", "", Tumor_Sample_Barcode)]
fwrite(clin, file='clinical.txt', sep="\t", quote=F)
clin
#read.maf(scc.maf.fil, cnTable='cntable.txt') -> scc.maf.o
#fread('scc_maf_fil.txt') -> a
#read.maf('scc_maf_fil.txt') -> scc.maf.o
read.maf('scc_maf_fil.txt', clinicalData='clinical.txt', vc_nonSyn = vc.key) -> scc.maf.o
as.character(scc.maf.o@data$Tumor_Sample_Barcode) -> tsb
tsb.t1 = tsb[grep("T1", tsb)]
tsb.t2 = tsb[grep("T2", tsb)]
scc.maf.t1.o = subsetMaf(scc.maf.o, tsb=tsb.t1, mafObj = T)
scc.maf.t2.o = subsetMaf(scc.maf.o, tsb=tsb.t2, mafObj = T)
scc.maf.fil[Hugo_Symbol == 'KMT2D', .(Tumor_Sample_Barcode, Hugo_Symbol, Variant_Classification, Variant_Classification_old, oncogenic)]
table(scc.maf.o@data$Variant_Classification)
# most amplied known function
mut.2017 = c('TP53', 'RB1', 'RHOB', 'PIK3CA', 'KDM6A', 'TSC1', 'ELF3', 'KMT2D', 'CREBBP', 'CDKN1A', 'EP300', 'ZFP36L1', 'ARID1A', 'STAG2', 'CDKN2A', 'HRAS', 'KRAS', 'FBXW7', 'ERCC2', 'ASXL2', 'RHOA', 'KMT2A', 'FGFR3', 'NFE2L2', 'KMT2C', 'PSIP1', 'KANSL1', 'C3orf70', 'FAT1', 'SPTAN1', 'RXRA', 'ZBTB7B', 'PTEN', 'ATM', 'KLF5', 'PARD3', 'CUL1', 'NRAS', 'SF3B1', 'GNA13', 'RBM10', 'ACTB', 'MBD1', 'CASP8', 'HIST1H3B', 'TAF11', 'ERBB2', 'NUP93', 'SF1', 'ERBB3', 'METTL3', 'SPN', 'MB21D2', 'SSH3', 'USP28', 'ASXL1', 'TMCO4', 'HES1', 'ZNF773')
mut.2014 = c('TP53', 'MLL2', 'ARID1A', 'KDM6A', 'PIK3CA', 'EP300', 'CDKN1A', 'RB1', 'ERCC2', 'FGFR3', 'STAG2', 'ERBB3', 'FBXW7', 'RXRA', 'ELF3', 'NFE2L2', 'TSC1', 'KLF5', 'TXNIP', 'FOXQ1', 'CDKN2A', 'RHOB', 'FOXA1', 'PAIP1', 'BTG2', 'HRAS', 'ZFP36L', 'RHOA', 'CCND3')
amp.2013 = c('AHR', 'BCL2L1', 'CCND1', 'CCNE1', 'E2F3', 'EGFR', 'ERBB2', 'FGFR3', 'GATA3', 'KRAS', 'MDM2', 'MYCL1', 'PPARG', 'PVRL4', 'SOX4', 'TERT', 'YWHAZ', 'ZNF703')
## plot summary
maffile = "exonseq/Proj_07813_DF/r_001/post/Proj_07813_DF___SOMATIC.vep.filtered.facets.V3.maf"
fread(maffile) -> tmp
tmp[t_alt_count > 3 & t_alt_count / t_depth >0.05,] -> tmp
read.maf(tmp) -> tmp.o
plotmafSummary(tmp.o, rmOutlier=T, addStat = 'median', dashboard = T, file='exonseq/maftools/maftools_summary_scc.pdf', width=10)
subsetMaf(tmp.o, tsb=tsb.t1, mafObj = T) -> tmp.t1.o
plotmafSummary(tmp.t1.o, rmOutlier=T, addStat = 'median', dashboard = T, file='exonseq/maftools/maftools_summary_scc_t1', width=10)
subsetMaf(tmp.o, tsb=tsb.t2, mafObj = T) -> tmp.t2.o
plotmafSummary(tmp.t2.o, rmOutlier=T, addStat = 'median', dashboard = T, file='exonseq/maftools/maftools_summary_scc_t2', width=10)
rm(tmp, tmp.o, tmp.t1.o, tmp.t2.o)
w = 12; h = 8
mut.2017.sel = c('KMT2D', 'TP53', 'PIK3CA', 'ATM', 'ARID1A', 'EP300', 'FGFR3', 'STAG2', 'KDM6A', 'KMT2C',
'RB1', 'CUL1', 'ELF3', 'ERBB3', 'KMT2A', 'NFE2L2', 'RHOA', 'ACTB', 'CREBBP', 'SPTAN1')
pdf('maftools/oncoplot_mut2017.pdf', width=w, height=h)
oncoplot(maf = scc.maf.o, genes=mut.2017.sel, color = color_vector, showTumorSampleBarcodes=F, top=20, clinicalFeatures='Cell_Type')
dev.off()
unique(scc.maf.t1.o@data$Tumor_Sample_Barcode)
w = 8; h = 8
pdf('maftools/oncoplot_t1.pdf', width=w, height=h)
oncoplot(maf = scc.maf.t1.o, genes=mut.2017.sel, color = color_vector, showTumorSampleBarcodes=F, top=20)
dev.off()
pdf('maftools/oncoplot_t2.pdf', width=w, height=h)
oncoplot(maf = scc.maf.t2.o, genes=mut.2017.sel, color = color_vector, showTumorSampleBarcodes=F, top=20)
dev.off()
system('rsync -avur maftools/ -e ssh mski1925:/Volumes/LaCie/huw/solit/study/hiseq/blca_cmo_06155_2016/exonseq/maftools/')
scc.maf[t_alt_count > 3 & t_alt_count / t_depth >0.05,] -> scc.maf.fil
tmp = read.maf(scc.maf.fil)
pdf('exonseq/maftools/lolli_kmt2d.pdf', width=6, height=3)
lollipopPlot(scc.maf.o, gene='KMT2D', cBioPortal=F, colors = color_vector)
dev.off()
sync('exonseq/maftools')
## tcga blca
tcga_sc_id = c('TCGA-BT-A0YX-01A', 'TCGA-BT-A20U-01A', 'TCGA-BT-A2LD-01A', 'TCGA-C4-A0F1-01A', 'TCGA-C4-A0F7-01A', 'TCGA-CU-A0YN-01A',
'TCGA-DK-A2I2-01A', 'TCGA-FD-A3B5-01A', 'TCGA-FD-A3N5-01A', 'TCGA-G2-A2ES-01A', 'TCGA-G2-A3IB-01A', 'TCGA-GC-A3I6-01A',
'TCGA-GD-A3OS-01A', 'TCGA-BT-A42E', 'TCGA-GU-A42Q', 'TCGA-FD-A43Y', 'TCGA-FD-A5BU', 'TCGA-K4-A4AC', 'TCGA-FD-A5BY', 'TCGA-PQ-A6FI',
'TCGA-GU-A766', 'TCGA-CU-A72E', 'TCGA-E7-A7XN', 'TCGA-XF-A8HE', 'TCGA-YC-A89H', 'TCGA-E7-A97P', 'TCGA-XF-A8HH', 'TCGA-ZF-A9RE',
'TCGA-ZF-AA4W', 'TCGA-4Z-AA80', 'TCGA-4Z-AA82', 'TCGA-4Z-AA89', 'TCGA-XF-A9SJ', 'TCGA-XF-A9T4', 'TCGA-XF-A9T8', 'TCGA-ZF-AA53',
'TCGA-XF-AAME', 'TCGA-XF-AAMH', 'TCGA-XF-AAMT', 'TCGA-XF-AAN2', 'TCGA-XF-AAN5', 'TCGA-ZF-A9RD', 'TCGA-ZF-A9RG', 'TCGA-BT-A20X-01A',
'TCGA-FD-A3B4-01A', 'TCGA-FD-A3N6-01A')
tcga_sc_id = sub("-01A", "", tcga_sc_id)
length(unique(tcga_sc_id))
tcga_basal_id = c('TCGA-DK-A3WW', 'TCGA-SY-A9G5', 'TCGA-DK-A2I4', 'TCGA-E7-A7XN', 'TCGA-XF-A9T8', 'TCGA-XF-A9T5', 'TCGA-ZF-AA4V', 'TCGA-BT-A0YX', 'TCGA-DK-AA6S',
'TCGA-UY-A9PB', 'TCGA-4Z-AA7W', 'TCGA-4Z-AA84', 'TCGA-BT-A3PJ', 'TCGA-XF-A8HD', 'TCGA-ZF-AA4W', 'TCGA-BT-A20J', 'TCGA-FD-A3SS', 'TCGA-XF-AAN2',
'TCGA-XF-A9SY', 'TCGA-DK-A3IU', 'TCGA-G2-A2ES', 'TCGA-XF-A8HE', 'TCGA-XF-A9T3', 'TCGA-DK-A3IN', 'TCGA-DK-AA6L', 'TCGA-FD-A3SN', 'TCGA-FD-A3SO',
'TCGA-FD-A5BX', 'TCGA-GC-A3RC', 'TCGA-XF-A9SI', 'TCGA-HQ-A5NE', 'TCGA-K4-A5RJ', 'TCGA-K4-A6FZ', 'TCGA-BT-A3PK', 'TCGA-DK-AA6R', 'TCGA-FD-A3N5',
'TCGA-E7-A7DV', 'TCGA-UY-A8OB', 'TCGA-XF-AAN5', 'TCGA-XF-A9T6', 'TCGA-XF-A9SJ', 'TCGA-UY-A78P', 'TCGA-G2-A2EJ', 'TCGA-DK-A2I6', 'TCGA-FD-A3B6',
'TCGA-G2-A2EF', 'TCGA-XF-A9SM', 'TCGA-GC-A3YS', 'TCGA-ZF-A9RF', 'TCGA-CF-A1HS', 'TCGA-G2-AA3C', 'TCGA-4Z-AA7Q', 'TCGA-CU-A3KJ', 'TCGA-GC-A6I1',
'TCGA-DK-AA74', 'TCGA-E5-A2PC', 'TCGA-4Z-AA86', 'TCGA-4Z-AA81', 'TCGA-ZF-AA58', 'TCGA-DK-A1AB', 'TCGA-UY-A78L', 'TCGA-E7-A97P', 'TCGA-GU-A766',
'TCGA-ZF-AA54', 'TCGA-K4-A5RH', 'TCGA-GU-A42Q', 'TCGA-ZF-A9RN', 'TCGA-BT-A42F', 'TCGA-GC-A3I6', 'TCGA-BT-A20O', 'TCGA-ZF-AA53', 'TCGA-C4-A0F1',
'TCGA-BT-A42E', 'TCGA-ZF-A9RD', 'TCGA-GU-AATQ', 'TCGA-FD-A3NA', 'TCGA-FT-A61P', 'TCGA-UY-A9PA', 'TCGA-FD-A3B3', 'TCGA-XF-AAN3', 'TCGA-ZF-AA4N',
'TCGA-CU-A0YN', 'TCGA-FD-A6TH', 'TCGA-BL-A5ZZ', 'TCGA-GV-A40E', 'TCGA-GC-A3WC', 'TCGA-K4-A4AC', 'TCGA-PQ-A6FI', 'TCGA-FD-A3B5', 'TCGA-FD-A5C1',
'TCGA-FD-A6TD', 'TCGA-LC-A66R', 'TCGA-K4-A5RI', 'TCGA-FD-A3SP', 'TCGA-GU-A764', 'TCGA-E7-A3X6', 'TCGA-FT-A3EE', 'TCGA-DK-A6B5', 'TCGA-DK-A2I2',
'TCGA-FD-A6TK', 'TCGA-DK-A1AE', 'TCGA-FD-A3N6', 'TCGA-FD-A5BT', 'TCGA-DK-AA6Q', 'TCGA-4Z-AA82', 'TCGA-BT-A2LD', 'TCGA-GD-A3OQ', 'TCGA-GU-A762',
'TCGA-CU-A72E', 'TCGA-ZF-AA56', 'TCGA-BL-A13I', 'TCGA-UY-A8OC', 'TCGA-XF-A9SX', 'TCGA-XF-AAMT', 'TCGA-BT-A20V', 'TCGA-G2-A3IB', 'TCGA-FD-A62N',
'TCGA-HQ-A5ND', 'TCGA-C4-A0F0', 'TCGA-GV-A3QG', 'TCGA-DK-A3IM', 'TCGA-BT-A20U', 'TCGA-BT-A20X', 'TCGA-PQ-A6FN', 'TCGA-FD-A3B7', 'TCGA-FD-A5BU',
'TCGA-FD-A62S', 'TCGA-DK-AA6M', 'TCGA-FD-A3B4', 'TCGA-ZF-AA5H', 'TCGA-FD-A43Y', 'TCGA-ZF-AA5N', 'TCGA-FD-A5BY', 'TCGA-DK-A3WX', 'TCGA-XF-A9T4',
'TCGA-XF-AAN4', 'TCGA-XF-AAMW', 'TCGA-FD-A3B8', 'TCGA-FD-A5BS', 'TCGA-XF-AAME', 'TCGA-DK-A3WY', 'TCGA-XF-AAN8');
tcga_sc_basal_id = c(tcga_sc_id, tcga_basal_id)
head(tcga_sc_basal_id)
length(unique(tcga_sc_basal_id)) ## 151
# import tcga blca data
mc3.blca.file = '../../tcga/tcga_mc3_blca_20170830_facets.tsv'
fread(mc3.blca.file) -> mc3.blca
mc3.blca[, vaf := t_alt_count / t_depth]
dim(mc3.blca)
mc3.blca=mc3.blca[t_alt_count > 3 & t_depth > 8 & vaf > 0.05,]
mc3.blca[, bcr := substr(mc3.blca$Tumor_Sample_Barcode, 1, 12)]
length(unique(mc3.blca$bcr))
length(unique(mc3.blca$Tumor_Sample_Barcode))
dim(mc3.blca)
mc3.blca.sb = mc3.blca[bcr %in% tcga_sc_basal_id,] # squamous and basal cell
mc3.blca.nn = mc3.blca[!(bcr %in% tcga_sc_basal_id),] # non basal and squamous cell
dim(mc3.blca.sb) # 47247
dim(mc3.blca.nn) # 86527
nrow(mc3.blca.sb) / length(unique(mc3.blca.sb$Tumor_Sample_Barcode)) # 319 per case
nrow(mc3.blca.nn) / length(unique(mc3.blca.nn$Tumor_Sample_Barcode)) # 346 per case
blca.clin = data.table(Tumor_Sample_Barcode = unique(mc3.blca$Tumor_Sample_Barcode))
blca.clin[, cellType := 'Uro']
blca.clin[, bcr := substr(Tumor_Sample_Barcode, 1, 12)]
blca.clin[bcr %in% tcga_basal_id, cellType := 'Basal']
blca.clin[bcr %in% tcga_sc_id, cellType := 'Sq']
blca.clin[bcr %in% intersect(tcga_sc_id, tcga_basal_id), cellType := 'Basal & Sq']
blca.clin
fwrite(blca.clin, file='blca.clin.txt', sep="\t", quote=F)
mc3.blca[, id := paste(Variant_Classification, oncogenic, sep=" ")]
setkey(mc3.blca, 'Variant_Classification')
mc3.blca = mc3.blca[simple_table,]
mc3.blca
table(mc3.blca$simple_val)
## reassign oncogenic value
setkey(mc3.blca, 'oncogenic')
mc3.blca = mc3.blca[oncogenic_table, ]
table(mc3.blca$oncogenic_value)
## assign color
mc3.blca[, id := paste(simple_val, oncogenic_value, sep=' ')]
setkey(mc3.blca, 'id')
mc3.blca = mc3.blca[color_table,]
table(mc3.blca$color_value)
mc3.blca[, Variant_Classification_old := Variant_Classification]
mc3.blca[, Variant_Classification := id]
read.maf(mc3.blca, clinicalData=blca.clin, vc_nonSyn = vc.key) -> mc3.blca.o
mc3.blca.sb.o = subsetMaf(mc3.blca.o, tsb = unique(mc3.blca.sb$Tumor_Sample_Barcode), mafObj = T) # squmous or basal
mc3.blca.nn.o = subsetMaf(mc3.blca.o, tsb = unique(mc3.blca.nn$Tumor_Sample_Barcode), mafObj = T) # non squmouse or basal
mc3.blca.sq.o = subsetMaf(mc3.blca.o, tsb = unique(mc3.blca[bcr %in% tcga_sc_id, Tumor_Sample_Barcode]), mafObj = T) # squamous
mc3.blca.sq1.o = subsetMaf(mc3.blca.o, tsb = unique(mc3.blca[bcr %in% setdiff(tcga_sc_id, tcga_basal_id), Tumor_Sample_Barcode]), mafObj = T) # squamous
mc3.blca.ba1.o = subsetMaf(mc3.blca.o, tsb = unique(mc3.blca[bcr %in% setdiff(tcga_basal_id, tcga_sc_id), Tumor_Sample_Barcode]), mafObj = T) # squamous
mc3.blca.ba.o = subsetMaf(mc3.blca.o, tsb = unique(mc3.blca[bcr %in% tcga_basal_id, Tumor_Sample_Barcode]), mafObj = T) # basal
mc3.blca.2sb.o = subsetMaf(mc3.blca.o, tsb = unique(mc3.blca[bcr %in% intersect(tcga_basal_id, tcga_sc_id), Tumor_Sample_Barcode]), mafObj = T) # samples have both basal and squamouse cell types
ll = c('TP53', 'KMT2D', 'ARID1A', 'KDM6A', 'PIK3CA', 'KMT2C', 'RB1', 'STAG2', 'EP300', 'ATM', 'FGFR3', 'SPTAN1', 'ERBB2', 'ELF3', 'CREBBP', 'FAT1', 'KMT2A', 'ERBB3', 'ERCC2', 'CDKN1A')
w = 22; h = 7
pdf('maftools/oncoplot_mc3_blca_mut2017.pdf', width=w, height=h)
tmp = oncoplot(maf = mc3.blca.o, genes=ll, color = color_vector, showTumorSampleBarcodes=F, top=20, clinicalFeatures='cellType', fontSize=8)
dev.off()
system('rsync -avur maftools/ -e ssh mski1925:/Volumes/LaCie/huw/solit/study/hiseq/blca_cmo_06155_2016/exonseq/maftools/')
w = 15; h = 7
ll = c('TP53', 'ARID1A', 'KDM6A', 'KMT2D', 'PIK3CA', 'KMT2C', 'STAG2', 'FGFR3', 'SPTAN1', 'ELF3', 'ATM', 'RB1', 'EP300', 'ERBB2', 'ERBB3', 'CREBBP', 'FAT1', 'CDKN1A', 'TSC1', 'KMT2A')
pdf('maftools/oncoplot_mc3_blca_uro_mut2017.pdf', width=w, height=h)
oncoplot(maf = mc3.blca.nn.o, genes=ll, color = color_vector, showTumorSampleBarcodes=F, top=20, clinicalFeatures='cellType', fontSize=8)
dev.off()
system('rsync -avur maftools/ -e ssh mski1925:/Volumes/LaCie/huw/solit/study/hiseq/blca_cmo_06155_2016/exonseq/maftools/')
pdf('maftools/oncoplot_mc3_blca_BaSq_mut2017.pdf', width=w, height=h)
oncoplot(maf = mc3.blca.sb.o, genes=mut.2017, color = color_vector, showTumorSampleBarcodes=F, top=20, clinicalFeatures='cellType')
dev.off()
w = 7; h = 7
ll = c('TP53', 'KMT2D', 'KDM6A', 'KMT2C', 'PIK3CA', 'STAG2', 'FAT1', 'ATM', 'NFE2L2', 'CDKN2A', 'ERBB2', 'RB1', 'RXRA', 'ARID1A', 'FBXW7', 'FGFR3', 'KMT2A', 'CREBBP', 'ERBB3', 'ERCC2')
pdf('maftools/oncoplot_mc3_blca_Sq_mut2017.pdf', width=w, height=h)
oncoplot(maf = mc3.blca.sq.o, genes=ll, color = color_vector, showTumorSampleBarcodes=F, top=20, clinicalFeatures='cellType', fontSize=8, legendFontSize=7, annotationFontSize=7, annotationTitleFontSize=7)
dev.off()
system('rsync -avur maftools/ -e ssh mski1925:/Volumes/LaCie/huw/solit/study/hiseq/blca_cmo_06155_2016/exonseq/maftools/')
## test
pdf('exonseq/maftools/oncoplot_mc3_test.pdf', width=w, height=h)
tmp = oncoplot(maf = mc3.blca.sq.o, genes=ll, color = color_vector, showTumorSampleBarcodes=T, top=20, clinicalFeatures='cellType', fontSize=8, legendFontSize=7, annotationFontSize=7, annotationTitleFontSize=7)
dev.off()
sync('exonseq', 'maftools')
blca.cc -> blca.cc.v2
colnames(blca.cc.v2) = substr(colnames(blca.cc), 1, 12)
substr(colnames(tmp@ht_list$matrix_3@matrix), 1, 12) -> tmp.cn
ov = intersect(colnames(blca.cc.v2), tmp.cn)
blca.cc.v2['ENSG00000167548', ov]
intersect(colnames(blca.cc.v2), colnames(tmp@ht_list$matrix_3@matrix))
substr(colnames(blca.cc.v2), 1, 10)
substr(colnames(tmp@ht_list$matrix_3@matrix), 1, 10)
intersect(substr(colnames(blca.cc.v2), 1, 10),substr(colnames(tmp@ht_list$matrix_3@matrix), 1, 10))
blca.cc['ENSG00000167548', colnames(tmp@ht_list$matrix_3@matrix)]
pdf('maftools/oncoplot_mc3_blca_Ba_mut2017.pdf', width=w, height=h)
oncoplot(maf = mc3.blca.ba.o, genes=mut.2017, color = color_vector, showTumorSampleBarcodes=F, top=20, clinicalFeatures='cellType')
dev.off()
pdf('maftools/oncoplot_mc3_blca_2sb_mut2017.pdf', width=w, height=h)
oncoplot(maf = mc3.blca.2sb.o, genes=mut.2017, color = color_vector, showTumorSampleBarcodes=F, top=20, clinicalFeatures='cellType')
dev.off()
pdf('maftools/oncoplot_mc3_bblca_sq1_mut2017.pdf', width=w, height=h) ## only squmaouse
oncoplot(maf = mc3.blca.sq1.o, genes=mut.2017, color = color_vector, showTumorSampleBarcodes=F, top=20, clinicalFeatures='cellType')
dev.off()
ll = c('TP53', 'KMT2D', 'RB1', 'ARID1A', 'PIK3CA', 'EP300', 'KMT2C', 'KDM6A', 'KMT2A', 'CREBBP', 'ERBB2', 'ERCC2', 'ATM', 'ERBB3', 'FAT1', 'ELF3', 'NFE2L2', 'CDKN1A', 'PARD3', 'SPTAN1')
w = 10; h = 7
pdf('maftools/oncoplot_mc3_bblca_ba1_mut2017.pdf', width=w, height=h) ## only squmaouse
oncoplot(maf = mc3.blca.ba1.o, genes=ll, color = color_vector, showTumorSampleBarcodes=F, top=20, clinicalFeatures='cellType', fontSize=8, legendFontSize=7, annotationFontSize=7, annotationTitleFontSize=7)
dev.off()
system('rsync -avur maftools/ -e ssh mski1925:/Volumes/LaCie/huw/solit/study/hiseq/blca_cmo_06155_2016/exonseq/maftools/')
w = 10; h = 27
pdf('maftools/oncoplot_mc3_bblca_ba1_mut2017_moregenes.pdf', width=w, height=h) ## only squmaouse
oncoplot(maf = mc3.blca.ba1.o, genes=mut.2017, color = color_vector, showTumorSampleBarcodes=F, top=20, clinicalFeatures='cellType', fontSize=8, legendFontSize=7, annotationFontSize=7, annotationTitleFontSize=7)
dev.off()
system('rsync -avur maftools/ -e ssh mski1925:/Volumes/LaCie/huw/solit/study/hiseq/blca_cmo_06155_2016/exonseq/maftools/')
system("find /ifs/res/taylorlab/tcga_wes_facets/blca_2017/ -name '*hisens.out' > aa")
fread("aa", header=F) -> out
out
out$purity = sapply(out$V1, function(x){system(paste("grep Purity ", x, " |sed 's/# Purity = //' "), intern=T)})
out$ploidy = sapply(out$V1, function(x){system(paste("grep Ploidy ", x, " |sed 's/# Ploidy = //' "), intern=T)})
out[, bcr := substr(basename(V1), 1, 12)]
out[, cellType := 'Uro']
out[bcr %in% tcga_sc_id, cellType := 'Sq']
out[bcr %in% setdiff(tcga_basal_id, tcga_sc_id), cellType := 'Ba']
out[, .(cellType, ploidy), by=cellType]
out[, ploidy := as.numeric(ploidy)]
## no difference
anova(as.data.frame(out[, .(cellType, ploidy)]))
aggregate(out$ploidy, by=list(out$cellType), )
out[ploidy > 2.5,] -> tmp
x1 = aggregate(rep(1,nrow(out)), by=list(out$cellType), sum); x1
x2 = aggregate(rep(1,nrow(tmp)), by=list(tmp$cellType), sum); x2
x2$x/x1$x
out[, cellType := factor(cellType, levels=c('Uro', 'Sq', 'Ba'))]
g = ggplot(out, aes(x =cellType, y = ploidy))
g = g + geom_jitter(width=0.2)
g = g + stat_summary(fun.data = "mean_cl_boot", geom='crossbar', width=.5, mapping=aes(group='cellType', colour = "red"),size=1, show.legend = F)
g = g + ylab('Ploidy') + ggtitle("Anova p < 0.01)") + xlab('')
g = g + theme(plot.title = element_text(face="bold", size=10, hjust=.5))
ggsave(g, file=paste0('maftools/ploidy_tcga_blca.pdf'), width=3, height=4)
system('rsync -avur maftools/ -e ssh mski1925:/Volumes/LaCie/huw/solit/study/hiseq/blca_cmo_06155_2016/exonseq/maftools/')
out$cellType
summary(aov(out$ploidy~ out$cellType))
## tcga rnaseq comparing uro to squamous cell, basal type cases
load("../../bcg/tcga_blca.RData")
tmp = assay(blca.data)
indi = substr(colnames(tmp), 1, 12)
design = data.frame(tsb = colnames(tmp), celltype = rep('Uro', ncol(tmp)), stringsAsFactors=F)
design$celltype[indi %in% tcga_sc_id] = 'Sq'
design$celltype[indi %in% setdiff(tcga_basal_id, tcga_sc_id)] = 'Ba'
design$celltype = factor(design$celltype, levels=c('Uro', 'Sq', 'Ba'))
ddsmat = DESeqDataSetFromMatrix(countData = tmp,
colData = design,
design = ~ celltype);
dds.ds <- estimateSizeFactors(ddsmat);
dds <- DESeq(dds.ds, parallel=T);
table(design$celltype)
res.sq = results(dds, contrast = c('celltype', 'Sq', 'Uro'), nrow=nrow(tmp))
res.sq = res.sq[order(res.sq$padj),]
res.sq$symbol = blca.rows[row.names(res.sq), 'external_gene_name']
head(res.sq)
res.sq[grep("gata3", res.sq$symbol, ignore.case=T),]
aggregate(tmp['ENSG00000107485',], by=list(design$celltype), mean)
aggregate(tmp['ENSG00000229647',], by=list(design$celltype), mean)
res.ba = results(dds, contrast = c('celltype', 'Ba', 'Uro'), nrow=nrow(tmp))
res.ba$symbol = blca.rows[row.names(res.ba), 'external_gene_name']
res.ba = res.ba[order(res.ba$padj),]
res.ba[grep("gata3", res.ba$symbol, ignore.case=T),]
res.ba[grep("foxa1", res.ba$symbol, ignore.case=T),]
res.ba[grep("ppar", res.ba$symbol, ignore.case=T),]
res.ba[grep("KMT2D", res.ba$symbol, ignore.case=T),]
blca.cc = counts(dds, normalized = T)
blca.cc = as.data.frame(tmp.cc)
blca.cc = tmp.cc
p3 =blca.cc[c('ENSG00000167548', 'ENSG00000107485', 'ENSG00000129514', 'ENSG00000132170'),]
p3 = as.data.table(p3)
genes = c('KMT2D', 'GATA3', 'FOXA1', 'PPARG')
p3[, gene := factor(genes, levels = genes)]
p3[1:4,1:2]
p3 = melt(p3)
p3[, bcr := substr(variable, 1, 12)]
p3[, celltype := 'Carcinoma']
p3[bcr %in% tcga_sc_id, celltype := 'Squamous']
p3[bcr %in% setdiff(tcga_basal_id, tcga_sc_id), celltype := 'Basal']
p3[, celltype := factor(celltype, levels=c('Carcinoma', 'Basal', 'Squamous'))]
p3[, log2Reads := log2(value+1)]
p3
gg = ggplot(data = p3, aes(celltype, log2Reads)) +
geom_jitter(width=.2) +
stat_summary(fun.data = "mean_cl_boot", geom='crossbar', width=.5, mapping=aes(group='celltype', colour = "red"),size=1, show.legend = F) +
xlab('') + ylab('Log2 # Reads') + facet_grid(. ~ gene)
ggsave(gg, file="maftools/three_gene.pdf", width=9, height=4)
system('rsync -avur maftools/ -e ssh mski1925:/Volumes/LaCie/huw/solit/study/hiseq/blca_cmo_06155_2016/exonseq/maftools/')
## methylation, see the solit/study/tcga/tcga.r folder
## see hiseq/tcga
cc = c('Hugo_Symbol', 'Tumor_Sample_Barcode', 'HGVSp_Short', 'Variant_Classification')
scc.maf[Hugo_Symbol %in% genes, cc, with=F]
##
t1.gs = row.names(scc.maf.t1.o@oncoMatrix)[1:50]
t2.gs = row.names(scc.maf.t2.o@oncoMatrix)[1:50]
intersect(t1.gs, t2.gs)
setdiff(t2.gs, t1.gs)
setdiff(t1.gs, t2.gs)
t1.gs = row.names(scc.maf.t1.o@oncoMatrix)[1:250]
t2.gs = row.names(scc.maf.t2.o@oncoMatrix)[1:250]
t1.gs.i = t1.gs[t1.gs %in% IMPACT468]
t2.gs.i = t2.gs[t2.gs %in% IMPACT468]
intersect(t1.gs, t2.gs)
setdiff(t2.gs, t1.gs)
setdiff(t1.gs, t2.gs)
scc.maf.ip = scc.maf.fil[IMPACT_468 == T, ]
scc.maf.t1.ip = scc.maf.t1[IMPACT_468 == T, ]
scc.maf.t2.ip = scc.maf.t2[IMPACT_468 == T, ]
scc.maf.ip.o =read.maf(scc.maf.ip)
scc.maf.t1.ip.o =read.maf(scc.maf.t1.ip)
scc.maf.t2.ip.o =read.maf(scc.maf.t2.ip)
pdf('oncoplot_impact_all.pdf', width=w, height=h)
oncoplot(maf = scc.maf.ip.o, top=top)
dev.off()
pdf('oncoplot_t1_impact.pdf', width=w, height=h)
oncoplot(maf = scc.maf.t1.ip.o, top=top)
dev.off()
pdf('oncoplot_t2_impact.pdf', width=w, height=h)
oncoplot(maf = scc.maf.t2.ip.o, top=top)
dev.off()
## for autospy
## adjusted:
scc.maf[ccf_Mcopies > 0.3] -> tmp
ds202.t1 = tmp[Tumor_Sample_Barcode == 's_DS_bla_202_T1', Hugo_Symbol]
ds202.t2 = tmp[Tumor_Sample_Barcode == 's_DS_bla_202_T2', Hugo_Symbol]
ds202.m1 = tmp[Tumor_Sample_Barcode == 's_DS_bla_202_M1', Hugo_Symbol]
setdiff(ds202.m1, c(ds202.t1, ds202.t2)) # m1 unique 16
setdiff(ds202.t1, c(ds202.m1, ds202.t2)) # t1 unique 44
setdiff(ds202.t2, c(ds202.m1, ds202.t1)) # t1 unique 44
setdiff(intersect(ds202.m1, ds202.t2), ds202.t1) # t1 unique 44
intersect(ds202.t2, intersect(ds202.m1, ds202.t1)) # t1 unique 44
ds211.t1 = tmp[Tumor_Sample_Barcode == 's_DS_bla_211_T1', Hugo_Symbol]
ds211.t2 = tmp[Tumor_Sample_Barcode == 's_DS_bla_211_T2', Hugo_Symbol]
ds211.t1
ds211.t2
intersect(ds211.t1, ds211.t2) # t1 unique 44
setdiff(ds211.t1, ds211.t2) # t1 unique 44
setdiff(ds211.t2, ds211.t1) # t1 unique 44
fread(maffile) -> scc.maf
IMPACT468 <- scan("/ifs/depot/resources/dmp/data/mskdata/interval-lists/VERSIONS/cv6/genelist", what = "")
scc.maf.fil[, IMPACT_468 := Hugo_Symbol %in% IMPACT468]
scc.maf[, Variant_Bioportal := paste0(Variant_Classification, oncogenic)]
scc.maf.fil[, patient := stringr::str_extract(Tumor_Sample_Barcode, pid)]
scc.maf.fil[, sample := stringr::str_extract(Tumor_Sample_Barcode, sid)]
dim(scc.maf.fil)
scc.maf.fil[, t_var_freq := as.numeric(t_alt_count) / t_depth]
scc.maf.fil[, tm := paste0(Hugo_Symbol, " ", as.numeric(gsub("[^\\d]+", "", HGVSp_Short, perl=T)))] #
scc.maf.fil[, TAG := paste0('chr', Chromosome, ':', Start_Position, '-', End_Position, ':', Reference_Allele, ':', Tumor_Seq_Allele2)]
scc.maf.fil[, variant := paste0(TAG, '::', Hugo_Symbol, ':', HGVSp_Short)]
sampleID = data.table(`Sample ID` = unique(scc.maf.fil$Tumor_Sample_Barcode))
sampleID[, `Sample Class` := 'Primary']
sampleID[grep("T2", `Sample ID`), `Sample Class` := 'Tumor']
sampleID[grep("M", `Sample ID`), `Sample Class` := 'Tumor']
sampleID[, patient := stringr::str_extract(`Sample ID`, pid)]
sampleID[, sample := stringr::str_extract(`Sample ID`, sid)]
sampleID
o = getwd()
setwd('exonseq/autospy')
IMPACT410 <- scan("/ifs/depot/resources/dmp/data/mskdata/interval-lists/VERSIONS/cv5/genelist", what = "")
IMPACT410
##
source('~/program/autospy/R/process_autopsy_maf.R')
source('~/program/autospy/R/stratton_plot.R')
### refilter
filter_results <- filter_maf_report(scc.maf.fil)
dim(scc.maf.fil)
scc.maf.fil <- filter_results$maf
nrow(tmp)
nrow(scc.maf.fil)
write.table(scc.maf.fil, 'filtered.maf', sep="\t", quote=F, row.names=F)
### overlap plot
make_mutation_overlap_plot(scc.maf.fil, pid = pid, log = F, out = "pre_filter")
## mutation signature
cmd = 'python ~/program/autospy/inst/mutation-signatures/main.py --seed 100 ~/program/autospy/inst/mutation-signatures/Stratton_signatures29.txt filtered.maf signature.out'
system(cmd)
fread("signature.out") -> mut.sig
fwrite(filter_results$report, file='report.txt', sep="\t", quote=F)
ggsave(plot_mutation_signatures(mut.sig, pid, sid, fraction_threshold = 0.5),
filename='mutation_singaure_decompoisition_combined.pdf', width=5, height=6)
### patient wise
patients = unique(scc.maf.fil$patient)
tumor_samples = unique(scc.maf.fil$Tumor_Sample_Barcode)
for(pat in patients){
primary <- sampleID[patient == pat & `Sample Class` == 'Primary', `Sample ID`]
primary
pat.maf <- scc.maf.fil[patient== pat,]
pat.maf
print(paste("make_variant_classification_plot for patient ", pat))
make_variant_classification_plot(pat.maf, out = pat)
print("make_ccf_plots")
make_ccf_plots(pat.maf, tumor_samples)
print("make_stratton_plots")
make_stratton_plots(pat.maf, tumor_samples, out = pat)
print("make_binary_tree")
print("make_mutation_signatures")
write.table(pat.maf, 'pat.maf', sep="\t", quote=F, row.names=F)
cmd = paste0('python ~/program/autospy/inst/mutation-signatures/main.py --seed 100 ')
cmd = paste0(cmd, '~/program/autospy/inst/mutation-signatures/Stratton_signatures29.txt pat.maf signature.out')
system(cmd)
fread("signature.out") -> mut.sig
ggsave(plot_mutation_signatures(mut.sig, pid, sid, fraction_threshold = 0.5),
filename=paste0('mutation_singaure_decompoisition_', pat, '.pdf'), width=5, height=6)
samples = unique(pat.maf$sample)
sample_pairs <- combn(samples, 2, simplify = F)
dir.create('ccf_2d_plots')
for(sample_pairs in sample_pairs){
make_ccf_2d(pat.maf,
sample_pairs,
out = pat,
directory = 'ccf_2d_plots')
}
}
for(pat in patients){
primary <- sampleID[patient == pat & `Sample Class` == 'Primary', `Sample ID`]
pat.maf <- scc.maf.fil[patient== pat,]
make_binary_tree(pat.maf, primary, hotspots = autospy::hotspots, vertical = TRUE, margins = TRUE, out = pat)
}
### maftools
scc.maf.fil.o = read.maf(scc.maf.fil)
plotmafSummary(scc.maf.fil.o, rmOutlier=T, addStat = 'median', dashboard = T, file='maftools_summary.pdf')
patients = unique(scc.maf.fil$Tumor_Sample_Barcode)
lapply(unique(patients),
function(tsb){
maftools::rainfallPlot(scc.maf.fil.o, tsb = tsb, savePlot = T)
})
scc.maf.fil$sample
intersect(unique(scc.maf.t1$Hugo_Symbol), unique(scc.maf.t2$Hugo_Symbol))
setdiff(unique(scc.maf.t1$Hugo_Symbol), unique(scc.maf.t2$Hugo_Symbol))
setdiff(unique(scc.maf.t2$Hugo_Symbol), unique(scc.maf.t1$Hugo_Symbol))
unique(scc.maf.t1$Hugo_Symbol)
scc.maf.t1$Hugo_Symbol
scc.maf.t2$Hugo_Symbol
## exonseq/autospy
## cnv
IMPACT341_targets <- suppressWarnings(fread(paste0('grep -v "^@" /ifs/depot/resources/dmp/data/mskdata/interval-lists/VERSIONS/cv6/picard_targets.interval_list')))
setnames(IMPACT341_targets, c("chr", "start", "end", "strand", "name"))
IMPACT341_targets[, symbol := sub("_.*", "", name)]
IMPACT341_targets[, gene.start := min(start), by=symbol][, gene.end := max(end), by = symbol]
IMPACT341_targets = IMPACT341_targets[!duplicated(symbol),]
IMPACT341_targets
source('~/program/facets-suite/geneLevel.R')
fread('cncf_hisens.list', header=F) -> genelevel
genelevel = setNames(genelevel, 'cncfFile')
genelevel[, cncfFile := paste0('../', cncfFile)]
genelevel[, bcr := str_extract(cncfFile, "DS_bla_..._[T|M][0-9]?")]
genelevel[, outfile := paste0('genelevel/', bcr, '.genelevel')]
genelevel[, infofile := sub("cncf.txt", "out", cncfFile)]
genelevel[, rdatafile := sub("out", "Rdata", infofile)] #
dir.create('genelevel')
head(genelevel)
genelevel[, {
cnv = get_gene_level_calls(cncf_files = cncfFile)
cnv[, Tumor_Sample_Barcode := bcr]
fwrite(cnv, file=outfile, sep="\t", quote=F, row.names=F)
}, by=1:nrow(genelevel)]
cnv.list = lapply(genelevel$outfile, fread)
rbindlist(cnv.list) -> all.cnv
head(all.cnv)
dim(all.cnv)
all.cnv = all.cnv[ !is.na(FACETS_CNA) & FACETS_CNA != 0,]
all.cnv
all.cnv = all.cnv[, Variant_Classification := 'CNV']
all.cnv = all.cnv[, Variant_Type := 'AMP']
all.cnv = all.cnv[FACETS_CNA < 0, Variant_Type := 'DEL']
fwrite(all.cnv, file='genelevel_facets_cnv.txt', row.names=F, sep="\t", quote=F)
colnames(all.cnv)
head(all.cnv)
# facets ploidy and purity inforation
facet.info = data.table(bcr = genelevel$bcr)
facet.info$purity = sapply(genelevel$infofile, function(x){system(paste("grep Purity ", x, " |sed 's/# Purity = //' "), intern=T)})
facet.info$ploidy = sapply(genelevel$infofile, function(x){system(paste("grep Ploidy ", x, " |sed 's/# Ploidy = //' "), intern=T)})
facet.info[, purity := as.numeric(purity)]
facet.info[, ploidy := as.numeric(ploidy)]
facet.info[, sampletype := substr(bcr, 12, 13)]
facet.info[, patient := substr(bcr, 1, 10)]
facet.info[grep('188', bcr),]
facet.info[grep('202', bcr),]
# ploidy
facet.info
tmp = facet.info[grep("M", bcr, invert=T),]
tmp.w = dcast(tmp, patient ~ sampletype, value.var='ploidy'); tmp.w
mbar = apply(tmp.w[,2:3], 2, median, na.rm=T)
mbar = as.data.table(mbar)
g = ggplot(tmp, aes(x = sampletype, y = ploidy))
g = g + geom_jitter(width=0.2)
g = g + geom_segment(data=mbar, aes(x = c(.7, 1.7), y = mbar, xend = c(1.3, 2.3), yend = mbar), alpha=.5, lwd=1.5, colour='blue')
g = g + geom_segment(data=tmp.w, aes(x = 1.2, y = T1, xend = 1.8, yend = T2), alpha=0.2, colour='red')
g = g + ylab('Ploidy') + ggtitle("wilcox rank test(paired, p=0.01755)") + xlab('')
g = g + theme(plot.title = element_text(face="bold", size=10, hjust=.5))
ggsave(g, file=paste0('../maftools/ploidy.pdf'), width=3, height=4)
tmp.w
wilcox.test(tmp.w$T1, tmp.w$T2, paired=T)
gg = ggplot(data=facet.info[grep("M", bcr, invert=T),], aes(x = sampletype, y = ploidy)) + geom_point()
ggsave(file="../maftools/ploidy.pdf", width=3, height=4)
facet.info$ploidy
all.cnv[, patient := substr(Tumor_Sample_Barcode, 1, 10)]
all.cnv[, sampletype := substr(Tumor_Sample_Barcode, 12, 13)]
tmp = all.cnv[Hugo_Symbol == gene, .(sampletype,Variant_Type)];tmp
table(tmp)
chisq.test(unlist(tmp[,1]), unlist(tmp[,2]))
tmp
tmp[,1]
tmp[,2]
# cnv gene specific
all.cnv
genes = c('GATA3', 'FOXA1', 'PPARG')
source('~/program/facets-suite/fPlots_ggplot2.R')
tmp = all.cnv[Hugo_Symbol %in% genes[3], .(Tumor_Sample_Barcode, Hugo_Symbol, sampletype, Variant_Type, patient, FACETS_CNA)];tmp
tmp.w = dcast(tmp, patient ~ sampletype, value.var='FACETS_CNA'); tmp.w
for(gene in genes){
tmp = all.cnv[Hugo_Symbol %in% gene, .(Tumor_Sample_Barcode, Hugo_Symbol, sampletype, Variant_Type, patient, FACETS_CNA)];tmp
tmp.w = dcast(tmp, patient ~ sampletype, value.var='FACETS_CNA'); tmp.w
for(pat in tmp.w$patient){
patient = paste0(pat, '_T1')
load(genelevel[bcr == patient, rdatafile])
plot.facets.all.output(out, fit, type='png', main=paste0(patient, '| cval: 100'), plotname=paste0('../maftools/', patient, '_', gene), gene.name=gene)
patient = paste0(pat, '_T2')
load(genelevel[bcr == patient, rdatafile])
plot.facets.all.output(out, fit, type='png', main=paste0(patient, '| cval: 100'), plotname=paste0('../maftools/', patient, '_', gene), gene.name=gene)
}
}
tmp.w[is.na(T1), T1 := 0]
tmp.w[is.na(T2), T2 := 0];tmp.w
tmp.w = tmp.w[T2 - T1 != 0,]; tmp.w
tmp.w[, dd := T2 -T1]
tmp.w
tmp.w$T2 - tmp.w$T1
melt(tmp.w) -> tmp; colnames(tmp) = c('patient', 'sampletype', 'FACETS_CNA'); tmp
mbar = apply(tmp.w[,2:3], 2, median, na.rm=T)
mbar = as.data.table(mbar); mbar
g = ggplot(tmp, aes(x = sampletype, y = FACETS_CNA))
g = g + geom_jitter(width=0.1)
g = g + geom_segment(data=mbar, aes(x = c(.7, 1.7), y = mbar, xend = c(1.3, 2.3), yend = mbar), alpha=.5, lwd=1.5, colour='blue')
g = g + geom_segment(data=tmp.w, aes(x = 1.2, y = T1, xend = 1.8, yend = T2), alpha=0.2, colour='red')
g = g + ylab('CNV') + ggtitle(gene) + xlab('')
g = g + theme(plot.title = element_text(face="bold", size=10, hjust=.5))
ggsave(g, file=paste0('../maftools/cnv_', gene, '.pdf'), width=3, height=4)
wilcox.test(tmp.w$T1, tmp.w$T2, paired=T)
table(all.cnv[Hugo_Symbol == 'GATA3', .(sampletype, Variant_Type)])
unique(all.cnv$Tumor_Sample_Barcode)
out = export.oncoprint(maf, cnv, res.cc, res.sig)
dim(out)
fwrite(out, file='output_4_oncoprint.txt', sep="\t", quote=F)
##
library(VennDiagram)
scc.maf[grep('202', Tumor_Sample_Barcode),] -> tmp
tmp = tmp[, .(Tumor_Sample_Barcode, Hugo_Symbol)]
tmp$patient = substr(tmp$Tumor_Sample_Barcode, 3, 12)
tmp$celltype = substr(tmp$Tumor_Sample_Barcode, 14, 15)
tmp.m = tmp[grep('M1', Tumor_Sample_Barcode), Hugo_Symbol]
tmp.t1 = tmp[grep('T1', Tumor_Sample_Barcode), Hugo_Symbol]
tmp.t2 = tmp[grep('T2', Tumor_Sample_Barcode), Hugo_Symbol]
tmp.m
pdf("exonseq/autospy/DS_bla_202_ven.pdf", width=8, height=8)
grid.newpage()
draw.triple.venn(area1 = length(unique(tmp.t1)),
area2 = length(unique(tmp.t2)),
area3 = length(unique(tmp.m)),
n12 = length(intersect(tmp.t1, tmp.t2)),
n23 = length(intersect(tmp.t2, tmp.m)),
n13 = length(intersect(tmp.t1, tmp.m)),
n123 = length(intersect(intersect(tmp.t1, tmp.t2), tmp.m)),
category = c("T1", "T2", "M1"), scaled=T)
dev.off()
#merge(all.cnv, scc.maf.fil, by = 'Tumor_Sample_Barcode') -> scc.maf.cnv
## export for oncoprint
## http://www.cbioportal.org/oncoprinter.jsp#
## Sample Gene
## Alteration Type
## R248W MISSENSE
## R306fs TRUNC
## MCN237del INFRAME
## FUSION FUSION
## HOMDEL CNA
## HETLOSS CNA
## GAIN CNA
## AMP CNA
## UP EXP
## DOWN EXP
export.oncoprint = function(maf, cnv, res.cc, res.sig){
maf.sel = maf[, .(Tumor_Sample_Barcode, Hugo_Symbol, Variant_Classification, Variant_Type, HGVSp_Short)]
IMPACT468 <- scan("/ifs/depot/resources/dmp/data/mskdata/interval-lists/VERSIONS/cv6/genelist", what = "")
maf.sel[, IMPACT_468 := Hugo_Symbol %in% IMPACT468]
maf.sel = maf.sel[IMPACT_468 == T, ]
#write.table(unique(maf.sel$Variant_Classification), '~/program/fun/oncoprint_table', quote=F, sep="\t")
fread("~/program/fun/oncoprint_table", header = T) -> tbl
setkey(tbl, 'Variant_Classification')
setkey(maf.sel, 'Variant_Classification')
maf.sel.2 = maf.sel[tbl,]
maf.sel.2 = maf.sel.2[!is.na(Type),]
maf.sel.2[, Alteration := sub("p.", "", HGVSp_Short)]
maf.sel.2$Alteration
## CNA
## HOMDEL CNA
## HETLOSS CNA
## GAIN CNA
## AMP CNA
cnv = all.cnv
cnv = cnv[, .(Tumor_Sample_Barcode, Hugo_Symbol, chr, Variant_Classification, Variant_Type, tcn, lcn, FACETS_CNA)]
cnv = cnv[, Type := 'CNA']
cnv = cnv[FACETS_CNA == 1, Alteration := 'GAIN']
cnv = cnv[FACETS_CNA > 1, Alteration := 'AMP']
cnv = cnv[FACETS_CNA == -1, Alteration := 'HETLOSS']
cnv = cnv[FACETS_CNA < -1, Alteration := 'HOMDEL']
cnv = cnv[chr == 'X' & FACETS_CNA == -1, Alteration := 'HOMDEL']
cnv = cnv[chr == 'X' & FACETS_CNA > 0, Alteration := 'AMP']
out = rbind(maf.sel.2[, .(Tumor_Sample_Barcode, Hugo_Symbol, Alteration, Type)],cnv[, .(Tumor_Sample_Barcode, Hugo_Symbol, Alteration, Type)])
res.cc.sig = res.cc[row.names(res.sig),]
rs = apply(res.cc.sig, 1, mean)
res.cc.sig = res.cc.sig[rs > 100,]
dim(res.cc.sig)
res.cc.sig.sd = apply(res.cc.sig, 1, sd)
res.cc.sig.zscore = t(apply(res.cc.sig, 1, scale))
colnames(res.cc.sig.zscore) = colnames(res.cc.sig)
res.cc.sig.zscore > 1.96