-
Notifications
You must be signed in to change notification settings - Fork 1
/
analysis_export.R
2732 lines (2405 loc) · 151 KB
/
analysis_export.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
# [Results] ####
#= Analysis of output .Rda of _marginS_ on GCE i-4 or _marginFree_ on GCE i-4Free
# or i-4Plus
# >*** [choice ONE]: _marginFree_ or _marginS_ loading from .Rda
#marginTag <- "_marginS_" #at ./marginS
#marginTag <- "_marginFree_" #at ./marginFree
#marginTag <- "_marginPlus_" #at ./marginPlus
TCGA_cohort <- "HNSCC" # start-over again [2020/03/08]
raw <-
readline("_margin(S)_, _marginFree(F)_ or _margin(P)lus_ -- process run: ")
select_margin <- function(x) {
switch(x,
s = "_marginS_",
f = "_marginFree_",
p = "_marginPlus_",
S = "_marginS_",
# F = "_marginFree_",
P = "_marginPlus_",
stop("Unknown input")
)
}
marginTag <- select_margin(raw)
print(marginTag)
rm(raw)
# [2019/07/03-2019/07/22] they are stored at ./xlsx => moved to ./marginS
# [2019/07/03-2019/07/22] they are stored at ./xlsx => moved to ./marginFree
# [2019/07/03-2019/07/22] they are stored at ./xlsx => moved to ./marginPlus
# [2019/07/30-2019/08/09] they are stored at ./xlsx => moved to ./marginS/tobacco
# set path to the source of .Rda from cutoff finding
path_cohort <- getwd() # "/home/tex/R/HNSCC_Tex_survival/hnscc_github"
path_ZSWIM2 <- file.path(path_cohort, gsub("_", "", marginTag), "") # e.x. marginS/
# ZSWIM2_archive1000_20180408_0042_0933.Rda; 9 hours for 1,000 genes to be scanned
# 3 hours for 1,000 genes to be scanned under GCP Rstudio server
# STRAP to SLC8A1
#which(whole_genome==geneName)
#
#_marginS_
# x merge ZSWIM2a ZSWIM2b and ZSWIM2c => ZSWIM2abc_archive.Rda [2018/06/19]
# para_seg <- c(20499, 13528, 6833, 1) # ZZZ3-> PLCE1, PNMT-> GARNL3, GAR1-> A1BG
#load(file=file.path(path_cohort, "ZSWIM2_archive.Rda")) # as ZSWIM2
#ZSWIM2 <- ZSWIM2abc #(done, merged)
#save(data=ZSWIM2, file=file.path(path_ZSWIM2, "ZSWIM2_archive.Rda")) # or ZSWIM2abc_archive
#x OR
# _marginFree_
#load(file="ZSWIM2_free_archive.Rda") # as well as ZSWIM2
#(at the first time)
#>Dissection of ZSWIM2 ####
#1) KM plot is not at best cutoff, why??
#2) ZSWIM2 should be saved by appending.
#3)
load(file=file.path(path_cohort, "ZSWIM2_archive.Rda")) # x merged abc
ZSWIM2$X3 <- addNA(ZSWIM2$X2, ifany=F)
ZSWIM2_2 <- table(ZSWIM2$X3) # try to tryCatch (1, 2)
# 0 1 2 3 4 5 6 7 8 9
# 682 64 187 26 23 21 9 18 13 14
# 10 11 12 13 14 15 16 17 18 19
# 14 10 12 10 5 6 5 6 2 5
# 20 21 22 23 24 25 26 27 28 29
# 3 5 1 4 2 3 1 2 5 2
# 30 31 34 35 36 37 40 41 44 49
# 3 3 3 2 2 2 1 1 1 1
# 51 52 57 60 66 <NA>
# 1 2 1 1 1 19314
ZSWIM2_2 <- data.frame(ZSWIM2_2)
#ZSWIM2_2$Freq[46] <- ZSWIM2_2$Freq[46] - (17406+(LUAD_n-18602)) #number of NA:11, from TRIL(18602) to "STX10"(17406)
#print(run16h <- (sum(ZSWIM2_2$Freq)-(LUAD_n-(18602-17406))))
# running 18602-17406=1196 genes in 16 hours
plot((ZSWIM2_2))
sum(ZSWIM2_2$Freq)
#[1] 20500 # scan completely
# why error_01: whole_genome[ZSWIM2$X2 == 1]
#
# Only reture(0) is ok for subsequent analyses
pielabels <- sprintf("%s", ZSWIM2_2$Freq[ZSWIM2_2$Freq>0])
pie_colors <- c("yellow", "green", "violet",
"orange", "blue", "pink", "cyan","red")
text_pie <- paste("Workable genes \n in", pie_colors[1], "(", round(ZSWIM2_2$Freq[1]/sum(ZSWIM2_2$Freq)*100), "% of whole genome)") # _marginS_ about 45.9% usable RNAseq data
# n=9416
pie(ZSWIM2_2$Freq[ZSWIM2_2$Freq>0],
labels=NA,
clockwise=F,
col=pie_colors,
border="white",
radius=0.7,
cex=0.8,
main=text_pie)
legend("bottomright", legend=pielabels, bty="n",
fill=pie_colors)
# brewer.pal(7,"Set1") # from RColorBrewer::brewer.pal()
#browsers<-read.table("browsers.txt",header=TRUE)
#browsers<-browsers[order(browsers[,2]),]
#pielabels <- sprintf("%s = %3.1f%s", browsers[,1],
# 100*browsers[,2]/sum(browsers[,2]), "%")
#pie(ZSWIM2_2$Freq, labels=ZSWIM2_2$Var1, main=text_pie)
#
# deal with return(1), return(2) and return(3) errors, try to solve it
# _marginS_
n_percent_Bonferroni <- ZSWIM2_2$Freq[1]/sum(ZSWIM2_2$Freq) # 0.4593171 -> 0.4581951
error01_sample <- which(ZSWIM2$X3==1) # 32.2% error01: "ZSWIM2 skip from contingencyTCGA()"): one group issue in Melt()
# => *** re-run
error02_sample <- which(ZSWIM2$X3==2) # 14.2% error02: There has only one group in survdiff.
error03_sample <- which(ZSWIM2$X3==3) # 6.85% error03: There has only one group in survdiff on KM cutofFinder_func.R.
#=> Test for difference (log-rank test is multiple Chi-square alone survival time) with P-value; or Test for different KM curve between two groups (seperated by PMM1_median 0 vs 1)
error05_sample <- which(ZSWIM2$X3==5) # 0.78%(159 genes) error05: for why?
# done #
# #debug {CoxPH table 3, univariate 全部是同一個值 from gender to tobacco} only RNAseq 是正確的 [2019/08/14]
# >A summary table of P-value, Z-score standardization from all HNSCC_survival*.Rda ####
# 不必每次重 run (saved at HNSCC_OS_marginS_pvalueKM_candidate_cox.Rda)
# go ahead post2, a simple way for p.adjut() =>
# _marginFree_ or _marginS_ or _marginPlus_ from .Rda
# number of OS_pvalue: from cutoff finder, the number (frequency) of OS P-values, which KM P-value < 0.05, in each gene;
# get_Rda_pvalue <- function(geneName) {
# load(file=paste("HNSCC_survivalAnalysis_marginS_", geneName, ".Rda", sep=""))
# # load list = c("tableChi1", "tableOS1", "tableRFS1", "OS_pvalue", "RFS_pvalue")
# # a example: geneName <- "TRIP13"
# #OS_pvalue$p_OS[which.min(OS_pvalue$p_OS)]
#
# if (nrow(OS_pvalue) > 0) { # we hit this gene with P-value < 0.05 in KM plot
# return(min(OS_pvalue$p_OS))} else {return(NA)}
# }
# candidate_sample(KM) and candidate_cox (Cox list or Cox table), two parts
# candidate_sample: Kaplan–Meier plots for genes significantly associated with survival.
# Table1: list genes, which it's KM plot with P-value < 0.05, and ranking by P-value (ascending) and z-score (decending)
aa <- LUAD_n; bb<- 1
#aa <- ZSWIM2_2$Freq[1] # n=9416
# however, $ ls HNSCC_sur*.Rda | wc -l
# 16017
#{ declare empty data.frame and list
#*
candidate_sample <- data.frame(matrix(data = NA, nrow = aa, ncol = 3)) # for num, gene ID and it's P-value
colnames(candidate_sample) <- c("number", "gene_id", "p_value") # KM OS P-value only (there is no DFS in HNSCC);
#x"number" position in ZSWIM2
#xcandidate_sample$number <- data.frame(which(ZSWIM2$X3==0)) # gene "number"
candidate_sample$gene_id <- whole_genome[bb:aa] # retrieving gene name from whole_genome; return() at X2
#
#* a list for all cox survival datas
# http://www.cookbook-r.com/Manipulating_data/Converting_between_data_frames_and_contingency_tables/
# column name might be created by variable: e.x. df.sex[,"per"] <- df.sex$count1/sum(df.sex$count1); # df.sex$per
candidate_cox <- replicate(aa, list()) # empty list(), which doesn't need colnames
#data.table(matrix(data = NA, nrow = aa, ncol = 3)) # for num, gene ID and it's P-value
# colnames(candidate_cox) <- c( "Features", "HR", "P_value_uni", "sig", "Features", "HR",
# "P_value_multi", "sig", "Features", "P_value_KM", "sig" )
# #}
setwd(paste(path_ZSWIM2, "Rda", sep="")) # set for a while (for ip loop) at ./marginS/Rda
# * all .Rda 要先解壓縮 HNSCC.survival.marginS.20500.tar.gz
# retrieved then saved as HNSCC_OS_marginS_pvalueKM_candidate_cox.Rda
for (ip in (bb:aa)) { # 3 hours for each run
geneName <- candidate_sample$gene_id[ip]
#print(paste("At", path_ZSWIM2, "=> (", ip, ")", geneName), sep="")
#candidate_sample$p_value <- lapply(unlist(candidate_sample$gene_id[bb:aa]), get_Rda_pvalue) # retrieving P-value by gene name from .Rda; return() at X3
#[choice ONE]: _marginFree_ or _marginS_ loading from .Rda
# _marginS_
# aka: "HNSCC_survivalAnalysis_marginS_DKK1.Rda"
# list = c("tableChi1", "tableOS1", "tableRFS1", "OS_pvalue", "RFS_pvalue")
load_filename <- file.path(paste(TCGA_cohort, "_survivalAnalysis", marginTag, geneName, ".Rda", sep=""))
#OR (automatically defined)
#_marginFree_
#load_filename <- paste("HNSCC_survivalAnalysis_marginS_", geneName, ".Rda", sep="")
#
#
if (load_filename %in% dir()) {
load(file=load_filename)
# if (is.na(tryCatch(load(file=load_filename), error = function(e) return(NA)))) {} # load file with error free :-)
# load(file=paste("HNSCC_survivalAnalysis_marginS_", geneName, ".Rda", sep=""))
# load list = c("tableChi1", "tableOS1", "tableRFS1", "OS_pvalue", "RFS_pvalue")
# a example: geneName <- "TRIP13"
print(paste(marginTag, ", there is ", nrow(OS_pvalue), " OS P-values (uncorrected)"))
# create a temp variable: OS_pvalueS
OS_pvalueS <- as.data.frame(matrix(NA, nrow=nrow(OS_pvalue), ncol=3))
colnames(OS_pvalueS) <- c("p_value", "p_value_adj_bonferroni", "p_value_adj_FDR")
OS_pvalueS$p_value <- OS_pvalue$p_OS
OS_pvalueS$p_value_adj_bonferroni <- p.adjust(OS_pvalue$p_OS, method='bonferroni')
OS_pvalueS$p_value_adj_FDR <- p.adjust(OS_pvalue$p_OS, method='fdr')
if ((nrow(OS_pvalue) > 0) & any(OS_pvalueS$p_value_adj_FDR < 0.05)) {
candidate_sample$p_value[ip] <- min(OS_pvalueS$p_value_adj_FDR) # most sigificant P-value => 要改為 min(FDR P-value)
# for 20500 genes comparison, candidate_sample$p_value 仍須要再一次 Bonferroni correction
candidate_sample$number[ip] <- nrow(OS_pvalueS[OS_pvalueS$p_value_adj_FDR<0.05, ])
#number of OS_pvalue: from cutoff finder, the number (frequency) of OS P-values, which KM P-value < 0.05, in each gene;
}
#candidate_sample$p_value[ip] <- get_Rda_pvalue(candidate_sample$gene_id[ip]) # retrieving P-value by gene name from .Rda; return() at X3
# print(paste(ip, geneName, ": ", candidate_sample$p_value[ip], sep=" "))
#***
# Significant features from table 2, table 3 and table 4 of output .Rda files ##
#{
# [uni_cox_pvalue and uni_HR]
# [multi_cox_pvalue and multi_HR]
# [exp_pvalue]
# from tableChi1 (Table 2), tableOS1 (Table 3) /[tableRFS1]
# focusing on tableOS1, Cox proportiopnal hazard model: (both univariate and multivariate) P-value <= 0.05,
# and sorted by HR > 1 vs HR < 1
# P-value notes:
# Significant codes: 0 ???***??? 0.001 ???**??? 0.01 ???*??? 0.05 ???.??? 0.1 ??? ??? 1
# if <0.001 => mark as "***"
# osHR$X4[osHR$X4<0.001] <- "***"
# uni_cox_pvalue
uni_cox_pvalue <- tableOS1[c(FALSE, TRUE), c(1,2,5)] # get significant P-value, hazard ratio at column 2
uni_cox_pvalue$`P-value` <- as.character(uni_cox_pvalue$`P-value`)
uni_cox_pvalue$`P-value`[(uni_cox_pvalue$`P-value` == "***")] <- "0.001"
uni_cox_pvalue$`P-value` <- as.numeric(uni_cox_pvalue$`P-value`)
uni_cox_pvalue$sig <- uni_cox_pvalue$`P-value` <= 0.05 # "sig" marking for significant
# multi_cox_pvalue
multi_cox_pvalue <- tableOS1[c(FALSE, TRUE), c(1,6,9)] # get significant P-value, hazard ratio at column 6
multi_cox_pvalue$`P-value` <- as.character(multi_cox_pvalue$`P-value`)
multi_cox_pvalue$`P-value`[(multi_cox_pvalue$`P-value` == "***")] <- "0.001"
multi_cox_pvalue$`P-value` <- as.numeric(multi_cox_pvalue$`P-value`)
multi_cox_pvalue$sig <- multi_cox_pvalue$`P-value` <= 0.05 # "sig" marking for significant
# *** we don't have RFS in HNSCC cohort :-)
# and tableChi1: P-value <= 0.05 # exp_pvalue
# "sig" marking the significant "features": check "odd" position
exp_pvalue <- tableChi1[c(TRUE, FALSE), c(1,7)] # get significant P-value from column 7, name from column 1; remark at column 8
exp_pvalue$`P-value` <- as.numeric(as.character(exp_pvalue$`P-value`))
exp_pvalue$sig <- exp_pvalue$`P-value` <= 0.05 # "sig" marking for significant
# # merging them as one by common row names
# > colnames(exp_pvalue)
exp1 <- data.frame("X1"= geneName, "X2" = NA, "X3"=NA) # append one row, with this geneName
colnames(exp1) <- colnames(exp_pvalue) # precisely matched
candidate_cox_ip <- cbind(uni_cox_pvalue, multi_cox_pvalue, rbind(exp_pvalue, exp1)) # colname is duplicated, bind 3 tables together
colnames(candidate_cox_ip) <- c( "uni_Features", "uni_HR", "uni_P_value", "uni_sig", "multi_Features", "multi_HR",
"multi_P_value", "multi_sig", "KM_Features", "KM_P_value", "KM_sig") # KM_sig is Remark at table 2(tableChi1)
# it must be [[]] for assign the content !!! https://stat.ethz.ch/R-manual/R-devel/library/base/html/Extract.html.
candidate_cox[[ip]] <- candidate_cox_ip #http://cran.r-project.org/doc/manuals/R-lang.html#Indexing
print(paste(ip, geneName, ": cox features saved; ncol = ", length(candidate_cox[[ip]]))) # a vector in [] is ok for indexing
# length == 11 => that is correct !
#}
}
} # end of ip for loop
# #[2019/06/26] _marginS_ finished at 19:48 (about 3 hours)
# #[2020/03/12] _marginS_ finished at 01:00 (about 3 hours) with Bonferroni and FDR P-value correction
# n=6429
#_marginS_ or _marginFree_ by SFree; saving on ./run04_marginS_, files => 17030
save(candidate_sample, candidate_cox, n_percent_Bonferroni,
file=file.path(path_ZSWIM2, paste(TCGA_cohort, "_OS", marginTag, "pvalueKM_candidate_cox.Rda", sep=""))) #ok; with KM_sig and Remark, and Cox HR
setwd(path_cohort)
#_marginS_ by marginTag
# saved file="HNSCC_OS_marginS_pvalueKM_candidate_cox.Rda" above
# R4> candidate_sample[4:5,] # yes with FDR correction # n=6429
# number gene_id p_value
# 4 14 A2LD1 0.04930000
# 5 99 A2ML1 0.04648171
# old version preserved as HNSCC_OS_marginS_pvalueKM_candidate_cox_bak_cutoffnoFDR.Rda
# R4> candidate_sample[4:5,] # noFDR # n=6429
# number gene_id p_value
# 4 14 A2LD1 0.03210
# 5 99 A2ML1 0.00552
# devtools::install_github(c('jeroenooms/jsonlite', 'rstudio/shiny', 'ramnathv/htmlwidgets', 'timelyportfolio/listviewer'))
# library(listviewer)
# jsonedit( candidate_cox )
# # finished (both) processes
# archive .xlsx and transfer .Rda from GCE i-5, i-6 to i-4 (3 in 1) ####
#$ find HNSCC_survivalAnalysis_marginS_*.* -print > survival.txt
#$ tar -czf HNSCC.survival.marginS.20500.tar.gz -T survival.txt --remove-files
# macOS$ scp [email protected]:~/R/HNSCC_Tex_survival/hnscc_github/marginFree/HNSCC_OS_marginFree_pvalueKM_candidate_cox.Rda ./
# $ scp /Users/apple/R/HNSCC_OS_marginFree_pvalueKM_candidate_cox.Rda [email protected]:~/R/HNSCC_Tex_survival/hnscc_github/marginFree/
#
# macOS$ scp [email protected]:~/R/HNSCC_Tex_survival/hnscc_github/marginPlus/HNSCC_OS_marginPlus_pvalueKM_candidate_cox.Rda ./
# $ scp /Users/apple/R/HNSCC_OS_marginPlus_pvalueKM_candidate_cox.Rda [email protected]:~/R/HNSCC_Tex_survival/hnscc_github/marginPlus/
$ la -al *.Rda
## Post1 cut by P-value and/or Z-score ####
## table1 (KM): candidate_sample(KM) ##
# #sort by p_value (ascending) and cyl (descending)
# 楊老師: Bonferroni correction (adjustment) sets the significance cut-off at α/n. of KM P-value; Cox P-value <=0.05 as well.
# 王老師: 珍貴的結果 strong evidence
# https://www.stat.berkeley.edu/~mgoldman/Section0402.pdf
# newdata <- mtcars[order(mpg, -cyl),]
# >*** [choice ONE]: _marginFree_ or _marginS_ loading from .Rda
#marginTag <- "_marginS_" #at ./marginS
#marginTag <- "_marginFree_" #at ./marginFree
#marginTag <- "_marginPlus_" #at ./marginPlus
raw <-
readline("_margin(S)_, _marginFree(F)_ or _margin(P)lus_ -- process run: ")
select_margin <- function(x) {
switch(x,
s = "_marginS_",
f = "_marginFree_",
p = "_marginPlus_",
S = "_marginS_",
# F = "_marginFree_",
P = "_marginPlus_",
stop("Unknown input")
)
}
marginTag <- select_margin(raw)
print(marginTag)
rm(raw)
# notice: //
path_ZSWIM2 <- file.path(path_cohort, gsub("_", "", marginTag), "") # e.x. marginS/
load(file=paste(path_ZSWIM2, TCGA_cohort, "_OS", marginTag, "pvalueKM_candidate_cox.Rda", sep=""))
# as candidate_sample with candidate_cox and n_percent_Bonferroni at HNSCC_OS_marginS_pvalueKM_candidate_cox.Rda
# marginS, marginPlue or marginFree: using a "common" HNSCC_OS_marginS_pvalue_sorted
# run 3 times, 就有三組 marginS, marginPlus and marginFree;
attach(candidate_sample) # n=20500
HNSCC_OS_marginS_pvalue_sorted <- candidate_sample[order(p_value, -number),] # sorting by order(ascending)
detach(candidate_sample)
# ***其實直接 jump to p.adjust() post2 run 454
# x try 人工 Bonferroni correction (adjustment)
# -> sets the significance cut-off at α/n
# -> p.adjust(p, method = p.adjust.methods="bonferroni", n = length(p)) # bonferroni, or fdr
# n= number of comparisons, must be at least length(p); only set this (to non-default) when you know what you are doing!
# {
attach(HNSCC_OS_marginS_pvalue_sorted)
alpha_HNSCC <- 0.05
Bonferroni_cutoff <- alpha_HNSCC / (LUAD_n * n_percent_Bonferroni)
# => 4.786521e-06 (LUAD run04); => 5.31011e-06 (2019 run02) => 5.323113e-06 [2020/03/12] with 100cut FDR correction
# } 人工 Bonferroni end
# 以下是 plotting (it is not final figure); calculation go 463 ####
# #number/OS_pvalue: from cutoff finder, the number (frequency) of OS P-values, which KM P-value < 0.05, in this gene;
# higher probability to be "found" significantly on a random selection of "cutoff" value in the tranditional manner.
#tiff("Rplot10_Freq_Pvalue.tiff", units="cm", width=5, height=5, res=300)
plot(p_value, number, type="p", ylab="Frequency", xlab="P-value", main="P-value plot of KM survival analyses", log="x", cex=0.3) # log scale x or y
abline(h=100, lty=2, col="blue")
abline(v=Bonferroni_cutoff, lty=2, col="red") # 5.31011e-06
legend("topright", legend=c(paste("Frequency at 100"), paste("Bonferroni ", signif(Bonferroni_cutoff, 2))), lty=2:2, col=c("blue","red"), cex=0.7) # box and font size
#dev.off()
# KM P-value with Bonferroni correction
# ok n=28 in _marginS_ of HNSCC_OS_marginS_pvalueBonferroni_sorted; (1/3)
HNSCC_OS_marginS_pvalueBonferroni_sorted <- HNSCC_OS_marginS_pvalue_sorted[which(p_value<=Bonferroni_cutoff & !is.na(p_value)), 1:3]
# ok n=14 in _marginFree_; (2/3)
HNSCC_OS_marginFree_pvalueBonferroni_sorted <- HNSCC_OS_marginS_pvalueBonferroni_sorted
# ok n=6 in _marginPlus_; (3/3); return to 258
HNSCC_OS_marginPlus_pvalueBonferroni_sorted <- HNSCC_OS_marginS_pvalueBonferroni_sorted
# afer 3/3 then save 3 SFP
save(HNSCC_OS_marginS_pvalueBonferroni_sorted,
HNSCC_OS_marginFree_pvalueBonferroni_sorted,
HNSCC_OS_marginPlus_pvalueBonferroni_sorted,
file=paste(path_cohort, "/", TCGA_cohort, "_OS", "_marginSFP_pvalueBonferroni_KM_candidate_cox.Rda", sep=""))
# a.k.a. HNSCC_OS_marginSFP_pvalueBonferroni_KM_candidate_cox.Rda
# go to 413 then try FDR 442
#
### if no Bonferroni: try z-cut, z_score (Tex發明的)
non_Bonferroni_cutoff <- alpha_HNSCC / 1
plot(p_value, number, type="p", ylab="Frequency", xlab="P-value", main="P-value plot of KM survival analyses", log="x", cex=0.3) # log scale x or y
abline(h=150, lty=2, col="blue")
abline(v=non_Bonferroni_cutoff, lty=2, col="red") # ***as alpha_HNSCC instead of 5.31011e-06
legend("bottomleft", legend=c(paste("Frequency at 150"), paste("P-value at ", non_Bonferroni_cutoff)), lty=2:2, col=c("blue","red"), cex=0.7) # box and font size
# KM P-value <= 0.05 (alpha_HNSCC)
HNSCC_OS_marginS_pvalue005_sorted <- HNSCC_OS_marginS_pvalue_sorted[which(p_value<=non_Bonferroni_cutoff & !is.na(p_value)), 1:3]
detach(HNSCC_OS_marginS_pvalue_sorted) # keeping drawing
# no correction: n=6624 in _marginS_; n=? in _marginFree_; and n=? in _marginPlus_
# of HNSCC_OS_marginS_pvalue005_sorted
# plot(OS.km, lty=1, col=c("blue","red"), sub=paste("p-value =", p_OS[j]), main=paste("OS in OSCC(n=", surv_OS$n[1]+surv_OS$n[2],")/", geneName, "cutoff=", i), ylab="Percent Survival", xlab="Days")
# legend("topright", legend=c(paste("low(",surv_OS$n[1], ")"), paste("high(",surv_OS$n[2], ")")), lty=1:2, col=c("blue","red"))
library(stats)
library(scales)
library(minpack.lm)
# n=6601
attach(HNSCC_OS_marginS_pvalue005_sorted)
# reg <- lm(number ~ p_value, data = HNSCC_OS_marginS_pvalue005_sorted)
# abline(reg, col="blue")
# n=6601 in HNSCC_OS_marginS_pvalue005_sorted
HNSCC_OS_marginS_pvalue005_sorted$z_score <- scale(number, center=T, scale = T) # z_score z_cut were born
# "number" frequency is standardized as z-score (-1.04 to +2.30)
# ("Z" because the normal distribution is also known as the "Z distribution").
# => scale(): scale=TRUE, center=TRUE then scaling is done by dividing the (centered) columns of x by their standard deviations
# cut Z-score at
zcut <- 0.8 # n=1475
boxplot(HNSCC_OS_marginS_pvalue005_sorted$z_score)
abline(h=zcut, lty=2, col="blue") # mean=0, Max.: 2.3034
#DO NOT use Feature Scaling - normalization by (here: scaling to [0, 1] range); Rescaling data to have values between 0 and 1. This is usually called feature scaling. (min-max scaling)
# it will "condensate" the spreading of "number".
#x HNSCC_OS_marginS_pvalue005_sorted$number_01 <- scales:::rescale(z_score, to = c(0, 1))
#x rescaled to range minnew to maxnew (aka. 0 to 1 for binomial glm)
#x number_01 (0~1) is not Z-score, it is Feature Scaling 須要 正名之
#tiff("Rplot10_Zscore_Pvalue.tiff", units="cm", width=5, height=5, res=300)
plot(p_value, z_score, type="p", ylab="Z-score", xlab="P-value", main="P-value plot of KM survival analysis", log="x") # log scale x or y
#axis(side=3, at=c(1e-7, 1e-6, 1e-5, 0.01, 0.05)) #1=below, 2=left, 3=above and 4=right
abline(h=zcut, lty=2, col="blue")
abline(v=alpha_HNSCC, lty=2, col="red") # ***as alpha_HNSCC instead of 5.31011e-06
# run a logistic regression model (categorical 0 vs 1)
#g <- glm(number_01 ~ p_value, family=poisson, data=HNSCC_OS_marginS_pvalue005_sorted)
# (in this case, generalized linear model with log link)(link = "log"), poisson distribution
#curve(predict(g, data.frame(p_value = x), type="response"), add=TRUE, col="blue") # draws a curve based on prediction from logistic regression model
# x# run a non-linear regression: non-linear least squares approach (function nls in R) ; A nice feature of non-linear regression in an applied context is that the estimated parameters have a clear interpretation (Vmax in a Michaelis-Menten model is the maximum rate) which would be harder to get using linear models on transformed data for example.
# # the Levenberg-Marquardt algorithm for nonlinear regression
# # "eyeball" plot to set approximate starting values
# # https://stats.stackexchange.com/questions/160552/why-is-nls-giving-me-singular-gradient-matrix-at-initial-parameter-estimates
# # nls "singular gradient matrix at initial parameter estimates" error, using nlsLM instead
# a_start <- 0.9 #param a is the y value when x=0
# b_start <- 2*log(2)/a_start #b is the decay rate
# m <- nlsLM(number_01 ~ p_value, data=HNSCC_OS_marginS_pvalue005_sorted, start=list(a=a_start, b=b_start))
# curve(predict(m, data.frame(p_value = x), type="response", col="green"), add=TRUE, col="blue") # draws a curve based on prediction from logistic regression model
# #lines(p_value, predict(m), lty=2, col="green", lwd=3)
legend("bottomleft", legend=c(paste("Z-score at ", zcut), paste("P-value at ", alpha_HNSCC)), lty=2:2, col=c("blue","red"), cex=0.7) # box and font size
# figure legend: logistic regression, LR, by Generalized linear model, glm
#detach(HNSCC_OS_marginS_pvalue005_sorted)
# then...
# a candidate table, with "number of P-value" under cutoff finding (becoming z-score: bigger, much more significant cutoff "sites")
# => a kind of local minimal or global minimal of curve fitting (Levenberg-Marquardt Optimization)?
# subsetting the candidated genes table, according P-value (Bonferroni_cutoff) and Z-score
# ***after Bonferroni correction => n=26 in _marginS_
# ***after Bonferroni correction => n=33 in _marginFree_
#attach(HNSCC_OS_marginS_pvalue005_sorted)
HNSCC_OS_marginS_pvalue005_zcut <- HNSCC_OS_marginS_pvalue005_sorted[which(p_value <= alpha_HNSCC & z_score >= zcut), -1]
# discard "number"
HNSCC_OS_marginS_pvalue005_zcut$p_value <- signif(HNSCC_OS_marginS_pvalue005_zcut$p_value, 3)
HNSCC_OS_marginS_pvalue005_zcut$z_score <- signif(HNSCC_OS_marginS_pvalue005_zcut$z_score, 3)
detach(HNSCC_OS_marginS_pvalue005_sorted)
# > colnames(HNSCC_OS_marginS_pvalue005_zcut)
# x[1] "gene_id" "p_value" "z_score" "number_01"
# [1] "gene_id" "p_value" "z_score"
# _marginS_ (ok) as marginTag
# *** there is 3 collections:
# save n=28, cut by P-value <= Bonferroni_cutoff (Bonferroni correction)
save(HNSCC_OS_marginS_pvalueBonferroni_sorted, file=file.path(path_ZSWIM2, paste(TCGA_cohort, "_OS", marginTag, "pvalueBonferroni_sorted.Rda", sep="")))
#
# #R4> HNSCC_OS_marginS_pvalueBonferroni_sorted$gene_id
# [1] "ZNF557" "DKK1" "ZNF266" "CAMK2N1"
# [5] "IL19" "MYO1H" "STC2" "PGK1"
# [9] "SURF4" "FCGBP" "LOC148709" "USP10"
# [13] "EVPLL" "PNMA5" "NDFIP1" "FOXA2"
# [17] "GRAP" "KIAA1683" "ZNF846" "ZNF20"
# [21] "CELSR3" "SLC26A9" "FAM3D" "GPR15"
# [25] "KLRA1" "NPB" "TCP11" "STIP1"
# venn of 3: marginS, marginFree and marginPlus:
venn_marginSFP <- list(HNSCC_OS_marginFree_pvalueBonferroni_sorted$gene_id, HNSCC_OS_marginS_pvalueBonferroni_sorted$gene_id,
HNSCC_OS_marginPlus_pvalueBonferroni_sorted$gene_id)
names_marginSFP <- c(paste("margin[-]"), paste("margin[+/-]"), paste("margin[+]"))
library(venn)
# https://cran.r-project.org/web/packages/venn/venn.pdf
#tiff("venn_marginSFP.tiff", units="cm", width=5, height=5, res=300)
# # saving as .tiff (by tiff())
venn(venn_marginSFP, snames=names_marginSFP,
ilabels = T, counts = T, ellipse = FALSE, zcolor = "red, deeppink, pink", opacity = 0.6, size = 15, cexil = 2.0, cexsn = 0.8, borders = FALSE)
# predefined colors if "style"
#http://www.stat.columbia.edu/~tzheng/files/Rcolor.pdf
# meta-language 1 0 or -
title <- c(paste(TCGA_cohort, "survival analyses: candidate genes"), paste("(KM P-Value <=", signif(Bonferroni_cutoff, 2), ")")) #, collapse = "\n")
#coords <- unlist(getCentroid(getZones(venn_HR2p5, snames="uni_CoxHR>=2p5, multi_CoxHR>=2p5")))
# coords[1], coords[2],
text(500,950, labels = title[1], cex = 1.30) # (0,0) on bottom_left corner
text(500,100, labels = title[2], cex = 1.20)
# n=47
#dev.off() # saving instead of showing
# retrieving the intersection genes by gplots::venn
library(gplots)
tmp_cand <- venn(venn_marginSFP, names=names_marginSFP, show.plot=F) #library(gplots); the group count matrix alone
isect_marginSFP <- attr(tmp_cand, "intersections")
#isect_marginSFP
detach(package:gplots)
## > Post2 KM adding candidate_cox ####
## # (ok)重新改寫 [Bonferroni] and [FDR] P-value correction
# with FDR or Bonferroni correction ##
# *** best [2019/11/07] pValue_adj <- p.adjust(survOutput_km$pValue, method="fdr") #, n = nrow(survOutput_km))
# the possibility of type I error: alpha (single test)
# multiple testing problem
# FDR = E[F/S] <= q-value; http://www.omicshare.com/forum/thread-173-1-1.html
# >*** [choice ONE]: _marginFree_ or _marginS_ loading from .Rda
#marginTag <- "_marginS_" #at ./marginS
#marginTag <- "_marginFree_" #at ./marginFree
#marginTag <- "_marginPlus_" #at ./marginPlus
raw <-
readline("_margin(S)_, _marginFree(F)_ or _margin(P)lus_ -- process run: ")
select_margin <- function(x) {
switch(x,
s = "_marginS_",
f = "_marginFree_",
p = "_marginPlus_",
S = "_marginS_",
# F = "_marginFree_",
P = "_marginPlus_",
stop("Unknown input")
)
}
marginTag <- select_margin(raw)
print(marginTag)
rm(raw)
# notice: //
path_ZSWIM2 <- file.path(path_cohort, gsub("_", "", marginTag), "") # e.x. marginS/
load(file=paste(path_ZSWIM2, TCGA_cohort, "_OS", marginTag, "pvalueKM_candidate_cox.Rda", sep=""))
# as candidate_sample with candidate_cox and n_percent_Bonferroni at HNSCC_OS_marginS_pvalueKM_candidate_cox.Rda
# after 100cut FDR correction and selection
# marginS, marginPlue or marginFree: using a "common" HNSCC_OS_marginS_pvalue_sorted
# run 3 times, 就有三組 marginS, marginPlus and marginFree;
attach(candidate_sample) # n=20500
HNSCC_OS_marginS_pvalue_sorted <- candidate_sample[order(p_value, -number),] # sorting by order(ascending)
detach(candidate_sample)
#install.packages("BiocManager")
library("BiocManager")
# #source("https://bioconductor.org/biocLite.R")
# #biocLite("GDCRNATools")
# #biocLite("BiocParallel")
# install.packages("remotes")
# library(remotes)
# devtools::install_github("jeroen/jsonlite")
#
# # https://github.com/Jialab-UCR/Jialab-UCR.github.io/blob/master/GDCRNATools.workflow.R
# remotes::install_github("Jialab-UCR/GDCRNATools")
# library(GDCRNATools) # Pathview, citation("pathview") within R
# #
# a simple way
# na.omit -> only n=6624 genes have P-value available; removal of NA
HNSCC_OS_marginS_pvalue_sorted_noNA <- HNSCC_OS_marginS_pvalue_sorted[complete.cases(HNSCC_OS_marginS_pvalue_sorted), ]
#x keeping z_score
# HNSCC_OS_marginS_pvalue_sorted_noNA$z_score <- scale(HNSCC_OS_marginS_pvalue_sorted_noNA$number, center=T, scale = T)
# 1) try bonferroni by p.adjust()
#p_value_adj_bonferroni <- p.adjust(HNSCC_OS_marginS_pvalue_sorted_noNA$p_value, method="bonferroni", n = nrow(HNSCC_OS_marginS_pvalue_sorted_noNA))
p_value_adj_bonferroni <- p.adjust(HNSCC_OS_marginS_pvalue_sorted_noNA$p_value, method="bonferroni") # n=default 不必寫
# 2) estimate FDR from p-values by p.adjust()
# https://www.rdocumentation.org/packages/stats/versions/3.6.2/topics/p.adjust
# by p.adjust(); n=6615 of FDR<0.05; n=9 FDR=0.05
p_value_adj_FDR <- p.adjust(HNSCC_OS_marginS_pvalue_sorted_noNA$p_value, method="fdr", n = nrow(HNSCC_OS_marginS_pvalue_sorted_noNA))
# trying FDR<0.02, n=8
# p_value_adj[p_value_adj<=0.02]; n=8
# p_value_adj[p_value_adj<=0.01]; n=0
HNSCC_OS_marginS_pvalue_sorted_noNA_p_adjustS <- cbind(HNSCC_OS_marginS_pvalue_sorted_noNA, p_value_adj_bonferroni, p_value_adj_FDR)
# HNSCC_OS_marginS_pvalue_sorted_noNA <- cbind(HNSCC_OS_marginS_pvalue_sorted_noNA, p_value_adj)
#HNSCC_OS_marginS_pvalue_sorted_noNA_FDR <- HNSCC_OS_marginS_pvalue_sorted_noNA
save(HNSCC_OS_marginS_pvalue_sorted_noNA_p_adjustS, file=file.path(path_ZSWIM2, paste(TCGA_cohort, "_OS", marginTag, "pvalue_sorted_noNA_p_adjustS.Rda", sep="")))
# [2020/02/16] p_value_adj is FDR and bonferroni;
# "HNSCC_OS_marginS_pvalue_sorted_noNA_p_adjustS.Rda" saved at "/home/tex/R/HNSCC_Tex_survival/hnscc_github/marginS/"
# n=6624 => n=6429
# x[2019/09/05]
#HNSCC_OS_marginS_pvalue005_sorted
# save n=6624, cut by P-value <= alpha_HNSCC
#x save(HNSCC_OS_marginS_pvalue005_sorted, file=file.path(path_ZSWIM2, paste(TCGA_cohort, "_OS", marginTag, "pvalue005_sorted.Rda", sep="")))
# save n=1437, cut by P-value <= alpha_HNSCC AND Z-score >= zcut(e.q. 0.8)
#x save(HNSCC_OS_marginS_pvalue005_zcut, Bonferroni_cutoff, file=file.path(path_ZSWIM2, paste(TCGA_cohort, "_OS", marginTag, "pvalue005_zcut.Rda", sep="")))
# *** rename HNSCC_OS_marginS_pvalue1e_6_zscore0_6 => HNSCC_OS_marginS_pvalue005_zcut
#
#x or
#x x) by fdrtool() with chart; n=6615 FDR<0.05
## https://www.rdocumentation.org/packages/fdrtool/versions/1.2.15/topics/fdrtool
#xinstall.packages("fdrtool")
#xHNSCC_fdr = fdrtool(HNSCC_OS_marginS_pvalue_sorted_noNA$p_value, statistic="pvalue", cutoff.method=c("fndr"))
#cutoff.method=c("fndr", "pct0", "locfdr")
# Step 1... determine cutoff point
# Step 2... estimate parameters of null distribution and eta0
# Step 3... compute p-values and estimate empirical PDF/CDF
# Step 4... compute q-values and local fdr
# Step 5... prepare for plotting
#HNSCC_fdr$qval # estimated Fdr values => all are zero
#HNSCC_fdr$lfdr # estimated local fdr => all are zero
#---
#library("BiocParallel")
#register(MulticoreParam(2)) # 2 cores
##xx it has [part I][part II][part III]
# "sig" marking for significant P-value (<=0.05)
# [uni_cox_pvalue, uni_HR, uni_sig]
# [multi_cox_pvalue, multi_HR, multi_sig]
# [exp_pvalue]
# to generate HNSCC_OS_marginS_pvalue005KM_sorted_pvalueCox_HR.Rda; n=6601 or 1476
# from
# x# 1) HNSCC_OS_marginS_pvalue005_sorted # n=6601; P-value < 0.05 (without correction)
# load(file=file.path(path_ZSWIM2, paste(TCGA_cohort, "_OS", marginTag,
# "pvalue005_sorted.Rda", sep="")))
# x# 2) HNSCC_OS_marginS_pvalue005_zcut, n=1476;
# load(file=file.path(path_ZSWIM2, paste(TCGA_cohort, "_OS", marginTag,
# "pvalue005_zcut.Rda", sep="")))
# x# or 3) # *** try using FDR: HNSCC_OS_marginS_pvalue_sorted_noNA_FDR.Rda; FDR
# load(file=file.path(path_ZSWIM2, paste(TCGA_cohort, "_OS", marginTag, "pvalue_sorted_noNA_FDR.Rda", sep="")))
load(file=file.path(path_ZSWIM2, paste(TCGA_cohort, "_OS", marginTag, "pvalue_sorted_noNA_p_adjustS.Rda", sep="")))
# as HNSCC_OS_marginS_pvalue_sorted_noNA_p_adjustS
#
load(file=file.path(path_ZSWIM2, paste(TCGA_cohort, "_OS", marginTag, "pvalueKM_candidate_cox.Rda", sep="")))
# as candidate_sample, candidate_cox, n_percent_Bonferroni (after 100cut FDR)
# [Bonferroni][FDR] new variable: KM + Cox, n=6429; P-value < 0.05 (Bonferroni correction)
# # KM P-value <= 0.05 (alpha_HNSCC): HNSCC_OS_marginS_pvalue005_sorted
HNSCC_OS_marginS_pvalue005KM_sorted_pvalueCox_HR <- HNSCC_OS_marginS_pvalue_sorted_noNA_p_adjustS
#dataframe[,"newName"] <- NA # add more named columns (NA)
HNSCC_OS_marginS_pvalue005KM_sorted_pvalueCox_HR[,c("uni_HR", "uni_P_value", "uni_sig","multi_HR", "multi_P_value", "multi_sig")] <- NA
#HNSCC_OS_marginS_pvalue005_sorted[,c(colnames(candidate_cox[[1]][8, c(2:4, 6:8)]))] <- NA
#colnames(HNSCC_OS_marginS_pvalue005KM_sorted_pvalueCox_HR) <- c(...."uni_HR", "uni_P_value", "uni_sig",
# "multi_HR", "multi_P_value", "multi_sig")
#attach(HNSCC_OS_marginS_pvalue005KM_sorted_pvalueCox_HR)
#ipp <- 0
# *** row and col position 非常重要
for (ip in 1:nrow(HNSCC_OS_marginS_pvalue005KM_sorted_pvalueCox_HR)) {
pos_gene <- which(whole_genome==HNSCC_OS_marginS_pvalue005KM_sorted_pvalueCox_HR$gene_id[ip]) # HNSCC_OS_marginS_pvalue005KM_sorted_pvalueCox_HR$gene_id
# by geneid ?
if (length(candidate_cox[[pos_gene]])==11) {
# reference: candidate_cox_ip, which listing as candidate_cox
HNSCC_OS_marginS_pvalue005KM_sorted_pvalueCox_HR[ip, 6:11] <- candidate_cox[[pos_gene]][9, c(2:4, 6:8)]
# taking 9 RNAseg: sig marked and P-values, HRs
#*** 8 is tobacco;
# we don't have number0_1 any more: colnames "number" "gene_id" "p_value" "z_score"
# ipp <- ipp+1
print(paste(ip, " out of ", nrow(HNSCC_OS_marginS_pvalue005KM_sorted_pvalueCox_HR), " (", whole_genome[pos_gene], ")", sep=""))
print(paste(c("..adding...", HNSCC_OS_marginS_pvalue005KM_sorted_pvalueCox_HR[ip, c(2, 6, 9)]), sep=";"))
}
# on : [2018-05-18 07:26:42] [error] handle_read_frame error: websocketpp.transport:7 (End of File)
#"exp_pvalue" is a correlation of gene expression vs features (TNM....):
# <- candidate_cox[which(gene_id[ip]==whole_genome)][1:7, c(11)] # correlation
# colnames <- c("KM_Features", "KM_P_value", "KM_sig")
}
# HNSCC_OS_marginS_pvalue_sorted_noNA_p_adjustS with [Bonferroni][FDR] and variable: KM + Cox
save(HNSCC_OS_marginS_pvalue005KM_sorted_pvalueCox_HR, file=file.path(path_ZSWIM2, paste(TCGA_cohort, "_OS", marginTag, "pvalue005KM_sorted_pvalueCox_HR.Rda", sep="")))
# as HNSCC_OS_marginS_pvalue005KM_sorted_pvalueCox_HR.Rda
# 2020/02/24 it is tobacco :-); 2020/03/08 ok RNA-seq; go "Pickup all..."
# # xx
# #x [part I] new variable: KM + Cox, n=6601; P-value < 0.05 (without correction)
# #xHNSCC_OS_marginS_pvalue005KM_sorted_pvalueCox_HR <- HNSCC_OS_marginS_pvalue005_sorted
# #dataframe[,"newName"] <- NA # add more named columns (NA)
# #xHNSCC_OS_marginS_pvalue005KM_sorted_pvalueCox_HR[,c("uni_HR", "uni_P_value", "uni_sig","multi_HR", "multi_P_value", "multi_sig")] <- NA
# #HNSCC_OS_marginS_pvalue005_sorted[,c(colnames(candidate_cox[[1]][8, c(2:4, 6:8)]))] <- NA
# #colnames(HNSCC_OS_marginS_pvalue005KM_sorted_pvalueCox_HR) <- c(...."uni_HR", "uni_P_value", "uni_sig",
# # "multi_HR", "multi_P_value", "multi_sig")
#
# #attach(HNSCC_OS_marginS_pvalue005KM_sorted_pvalueCox_HR)
# #ipp <- 0
# for (ip in 1:nrow(HNSCC_OS_marginS_pvalue005KM_sorted_pvalueCox_HR)) {
# pos_gene <- which(whole_genome==HNSCC_OS_marginS_pvalue005KM_sorted_pvalueCox_HR$gene_id[ip]) # HNSCC_OS_marginS_pvalue005KM_sorted_pvalueCox_HR$gene_id
# # by geneid ?
# if (length(candidate_cox[[pos_gene]])==11) {
# # reference: candidate_cox_ip, which listing as candidate_cox
# HNSCC_OS_marginS_pvalue005KM_sorted_pvalueCox_HR[ip, 5:10] <- candidate_cox[[pos_gene]][8, c(2:4, 6:8)] # taking RNAseg: sig marked and P-values, HRs
# # we don't have number0_1 any more: colnames "number" "gene_id" "p_value" "z_score"
# # ipp <- ipp+1
# print(paste(ip, " out of ", nrow(HNSCC_OS_marginS_pvalue005KM_sorted_pvalueCox_HR), " (", whole_genome[pos_gene], ")", sep=""))
# print(paste(c("..adding...", HNSCC_OS_marginS_pvalue005KM_sorted_pvalueCox_HR[ip, c(2, 5)]), sep=";"))
# }
# # on : [2018-05-18 07:26:42] [error] handle_read_frame error: websocketpp.transport:7 (End of File)
# #"exp_pvalue" is a correlation of gene expression vs features (TNM....):
# # <- candidate_cox[which(gene_id[ip]==whole_genome)][1:7, c(11)] # correlation
# # colnames <- c("KM_Features", "KM_P_value", "KM_sig")
#
# }
# #detach(HNSCC_OS_marginS_pvalue005KM_sorted_pvalueCox_HR)
# # c( "uni_Features", "uni_HR", "uni_P_value", "uni_sig", "multi_Features", "multi_HR",
# #"multi_P_value", "multi_sig", "KM_Features", "KM_P_value", "KM_sig")
# # add colname as HRs, "uni_cox"/"multi_cox", sig ... for HRs, P-values, sig of RNAseq(z-score)
#
#
# # [part II] new variable: KM + Cox, n=1475; under zcut
# HNSCC_OS_marginS_pvalue005_zcutKM_sorted_pvalueCox_HR <- HNSCC_OS_marginS_pvalue005_zcut
# # add more columns
# HNSCC_OS_marginS_pvalue005_zcutKM_sorted_pvalueCox_HR[,c("uni_HR", "uni_P_value", "uni_sig","multi_HR", "multi_P_value", "multi_sig")] <- NA
# for (ip in 1:nrow(HNSCC_OS_marginS_pvalue005_zcutKM_sorted_pvalueCox_HR)) {
# pos_gene <- which(whole_genome==HNSCC_OS_marginS_pvalue005_zcutKM_sorted_pvalueCox_HR$gene_id[ip]) # HNSCC_OS_marginS_pvalue005_zcutKM_sorted_pvalueCox_HR$gene_id
# if (length(candidate_cox[[pos_gene]])==11) {
# # reference: candidate_cox_ip, which listing as candidate_cox
# HNSCC_OS_marginS_pvalue005_zcutKM_sorted_pvalueCox_HR[ip, 4:9] <- candidate_cox[[pos_gene]][8, c(2:4, 6:8)] # taking RNAseg: sig marked and P-values, HRs
# # we don't have number0_1 any more: colnames "gene_id" "p_value" "z_score"
# # ipp <- ipp+1
# print(paste(ip, " out of ", nrow(HNSCC_OS_marginS_pvalue005_zcutKM_sorted_pvalueCox_HR), " (", whole_genome[pos_gene], ")", sep=""))
# print(paste(c("..adding...", HNSCC_OS_marginS_pvalue005_zcutKM_sorted_pvalueCox_HR[ip, c(1, 4)]), sep=";"))
# }
# }
# ##
# # save table1 + table2 (ok) [2019/07/01], n= 6601 or 1475
# save(HNSCC_OS_marginS_pvalue005KM_sorted_pvalueCox_HR, file=file.path(path_ZSWIM2, paste(TCGA_cohort, "_OS", marginTag, "pvalue005KM_sorted_pvalueCox_HR.Rda", sep="")))
# save(HNSCC_OS_marginS_pvalue005_zcutKM_sorted_pvalueCox_HR, file=file.path(path_ZSWIM2, paste(TCGA_cohort, "_OS", marginTag, "pvalue005_zcutKM_sorted_pvalueCox_HR.Rda", sep="")))
# #save(list(HNSCC_OS_marginS_pvalue005_zcut, ???))
# x[i], or might be x[i:j]
# x[i, j]
# x[[i]]; x[[expr]]; it can NOT be x[[i:j]]
# x[[i, j]]
# x$a
# x$"a"
# # [part III] under FDR q-value
# # # HNSCC_OS_marginS_pvalue_sorted_noNA_FDR.Rda
# HNSCC_OS_marginS_pvalue_sorted_noNA_FDRKM_sorted_pvalueCox_HR <- HNSCC_OS_marginS_pvalue_sorted_noNA_FDR
# # add more columns
# HNSCC_OS_marginS_pvalue_sorted_noNA_FDRKM_sorted_pvalueCox_HR[,c("uni_HR", "uni_P_value", "uni_sig","multi_HR", "multi_P_value", "multi_sig")] <- NA
# for (ip in 1:nrow(HNSCC_OS_marginS_pvalue_sorted_noNA_FDRKM_sorted_pvalueCox_HR)) {
# pos_gene <- which(whole_genome==HNSCC_OS_marginS_pvalue_sorted_noNA_FDRKM_sorted_pvalueCox_HR$gene_id[ip]) # HNSCC_OS_marginS_pvalue_sorted_noNA_FDRKM_sorted_pvalueCox_HR$gene_id
# if (length(candidate_cox[[pos_gene]])==11) {
# # reference: candidate_cox_ip, which listing as candidate_cox
# HNSCC_OS_marginS_pvalue_sorted_noNA_FDRKM_sorted_pvalueCox_HR[ip, 5:10] <- candidate_cox[[pos_gene]][8, c(2:4, 6:8)] # taking RNAseg: sig marked and P-values, HRs
# # we don't have number0_1 any more: colnames "gene_id" "p_value" "z_score"
# # ipp <- ipp+1
# print(paste(ip, " out of ", nrow(HNSCC_OS_marginS_pvalue_sorted_noNA_FDRKM_sorted_pvalueCox_HR), " (", whole_genome[pos_gene], ")", sep=""))
# print(paste(c("..adding...", HNSCC_OS_marginS_pvalue_sorted_noNA_FDRKM_sorted_pvalueCox_HR[ip, c(1, 5)]), sep=";"))
# }
# }
# #
# save(HNSCC_OS_marginS_pvalue_sorted_noNA_FDRKM_sorted_pvalueCox_HR, file=file.path(path_ZSWIM2, paste(TCGA_cohort, "_OS", marginTag, "pvalue_sorted_noNA_FDRKM_sorted_pvalueCox_HR.Rda", sep="")))
# ## =6624
#> Pickup all significant genes list -> HNSCC_OS_marginS_THREE_pvalue005 ####
# x FDR < 0.05; HNSCC_OS_marginS_pvalue_sorted_noNA_FDRKM_sorted_pvalueCox_HR, n=6624
# x Z-score > 0.8: HNSCC_OS_marginS_pvalue005_zcutKM_sorted_pvalueCox_HR, n=1475
### => HNSCC_OS_marginS_pvalue_sorted_noNA_p_adjustS with [Bonferroni][FDR] and variable: KM + Cox HR
# as HNSCC_OS_marginS_pvalue005KM_sorted_pvalueCox_HR
# _marginS_ on [2019/07/02]
load(file=file.path(path_ZSWIM2, paste(TCGA_cohort, "_OS", marginTag, "pvalue005KM_sorted_pvalueCox_HR.Rda", sep="")))
# # > colnames(HNSCC_OS_marginS_pvalue005KM_sorted_pvalueCox_HR)
# [Bonferroni] and [FDR] P-value corrected (no z_cut)
# [1] "number"
# [2] "gene_id"
# [3] "p_value"
# [4] "p_value_adj_bonferroni"
# [5] "p_value_adj_FDR"
# [6] "uni_HR"
# [7] "uni_P_value"
# [8] "uni_sig"
# [9] "multi_HR"
# [10] "multi_P_value"
# [11] "multi_sig"
# R4>
#xHNSCC_OS_marginS_THREE_pvalue005_FDR <- subset(HNSCC_OS_marginS_pvalue_sorted_noNA_FDRKM_sorted_pvalueCox_HR,
# select=c(gene_id, p_value, p_value_adj, uni_HR, uni_P_value, multi_HR, multi_P_value))
# p_value_adj is FDR
# n=6429
HNSCC_OS_marginS_THREE_pvalue005 <- subset(HNSCC_OS_marginS_pvalue005KM_sorted_pvalueCox_HR,
select=c(gene_id, p_value, p_value_adj_bonferroni, p_value_adj_FDR, uni_HR, uni_P_value, multi_HR, multi_P_value))
save(HNSCC_OS_marginS_THREE_pvalue005, file=file.path(path_ZSWIM2, paste(TCGA_cohort, "_OS", marginTag, "THREE_pvalue005.Rda", sep="")))
#xHNSCC_OS_marginS_THREE_pvalue005_1475 <- subset(HNSCC_OS_marginS_pvalue005_zcutKM_sorted_pvalueCox_HR,
# select=c(gene_id, p_value, z_score, uni_HR, uni_P_value, multi_HR, multi_P_value))
#... <- subset(..., (uni_P_value <= 0.05) & (multi_P_value <= 0.05),
#save(HNSCC_OS_marginS_THREE_pvalue005_FDR, file=file.path(path_ZSWIM2, paste(TCGA_cohort, "_OS", marginTag, "THREE_pvalue005_FDR.Rda", sep="")))
#save(HNSCC_OS_marginS_THREE_pvalue005_6601, file=file.path(path_ZSWIM2, paste(TCGA_cohort, "_OS", marginTag, "THREE_pvalue005_6601.Rda", sep="")))
#save(HNSCC_OS_marginS_THREE_pvalue005_1475, file=file.path(path_ZSWIM2, paste(TCGA_cohort, "_OS", marginTag, "THREE_pvalue005_1475.Rda", sep="")))
# as HNSCC_OS_marginS_THREE_pvalue005 (6601 or 1475)
# >pubmed.mineR ####
# # no zcut: HNSCC_OS_marginS_THREE_pvalue005_6601 <- HNSCC_OS_marginS_THREE_pvalue005, n=6601
# load(file=file.path(path_ZSWIM2, paste(TCGA_cohort, "_OS", marginTag, "THREE_pvalue005_6601.Rda", sep="")))
# # zcut, Z-score > 0.8: HNSCC_OS_marginS_THREE_pvalue005_1475 <- HNSCC_OS_marginS_pvalue005_zcut, n=1475
# load(file=file.path(path_ZSWIM2, paste(TCGA_cohort, "_OS", marginTag, "THREE_pvalue005_1475.Rda", sep="")))
# # if FDR < 0.05
# load(file=file.path(path_ZSWIM2, paste(TCGA_cohort, "_OS", marginTag, "THREE_pvalue005_FDR.Rda", sep="")))
# start to working...# ***
load(file=file.path(path_ZSWIM2, paste(TCGA_cohort, "_OS", marginTag, "THREE_pvalue005.Rda", sep="")))
# as HNSCC_OS_marginS_THREE_pvalue005
# [GDC data portal]
# https://www.rdocumentation.org/packages/pubmed.mineR/versions/1.0.1
# https://docs.gdc.cancer.gov/Data_Portal/Users_Guide/Exploration/
# Excluding COSMIC Cancer Gene Census (CGC, such as TRIM24, ...) from GDC data portal: d/l Cancer Gene Census (575 genes)
# [2019/07/17] downloaded, n=575; https://cancer.sanger.ac.uk/census/? 再也找不到了
# [2020/02/27] Census_allThu Feb 27 09_29_04 2020.tsv: total n=723; n=7+12=19 in tumour types: head and neck cancer, HNSCC, oral SCC, oral squamous cell carcinoma]
# load genes.2019-07-17.json
#install.packages("jsonlite")
library(jsonlite)
#x cgc_gene575 <- fromJSON("~/R/genes.2019-07-17.json", simplifyDataFrame=TRUE)
cgc_gene723 <- read.table(file = "~/R/Census_allThu Feb 27 09_29_04 2020.tsv", sep = '\t', header = TRUE)
# subsetting by omitting row
# xcc_Index2019 <- which(HNSCC_OS_marginS_THREE_pvalue005$gene_id %in% cgc_gene575$symbol)
cgc_Index2020 <- which(HNSCC_OS_marginS_THREE_pvalue005$gene_id %in% cgc_gene723$Gene.Symbol)
#venn(list(cgc_gene575$symbol[cc_Index2019], cgc_gene723$Gene.Symbol[cc_Index2020]), snames=c("CGC_2019", "CGC_2020"), ilabels = T, counts = T, ellipse = FALSE, zcolor = "red, deeppink, pink", opacity = 0.6, size = 15, cexil = 2.0, cexsn = 0.8, borders = FALSE)
View(HNSCC_OS_marginS_THREE_pvalue005$gene_id[cgc_Index2020]) # n=213 or 52
HNSCC_OS_marginS_THREE_pvalue005_noCancerGene <- HNSCC_OS_marginS_THREE_pvalue005[-cgc_Index2020, ] # removal
# now n=6368 [2020/03/08]
# There is updated HNSCC related gene from publication ####
# *** go to embase
# x [PubMed] search keywoard:"((((marker[Abstract] OR biomarker[Abstract])) AND (HNSCC OR HNSC OR "oral"))) AND (prognostic[Title] OR prognosis[Title])"
#install.packages("pubmed.mineR") # two formats (text and XML) from PubMed
# scp /Users/apple/Downloads/pmc_result_HNSCC_genes1486_MEDLINE.txt [email protected]:~/R/
# *** export MEDLINE format (with abstract)
library(pubmed.mineR) # http://ramuigib.blogspot.com
#install.packages(c("rentrez", "XML"))
library(rentrez)
library(XML)
# gene_atomization(), official_fn(gene_atomization, abs, filename, terms),
#abs <- xmlreadabs("~/R/pmc_result_HNSCC_genes1486.xml") #an S4 object of class Abstracts containing journals, abstracts and PMID
#abs <- read.table("~/R/pmc_result_HNSCC_genes1486.xml", sep="|") #an S4 object of class Abstracts containing journals, abstracts and PMID
abs <- readabs("~/R/pmc_result_HNSCC_genes1486_MEDLINE.txt") # Abstracts <- .txt; the slot operator @
# # 5.5Mb; objects of class "Abstracts" have 3 slots, Journal, Abstract, and PMID
# readabs(), xmlgene_atomizations(m)
# x pub_hnscc_genes <- xmlgene_atomizations(abs)
#pub_hnscc_genes <- gene_atomization(abs) # n=615; however, "FAU" "T" "GC" "HR" are not gene symbol
## (there is misleading data)
#pub_Index <- which(pub_hnscc_genes[ , 1] %in% whole_genome) # curation1; n=611
#pub_hnscc_genes <- pub_hnscc_genes[pub_Index, ] # n=611
# https://www.rdocumentation.org/packages/pubmed.mineR/versions/1.0.1
# https://omictools.com/pubtator-tool PubTator
#x curation2 <- mapply(Give_Sentences, pub_hnscc_genes[ , 2], abs@Abstract) # or searchabsT
#x curation2 <- mapply(searchabsT, abs, include=pub_hnscc_genes[ , 2]) # or searchabsT
# getabs(abs, pub_hnscc_genes[1, 2], FALSE)
pubmed_hnscc_PMID <- entrez_search(db="pubmed",
term="((((((((marker[Abstract] OR biomarker[Abstract])) AND (prognostic[Title] OR prognosis[Title]))))) AND (((Upper Aerodigestive) OR HNSCC OR (oral cancer)))))) NOT ((salivary OR bladder OR breast OR bone OR kidney OR leukoplakia OR dysplasia))", retmax=2000, use_history=TRUE)
# n=1325
# x=> refinement with ((D006258[MeSH Major Topic]) OR D006258[MeSH Terms]) <= Head and Neck Neoplasms
#x pubmed_hnscc_PMID <- entrez_search(db="pubmed", term="((((marker[Abstract] OR biomarker[Abstract])) AND ((D006258[MeSH Major Topic]) OR D006258[MeSH Terms]) AND (prognostic[Title] OR prognosis[Title])", retmax=5000)
# MESH is not universal available :-)
# paper_links <- entrez_link(dbfrom="pubmed", id=25500142, cmd="llinks")
# paper_links$linkouts; linkout_urls(paper_links)
# entrez_fetch(); entrez_summary()
# error: download abstracts (HTTP failure 414, the request is too large. For large requests, try using "web history" as described in the rentrez tutorial)
# "web history" { , use_history=TRUE => web_history object
#upload_ncbi <- entrez_post(db="pubmed", id = pubmed_hnscc_PMID$ids)
#upload_ncbi
pubmed_hnscc_abs <- entrez_fetch(db="pubmed", web_history=pubmed_hnscc_PMID$web_history,
rettype="xml", retmax=2000, parsed = T)
#R4> str(pubmed_hnscc_abs)
#Classes 'XMLInternalDocument', 'XMLAbstractDocument' <externalptr>
# *.txt generated
# /Users/apple/Downloads/dataout.txt => gene without abstract available
# /Users/apple/Downloads/newabs.txt => abstracts
# /Users/apple/Downloads/result.txt => ditto with pubmed_hnscc_PMID_list **
# /Users/apple/Downloads/table.txt => genes list
# }
# x pubmed_hnscc_abs <- entrez_fetch(db = "pubmed", id = pubmed_hnscc_PMID$ids,
# rettype = "xml", parsed = T)
# >text annotation uisng online PubTator (rentrez::pubtator_function)
#pub_hnscc_PMID <- lapply(abs@PMID, pubtator_function) # Gene, Chemical, Disease and PMID
# ** ditto with result.txt from entrez_fetch
pubmed_hnscc_PMID_list <- lapply(pubmed_hnscc_PMID$ids, pubtator_function) # Gene, Chemical, Disease and PMID
# => n=1325; list of Genes, Diseases, ... and PMID
# e.x.
# R4> pubmed_hnscc_PMID_list[[555]]$Diseases
#$Diseases
#[1] "cancer>MESH:D009369"
#[2] "hematopoiesis>MESH:C536227"
#[3] "inflammation>MESH:D007249"
#[4] "tumor>MESH:D009369"
#[5] "squamous cell carcinoma>MESH:D002294"
#[6] "squamous cell carcinomas>MESH:D002294"
#[7] "tumors>MESH:D009369"
# e.x. pubmed_hnscc_PMID[[555]]$Genes is TATA-binding protein>6908 => Entrez Gene: 6908
#pub_hnscc_table <- pubtator_result_list_to_table(pub_hnscc_PMID) # to exclude HNSCC "disease"
# check genes with HNSCC OR HNSC OR "oral cancer" related
pubmed_hnscc_df <- as.data.frame(matrix(NA, nrow=length(pubmed_hnscc_PMID_list), ncol=3))
colnames(pubmed_hnscc_df) <- c("PMID", "Diseases", "Genes")
for (pubtator_i in 1: length(pubmed_hnscc_PMID_list)) {
if (pubmed_hnscc_PMID_list[[pubtator_i]] == " No Data ") {next}
else {pubmed_hnscc_df[pubtator_i, 1] <- pubmed_hnscc_PMID_list[[pubtator_i]]$PMID[1]}
tryCatch({
pubmed_hnscc_df[pubtator_i, 2] <- pubmed_hnscc_PMID_list[[pubtator_i]]$Diseases[1]
pubmed_hnscc_df[pubtator_i, 3] <- pubmed_hnscc_PMID_list[[pubtator_i]]$Genes[1]
}, error = function(err) {
# error handler picks up where error was generated
#print(paste("MY_ERROR: ", err))
return()
}) # END tryCatch
}
pubmed_hnscc_abstractFull <- read.csv(file.path(path_ZSWIM2, "newabs.txt"), header=T)
# /Users/apple/Downloads/newabs.txt => abstracts
# 29453876: ameloblastoma, Genes of FGF2, Bcl-2
# excluding (salivary OR bladder OR breast OR bone OR kidney OR leukoplakia OR dysplasia)
#[embase]
# >embase search then exported .csv ####
# https://dev.elsevier.com/documentation/EmbaseAPI.wadl
# https://www.rdocumentation.org/packages/rscopus/versions/0.6.3/topics/scopus_search
#https://cran.r-project.org/web/packages/rscopus/rscopus.pdf
#install.packages("rscopus")
library(rscopus)
library(pubmed.mineR) # http://ramuigib.blogspot.com
#library(RISmed) # https://amunategui.github.io/pubmed-query/; 2017 no more read.ris()
# https://cran.r-project.org/web/packages/RefManageR/RefManageR.pdf
#embase_retrieval(id, identifier = c("lui", "pii", "doi", "embase",
# "pubmed_id", "medline"), http_end = NULL, ...)
# Type of search. See https://dev.elsevier.com/api_docs.html
# [2019/07/20] my elsevier api_key = "9925b63f77af6f11b74b38a3d6a80f41" from web site
# [2020/02/29] manual Quick search in embase:
# (prognosis:ti OR prognostic:ti OR 'tumor marker') AND cancer:ti AND 'head and neck squamous cell carcinoma' OR ('SLC2A4' AND hnscc) OR ('thymosin beta 4' AND hnscc) OR (hnscc AND 'hsiao m.':au AND 'chang w.-m':au)
# download records-503.csv -> records-432.csv
res_df <- read.csv(file=file.choose(), header=T) # with abstract, PUI as embase
em_hnscc_PMID_list <- lapply(res_df$Medline.PMID, pubtator_function) # list of Gene, Chemical, Disease and PMID
# => n=371 => 134; 503
# e.x. The neuropeptide genes SST, TAC1, HCRT, NPY, and GAL are powerful epigenetic biomarkers in head and neck cancer: a site-specific analysis.
#(PMID:29682090 PMCID:PMC5896056) => The somatostatin (SST)
# parsing and pickup 1st: "PMID", "Diseases", "Genes"
pubmed_hnscc_df <- as.data.frame(matrix(NA, nrow=length(em_hnscc_PMID_list), ncol=3))
colnames(pubmed_hnscc_df) <- c("PMID", "Diseases", "Genes")
for (pubtator_i in 1: length(em_hnscc_PMID_list)) {
print(pubtator_i)
if (em_hnscc_PMID_list[[pubtator_i]] == " No Data ") {next}
else {pubmed_hnscc_df[pubtator_i, 1] <- em_hnscc_PMID_list[[pubtator_i]]$PMID[1]}
tryCatch({
pubmed_hnscc_df[pubtator_i, 2] <- em_hnscc_PMID_list[[pubtator_i]]$Diseases[1]
pubmed_hnscc_df[pubtator_i, 3] <- em_hnscc_PMID_list[[pubtator_i]]$Genes[1]
}, error = function(err) {
# error handler picks up where error was generated
#print(paste("MY_ERROR: ", err))
return()
}) # END tryCatch
}
# [HNSCC gene signature]
#Cancer GeneticsWeb: check it out
# http://www.cancerindex.org/geneweb/HRPT2.htm
# find published HNSCC genes from Embase
# pubmed_hnscc_df data cleaning: sorting by "Disease", manual curation
pubmed_hnscc_df_sorted <- pubmed_hnscc_df[order(pubmed_hnscc_df$Diseases, na.last=NA), ] # NA removal, n=259
pubmed_hnscc_df_sorted <- pubmed_hnscc_df_sorted[complete.cases(pubmed_hnscc_df_sorted$Genes), ] # n=169 => 64
# n=203; including DDX58; GLUT4; HNSCC; Metastasis; TRIM24, PMID: 28061796
# manually add GLUT4>6517 and DDX58>23586 from 28061796
pubmed_hnscc_df_sorted <- rbind(pubmed_hnscc_df_sorted, pubmed_hnscc_df_sorted[pubmed_hnscc_df_sorted$PMID==28061796, ]) # n=204
pubmed_hnscc_df_sorted <- rbind(pubmed_hnscc_df_sorted, pubmed_hnscc_df_sorted[pubmed_hnscc_df_sorted$PMID==28061796, ]) # n=206
pubmed_hnscc_df_sorted <- pubmed_hnscc_df_sorted[-(nrow(pubmed_hnscc_df_sorted)), ] # n=205
pubmed_hnscc_df_sorted[(nrow(pubmed_hnscc_df_sorted)), 3] <- "GLUT4>6517"
pubmed_hnscc_df_sorted[(nrow(pubmed_hnscc_df_sorted)-1), 3] <- "DDX58>23586"
# loading all genes mentioned in each article
pubmed_hnscc_genes <- as.data.frame(matrix(NA, nrow=nrow(pubmed_hnscc_df_sorted)*4, ncol=5))
colnames(pubmed_hnscc_genes) <- c("No", "PMID", "Diseases", "GeneSymbol", "EntrezGene")
No_i <- 1 # a serial number
for (curation_i in 1: nrow(pubmed_hnscc_df_sorted)) {
print(curation_i)
No_j <- 1 # index of genes in each article
# em_hnscc_PMID_list is 1:371 from res_df$Medline.PMID; there is duplicated article (PMID:24565202)
res_index <- which(res_df$Medline.PMID==pubmed_hnscc_df_sorted$PMID[curation_i]) # always choice res_index[1], first PMID
for (No_j in 1:length(em_hnscc_PMID_list[[res_index[1]]]$Genes)) {
pubmed_hnscc_genes[No_i + No_j - 1, ] <- c((No_i + No_j - 1), pubmed_hnscc_df_sorted$PMID[curation_i],
pubmed_hnscc_df_sorted$Diseases[curation_i],
unlist(strsplit(em_hnscc_PMID_list[[res_index[1]]]$Genes[No_j], ">")))
}
No_i <- No_i + No_j
# EntrezGene 4313 (MMP2), 4318 (MMP9); 83639 (TEX101) at PMID 23481573
# Cancer Biomark. 2012-2013;12(3):141-8. doi: 10.3233/CBM-130302.
# [Overexpression of TEX101, a potential novel cancer marker, in head and neck squamous cell carcinoma.]
} # from 1 to 976 entries in [pubmed_hnscc_genes]