-
Notifications
You must be signed in to change notification settings - Fork 5
/
Gene_Centric_Coding_Results_Summary_incl_ptv.R
1275 lines (1039 loc) · 60.4 KB
/
Gene_Centric_Coding_Results_Summary_incl_ptv.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
#' Summarize gene-centric coding analysis results generated by \code{STAARpipeline} package and
#' perform conditional analysis for (unconditionally) significant coding masks (including masks ptv and ptv_ds) by adjusting for a given list of known variants
#'
#' The \code{Gene_Centric_Coding_Results_Summary_incl_ptv} function takes in the objects of gene-centric coding analysis results
#' generated by \code{STAARpipeline} package,
#' the object from fitting the null model, and the set of known variants to be adjusted for in conditional analysis
#' to summarize the gene-centric coding analysis results and analyze the conditional association between a quantitative/dichotomous phenotype
#' (including imbalanced case-control design) and
#' the rare variants in the unconditional significant coding masks.
#' @param agds_dir file directory of annotated GDS (aGDS) files for all chromosomes (1-22)
#' @param gene_centric_coding_jobs_num the number of gene-centric coding analysis results generated by \code{STAARpipeline} package.
#' @param input_path the directory of gene-centric coding analysis results that generated by \code{STAARpipeline} package.
#' @param output_path the directory for the output files.
#' @param gene_centric_results_name file name of gene-centric coding analysis results generated by \code{STAARpipeline} package.
#' @param obj_nullmodel an object from fitting the null model, which is either the output from \code{fit_nullmodel} function in the \code{STAARpipeline} package,
#' or the output from \code{fitNullModel} function in the \code{GENESIS} package and transformed using the \code{genesis2staar_nullmodel} function in the \code{STAARpipeline} package.
#' @param known_loci the data frame of variants to be adjusted for in conditional analysis and should
#' contain 4 columns in the following order: chromosome (CHR), position (POS), reference allele (REF),
#' and alternative allele (ALT) (default = NULL).
#' @param cMAC_cutoff the cutoff of the minimum number of the cumulative minor allele of variants in the masks
#' when summarizing the results (default = 0).
#' @param method_cond a character value indicating the method for conditional analysis.
#' \code{optimal} refers to regressing residuals from the null model on \code{known_loci}
#' as well as all covariates used in fitting the null model (fully adjusted) and taking the residuals;
#' \code{naive} refers to regressing residuals from the null model on \code{known_loci}
#' and taking the residuals (default = \code{optimal}).
#' @param rare_maf_cutoff the cutoff of maximum minor allele frequency in
#' defining rare variants (default = 0.01).
#' @param QC_label channel name of the QC label in the GDS/aGDS file (default = "annotation/filter").
#' @param variant_type type of variant included in the analysis. Choices include "SNV", "Indel", or "variant" (default = "SNV").
#' @param geno_missing_imputation method of handling missing genotypes. Either "mean" or "minor" (default = "mean").
#' @param Annotation_dir channel name of the annotations in the aGDS file \cr (default = "annotation/info/FunctionalAnnotation").
#' @param Annotation_name_catalog a data frame containing the name and the corresponding channel name in the aGDS file.
#' @param Use_annotation_weights use annotations as weights or not (default = FALSE).
#' @param Annotation_name a vector of annotation names used in STAAR (default = NULL).
#' @param alpha p-value threshold of significant results (default = 2.5E-06).
#' @param manhattan_plot output manhattan plot or not (default = FALSE).
#' @param QQ_plot output Q-Q plot or not (default = FALSE).
#' @param cond_null_model_name the null model name for conditional analysis in the SPA setting, only used for imbalanced case-control setting (default = NULL).
#' @param cond_null_model_dir the directory of storing the null model for conditional analysis in the SPA setting, only used for imbalanced case-control setting (default = NULL).
#' @param SPA_p_filter logical: are only the variants with a normal approximation based p-value smaller than a pre-specified threshold use the SPA method to recalculate the p-value, only used for imbalanced case-control setting (default = FALSE).
#' @param p_filter_cutoff threshold for the p-value recalculation using the SPA method, only used for imbalanced case-control setting (default = 0.05).
#' @return The function returns the following analysis results:
#' @return \code{coding_sig.csv}: a matrix that summarizes the unconditional significant coding masks detected by STAAR-O or STAAR-B in imbalanced case-control setting (STAAR-O/-B pvalue smaller than the threshold alpha),
#' including gene name ("Gene name"), chromosome ("chr"), coding functional category ("Category"), number of variants ("#SNV"),
#' and unconditional p-values of set-based tests SKAT ("SKAT(1,25)"), Burden ("Burden(1,1)"), ACAT-V ("ACAT-V(1,25)") and STAAR-O ("STAAR-O")
#' or unconditional p-values of set-based tests Burden ("Burden(1,1)") and STAAR-B ("STAAR-B") for imbalanced case-control setting.
#' @return \code{coding_sig_cond.csv}: a matrix that summarized the conditional analysis results of unconditional significant coding masks detected by STAAR-O or STAAR-B in imbalanced case-control setting (available if known_loci is not a NULL),
#' including gene name ("Gene name"), chromosome ("chr"), coding functional category ("Category"), number of variants ("#SNV"),
#' and conditional p-values of set-based tests SKAT ("SKAT(1,25)"), Burden ("Burden(1,1)"), ACAT-V ("ACAT-V(1,25)") and STAAR-O ("STAAR-O")
#' or conditional p-values of set-based tests Burden ("Burden(1,1)") and STAAR-B ("STAAR-B") for imbalanced case-control setting.
#' @return \code{results_plof_genome.Rdata}: a matrix contains the STAAR p-values (including STAAR-O or STAAR-B in imbalanced case-control setting) of the coding mask defined by the putative loss of function variants (plof) for all protein-coding genes across the genome.
#' @return \code{plof_sig.csv}: a matrix contains the unconditional STAAR p-values (including STAAR-O or STAAR-B in imbalanced case-control setting) of the unconditional significant plof masks.
#' @return \code{plof_sig_cond.csv}: a matrix contains the conditional STAAR p-values (including STAAR-O or STAAR-B in imbalanced case-control setting) of the unconditional significant plof masks (available if known_loci is not a NULL).
#' @return \code{results_plof_ds_genome.Rdata}: a matrix contains the STAAR p-values (including STAAR-O or STAAR-B in imbalanced case-control setting) of the coding mask defined by the putative loss of function variants and disruptive missense variants (plof_ds) for all protein-coding genes across the genome.
#' @return \code{plof_ds_sig.csv}: a matrix contains the unconditional STAAR p-values (including STAAR-O or STAAR-B in imbalanced case-control setting) of the unconditional significant plof_ds masks.
#' @return \code{plof_ds_sig_cond.csv}: a matrix contains the conditional STAAR p-values (including STAAR-O or STAAR-B in imbalanced case-control setting) of the unconditional significant plof_ds masks (available if known_loci is not a NULL).
#' @return \code{results_ptv_genome.Rdata}: a matrix contains the STAAR p-values (including STAAR-O or STAAR-B in imbalanced case-control setting) of the coding mask defined by the protein-truncating variants (ptv) for all protein-coding genes across the genome.
#' @return \code{ptv_sig.csv}: a matrix contains the unconditional STAAR p-values (including STAAR-O or STAAR-B in imbalanced case-control setting) of the unconditional significant ptv masks.
#' @return \code{ptv_sig_cond.csv}: a matrix contains the conditional STAAR p-values (including STAAR-O or STAAR-B in imbalanced case-control setting) of the unconditional significant ptv masks (available if known_loci is not a NULL).
#' @return \code{results_ptv_ds_genome.Rdata}: a matrix contains the STAAR p-values (including STAAR-O or STAAR-B in imbalanced case-control setting) of the coding mask defined by the protein-truncating variants and disruptive missense variants (ptv_ds) for all protein-coding genes across the genome.
#' @return \code{ptv_ds_sig.csv}: a matrix contains the unconditional STAAR p-values (including STAAR-O or STAAR-B in imbalanced case-control setting) of the unconditional significant ptv_ds masks.
#' @return \code{ptv_ds_sig_cond.csv}: a matrix contains the conditional STAAR p-values (including STAAR-O or STAAR-B in imbalanced case-control setting) of the unconditional significant ptv_ds masks (available if known_loci is not a NULL).
#' @return \code{results_disruptive_missense_genome.Rdata}: a matrix contains the STAAR p-values (including STAAR-O or STAAR-B in imbalanced case-control setting) of the coding mask defined by the disruptive missense variants (disruptive_missense) for all protein-coding genes across the genome.
#' @return \code{disruptive_missense_sig.csv}: a matrix contains the unconditional STAAR p-values (including STAAR-O or STAAR-B in imbalanced case-control setting) of the unconditional significant disruptive_missense masks.
#' @return \code{disruptive_missense_sig_cond.csv}: a matrix contains the conditional STAAR p-values (including STAAR-O or STAAR-B in imbalanced case-control setting) of the unconditional significant disruptive_missense masks (available if known_loci is not a NULL).
#' @return \code{results_missense_genome.Rdata}: a matrix contains the STAAR p-values (including STAAR-O or STAAR-B in imbalanced case-control setting) of the coding mask defined by the missense variants (missense) for all protein-coding genes across the genome.
#' @return \code{missense_sig.csv}: a matrix contains the unconditional STAAR p-values (including STAAR-O or STAAR-B in imbalanced case-control setting) of the unconditional significant missense masks.
#' @return \code{missense_sig_cond.csv}: a matrix contains the conditional STAAR p-values (including STAAR-O or STAAR-B in imbalanced case-control setting) of the unconditional significant missense masks (available if known_loci is not a NULL).
#' @return \code{results_synonymous_genome.Rdata}: a matrix contains the STAAR p-values (including STAAR-O or STAAR-B in imbalanced case-control setting) of the coding mask defined by the synonymous variants (synonymous) for all protein-coding genes across the genome.
#' @return \code{synonymous_sig.csv}: a matrix contains the unconditional STAAR p-values (including STAAR-O or STAAR-B in imbalanced case-control setting) of the unconditional significant synonymous masks.
#' @return \code{synonymous_sig_cond.csv}: a matrix contains the conditional STAAR p-values (including STAAR-O or STAAR-B in imbalanced case-control setting) of the unconditional significant synonymous masks (available if known_loci is not a NULL).
#' @return manhattan plot (optional) and Q-Q plot (optional) of the gene-centric coding analysis results.
#' @references Li, Z., Li, X., et al. (2022). A framework for detecting
#' noncoding rare-variant associations of large-scale whole-genome sequencing
#' studies. \emph{Nature Methods}, \emph{19}(12), 1599-1611.
#' (\href{https://doi.org/10.1038/s41592-022-01640-x}{pub})
#' @export
Gene_Centric_Coding_Results_Summary_incl_ptv <- function(agds_dir,gene_centric_coding_jobs_num,input_path,output_path,gene_centric_results_name,
obj_nullmodel,known_loci=NULL,cMAC_cutoff=0,
method_cond=c("optimal","naive"),rare_maf_cutoff=0.01,
QC_label="annotation/filter",variant_type=c("SNV","Indel","variant"),geno_missing_imputation=c("mean","minor"),
Annotation_dir="annotation/info/FunctionalAnnotation",Annotation_name_catalog,
Use_annotation_weights=FALSE,Annotation_name=NULL,
alpha=2.5E-06,manhattan_plot=FALSE,QQ_plot=FALSE,
cond_null_model_name=NULL,cond_null_model_dir=NULL,
SPA_p_filter=FALSE,p_filter_cutoff=0.05){
## evaluate choices
method_cond <- match.arg(method_cond)
variant_type <- match.arg(variant_type)
geno_missing_imputation <- match.arg(geno_missing_imputation)
## SPA status
if(!is.null(obj_nullmodel$use_SPA))
{
use_SPA <- obj_nullmodel$use_SPA
}else
{
use_SPA <- FALSE
}
#######################################################
# summarize unconditional analysis results
#######################################################
results_coding_genome <- c()
for(kk in 1:gene_centric_coding_jobs_num)
{
print(kk)
results_coding <- get(load(paste0(input_path,gene_centric_results_name,"_",kk,".Rdata")))
results_coding_genome <- c(results_coding_genome,results_coding)
}
results_plof_genome <- c()
results_plof_ds_genome <- c()
results_missense_genome <- c()
results_disruptive_missense_genome <- c()
results_synonymous_genome <- c()
results_ptv_genome <- c()
results_ptv_ds_genome <- c()
for(kk in 1:length(results_coding_genome))
{
results <- results_coding_genome[[kk]]
if(is.null(results)==FALSE)
{
### plof
if(results[3]=="plof")
{
results_plof_genome <- rbind(results_plof_genome,results)
}
### plof_ds
if(results[3]=="plof_ds")
{
results_plof_ds_genome <- rbind(results_plof_ds_genome,results)
}
### missense
if(results[3]=="missense")
{
results_missense_genome <- rbind(results_missense_genome,results)
}
### disruptive_missense
if(results[3]=="disruptive_missense")
{
results_disruptive_missense_genome <- rbind(results_disruptive_missense_genome,results)
}
### synonymous
if(results[3]=="synonymous")
{
results_synonymous_genome <- rbind(results_synonymous_genome,results)
}
### ptv
if(results[3]=="ptv")
{
results_ptv_genome <- rbind(results_ptv_genome,results)
}
### ptv_ds
if(results[3]=="ptv_ds")
{
results_ptv_ds_genome <- rbind(results_ptv_ds_genome,results)
}
}
if(kk%%1000==0)
{
print(kk)
}
}
###### cMAC_cutoff
# plof
results_plof_genome <- results_plof_genome[results_plof_genome[,"cMAC"]>cMAC_cutoff,]
# plof + disruptive missense
results_plof_ds_genome <- results_plof_ds_genome[results_plof_ds_genome[,"cMAC"]>cMAC_cutoff,]
# missense
results_missense_genome <- results_missense_genome[results_missense_genome[,"cMAC"]>cMAC_cutoff,]
# disruptive missense
results_disruptive_missense_genome <- results_disruptive_missense_genome[results_disruptive_missense_genome[,"cMAC"]>cMAC_cutoff,]
# synonymous
results_synonymous_genome <- results_synonymous_genome[results_synonymous_genome[,"cMAC"]>cMAC_cutoff,]
# ptv
results_ptv_genome <- results_ptv_genome[results_ptv_genome[,"cMAC"]>cMAC_cutoff,]
# ptv + disruptive missense
results_ptv_ds_genome <- results_ptv_ds_genome[results_ptv_ds_genome[,"cMAC"]>cMAC_cutoff,]
###### whole-genome results
# plof
save(results_plof_genome,file=paste0(output_path,"plof.Rdata"))
# plof + disruptive missense
save(results_plof_ds_genome,file=paste0(output_path,"plof_ds.Rdata"))
# missense
save(results_missense_genome,file=paste0(output_path,"missense.Rdata"))
# disruptive missense
save(results_disruptive_missense_genome,file=paste0(output_path,"disruptive_missense.Rdata"))
# synonymous
save(results_synonymous_genome,file=paste0(output_path,"synonymous.Rdata"))
# ptv
save(results_ptv_genome,file=paste0(output_path,"ptv.Rdata"))
# ptv + disruptive missense
save(results_ptv_ds_genome,file=paste0(output_path,"ptv_ds.Rdata"))
if(use_SPA)
{
###### significant results
# plof
plof_sig <- results_plof_genome[results_plof_genome[,"STAAR-B"]<alpha,,drop=FALSE]
write.csv(plof_sig,file=paste0(output_path,"plof_sig.csv"))
# missense
missense_sig <- results_missense_genome[results_missense_genome[,"STAAR-B"]<alpha,,drop=FALSE]
write.csv(missense_sig,file=paste0(output_path,"missense_sig.csv"))
# synonymous
synonymous_sig <- results_synonymous_genome[results_synonymous_genome[,"STAAR-B"]<alpha,,drop=FALSE]
write.csv(synonymous_sig,file=paste0(output_path,"synonymous_sig.csv"))
# plof_ds
plof_ds_sig <- results_plof_ds_genome[results_plof_ds_genome[,"STAAR-B"]<alpha,,drop=FALSE]
write.csv(plof_ds_sig,file=paste0(output_path,"plof_ds_sig.csv"))
# disruptive_missense
disruptive_missense_sig <- results_disruptive_missense_genome[results_disruptive_missense_genome[,"STAAR-B"]<alpha,,drop=FALSE]
write.csv(disruptive_missense_sig,file=paste0(output_path,"disruptive_missense_sig.csv"))
# ptv
ptv_sig <- results_ptv_genome[results_ptv_genome[,"STAAR-B"]<alpha,,drop=FALSE]
write.csv(ptv_sig,file=paste0(output_path,"ptv_sig.csv"))
# ptv_ds
ptv_ds_sig <- results_ptv_ds_genome[results_ptv_ds_genome[,"STAAR-B"]<alpha,,drop=FALSE]
write.csv(ptv_ds_sig,file=paste0(output_path,"ptv_ds_sig.csv"))
# coding results
coding_sig <- rbind(plof_sig[,c("Gene name","Chr","Category","#SNV","cMAC","Burden(1,1)","STAAR-B")],
missense_sig[,c("Gene name","Chr","Category","#SNV","cMAC","Burden(1,1)","STAAR-B")])
coding_sig <- rbind(coding_sig,synonymous_sig[,c("Gene name","Chr","Category","#SNV","cMAC","Burden(1,1)","STAAR-B")])
coding_sig <- rbind(coding_sig,plof_ds_sig[,c("Gene name","Chr","Category","#SNV","cMAC","Burden(1,1)","STAAR-B")])
coding_sig <- rbind(coding_sig,disruptive_missense_sig[,c("Gene name","Chr","Category","#SNV","cMAC","Burden(1,1)","STAAR-B")])
coding_sig <- rbind(coding_sig,ptv_sig[,c("Gene name","Chr","Category","#SNV","cMAC","Burden(1,1)","STAAR-B")])
coding_sig <- rbind(coding_sig,ptv_ds_sig[,c("Gene name","Chr","Category","#SNV","cMAC","Burden(1,1)","STAAR-B")])
write.csv(coding_sig,file=paste0(output_path,"coding_sig.csv"))
}else
{
# plof
plof_sig <- results_plof_genome[results_plof_genome[,"STAAR-O"]<alpha,,drop=FALSE]
write.csv(plof_sig,file=paste0(output_path,"plof_sig.csv"))
# missense
missense_sig <- results_missense_genome[results_missense_genome[,"STAAR-O"]<alpha,,drop=FALSE]
write.csv(missense_sig,file=paste0(output_path,"missense_sig.csv"))
# synonymous
synonymous_sig <- results_synonymous_genome[results_synonymous_genome[,"STAAR-O"]<alpha,,drop=FALSE]
write.csv(synonymous_sig,file=paste0(output_path,"synonymous_sig.csv"))
# plof_ds
plof_ds_sig <- results_plof_ds_genome[results_plof_ds_genome[,"STAAR-O"]<alpha,,drop=FALSE]
write.csv(plof_ds_sig,file=paste0(output_path,"plof_ds_sig.csv"))
# disruptive_missense
disruptive_missense_sig <- results_disruptive_missense_genome[results_disruptive_missense_genome[,"STAAR-O"]<alpha,,drop=FALSE]
write.csv(disruptive_missense_sig,file=paste0(output_path,"disruptive_missense_sig.csv"))
# ptv
ptv_sig <- results_ptv_genome[results_ptv_genome[,"STAAR-O"]<alpha,,drop=FALSE]
write.csv(ptv_sig,file=paste0(output_path,"ptv_sig.csv"))
# ptv_ds
ptv_ds_sig <- results_ptv_ds_genome[results_ptv_ds_genome[,"STAAR-O"]<alpha,,drop=FALSE]
write.csv(ptv_ds_sig,file=paste0(output_path,"ptv_ds_sig.csv"))
# coding results
coding_sig <- rbind(plof_sig[,c("Gene name","Chr","Category","#SNV","cMAC","SKAT(1,25)","Burden(1,1)","ACAT-V(1,25)","STAAR-O")],
missense_sig[,c("Gene name","Chr","Category","#SNV","cMAC","SKAT(1,25)","Burden(1,1)","ACAT-V(1,25)","STAAR-O")])
coding_sig <- rbind(coding_sig,synonymous_sig[,c("Gene name","Chr","Category","#SNV","cMAC","SKAT(1,25)","Burden(1,1)","ACAT-V(1,25)","STAAR-O")])
coding_sig <- rbind(coding_sig,plof_ds_sig[,c("Gene name","Chr","Category","#SNV","cMAC","SKAT(1,25)","Burden(1,1)","ACAT-V(1,25)","STAAR-O")])
coding_sig <- rbind(coding_sig,disruptive_missense_sig[,c("Gene name","Chr","Category","#SNV","cMAC","SKAT(1,25)","Burden(1,1)","ACAT-V(1,25)","STAAR-O")])
coding_sig <- rbind(coding_sig,ptv_sig[,c("Gene name","Chr","Category","#SNV","cMAC","SKAT(1,25)","Burden(1,1)","ACAT-V(1,25)","STAAR-O")])
coding_sig <- rbind(coding_sig,ptv_ds_sig[,c("Gene name","Chr","Category","#SNV","cMAC","SKAT(1,25)","Burden(1,1)","ACAT-V(1,25)","STAAR-O")])
write.csv(coding_sig,file=paste0(output_path,"coding_sig.csv"))
}
#######################################################
# conditional analysis
#######################################################
if(length(known_loci)!=0)
{
if(!use_SPA)
{
### plof
plof_sig_cond <- c()
if(length(plof_sig)!=0)
{
if((class(plof_sig)[1]!="matrix")&(class(plof_sig)[1]!="data.frame"))
{
plof_sig <- matrix(plof_sig,nrow=1)
}
for(k in 1:dim(plof_sig)[1])
{
chr <- as.numeric(plof_sig[k,2])
gene_name <- as.character(plof_sig[k,1])
category <- as.character(plof_sig[k,3])
gds.path <- agds_dir[chr]
genofile <- seqOpen(gds.path)
res_cond <- Gene_Centric_Coding_cond(chr=chr,gene_name=gene_name,category=category,genofile=genofile,
obj_nullmodel=obj_nullmodel,known_loci=known_loci,rare_maf_cutoff=rare_maf_cutoff,
variant_type=variant_type,geno_missing_imputation=geno_missing_imputation,QC_label=QC_label,
Annotation_dir=Annotation_dir,Annotation_name_catalog=Annotation_name_catalog,
Use_annotation_weights=Use_annotation_weights,Annotation_name=Annotation_name)
plof_sig_cond <- rbind(plof_sig_cond,res_cond)
seqClose(genofile)
}
}
write.csv(plof_sig_cond,file=paste0(output_path,"plof_sig_cond.csv"))
### missense
missense_sig_cond <- c()
if(length(missense_sig)!=0)
{
if((class(missense_sig)[1]!="matrix")&(class(missense_sig)[1]!="data.frame"))
{
missense_sig <- matrix(missense_sig,nrow=1)
}
for(k in 1:dim(missense_sig)[1])
{
chr <- as.numeric(missense_sig[k,2])
gene_name <- as.character(missense_sig[k,1])
category <- as.character(missense_sig[k,3])
gds.path <- agds_dir[chr]
genofile <- seqOpen(gds.path)
res_cond <- Gene_Centric_Coding_cond(chr=chr,gene_name=gene_name,category=category,genofile=genofile,
obj_nullmodel=obj_nullmodel,known_loci=known_loci,rare_maf_cutoff=rare_maf_cutoff,
variant_type=variant_type,geno_missing_imputation=geno_missing_imputation,QC_label=QC_label,
Annotation_dir=Annotation_dir,Annotation_name_catalog=Annotation_name_catalog,
Use_annotation_weights=Use_annotation_weights,Annotation_name=Annotation_name)
missense_sig_cond <- rbind(missense_sig_cond,res_cond)
seqClose(genofile)
}
}
write.csv(missense_sig_cond,file=paste0(output_path,"missense_sig_cond.csv"))
### synonymous
synonymous_sig_cond <- c()
if(length(synonymous_sig)!=0)
{
if((class(synonymous_sig)[1]!="matrix")&(class(synonymous_sig)[1]!="data.frame"))
{
synonymous_sig <- matrix(synonymous_sig,nrow=1)
}
for(k in 1:dim(synonymous_sig)[1])
{
chr <- as.numeric(synonymous_sig[k,2])
gene_name <- as.character(synonymous_sig[k,1])
category <- as.character(synonymous_sig[k,3])
gds.path <- agds_dir[chr]
genofile <- seqOpen(gds.path)
res_cond <- Gene_Centric_Coding_cond(chr=chr,gene_name=gene_name,category=category,genofile=genofile,
obj_nullmodel=obj_nullmodel,known_loci=known_loci,rare_maf_cutoff=rare_maf_cutoff,
variant_type=variant_type,geno_missing_imputation=geno_missing_imputation,QC_label=QC_label,
Annotation_dir=Annotation_dir,Annotation_name_catalog=Annotation_name_catalog,
Use_annotation_weights=Use_annotation_weights,Annotation_name=Annotation_name)
synonymous_sig_cond <- rbind(synonymous_sig_cond,res_cond)
seqClose(genofile)
}
}
write.csv(synonymous_sig_cond,file=paste0(output_path,"synonymous_sig_cond.csv"))
### plof_ds
plof_ds_sig_cond <- c()
if(length(plof_ds_sig)!=0)
{
if((class(plof_ds_sig)[1]!="matrix")&(class(plof_ds_sig)[1]!="data.frame"))
{
plof_ds_sig <- matrix(plof_ds_sig,nrow=1)
}
for(k in 1:dim(plof_ds_sig)[1])
{
chr <- as.numeric(plof_ds_sig[k,2])
gene_name <- as.character(plof_ds_sig[k,1])
category <- as.character(plof_ds_sig[k,3])
gds.path <- agds_dir[chr]
genofile <- seqOpen(gds.path)
res_cond <- Gene_Centric_Coding_cond(chr=chr,gene_name=gene_name,category=category,genofile=genofile,
obj_nullmodel=obj_nullmodel,known_loci=known_loci,rare_maf_cutoff=rare_maf_cutoff,
variant_type=variant_type,geno_missing_imputation=geno_missing_imputation,QC_label=QC_label,
Annotation_dir=Annotation_dir,Annotation_name_catalog=Annotation_name_catalog,
Use_annotation_weights=Use_annotation_weights,Annotation_name=Annotation_name)
plof_ds_sig_cond <- rbind(plof_ds_sig_cond,res_cond)
seqClose(genofile)
}
}
write.csv(plof_ds_sig_cond,file=paste0(output_path,"plof_ds_sig_cond.csv"))
### disruptive_missense
disruptive_missense_sig_cond <- c()
if(length(disruptive_missense_sig)!=0)
{
if((class(disruptive_missense_sig)[1]!="matrix")&(class(disruptive_missense_sig)[1]!="data.frame"))
{
disruptive_missense_sig <- matrix(disruptive_missense_sig,nrow=1)
}
for(k in 1:dim(disruptive_missense_sig)[1])
{
chr <- as.numeric(disruptive_missense_sig[k,2])
gene_name <- as.character(disruptive_missense_sig[k,1])
category <- as.character(disruptive_missense_sig[k,3])
gds.path <- agds_dir[chr]
genofile <- seqOpen(gds.path)
res_cond <- Gene_Centric_Coding_cond(chr=chr,gene_name=gene_name,category=category,genofile=genofile,
obj_nullmodel=obj_nullmodel,known_loci=known_loci,rare_maf_cutoff=rare_maf_cutoff,
variant_type=variant_type,geno_missing_imputation=geno_missing_imputation,QC_label=QC_label,
Annotation_dir=Annotation_dir,Annotation_name_catalog=Annotation_name_catalog,
Use_annotation_weights=Use_annotation_weights,Annotation_name=Annotation_name)
disruptive_missense_sig_cond <- rbind(disruptive_missense_sig_cond,res_cond)
seqClose(genofile)
}
}
write.csv(disruptive_missense_sig_cond,file=paste0(output_path,"disruptive_missense_sig_cond.csv"))
### ptv
ptv_sig_cond <- c()
if(length(ptv_sig)!=0)
{
if((class(ptv_sig)[1]!="matrix")&(class(ptv_sig)[1]!="data.frame"))
{
ptv_sig <- matrix(ptv_sig,nrow=1)
}
for(k in 1:dim(ptv_sig)[1])
{
chr <- as.numeric(ptv_sig[k,2])
gene_name <- as.character(ptv_sig[k,1])
category <- as.character(ptv_sig[k,3])
gds.path <- agds_dir[chr]
genofile <- seqOpen(gds.path)
res_cond <- Gene_Centric_Coding_cond(chr=chr,gene_name=gene_name,category=category,genofile=genofile,
obj_nullmodel=obj_nullmodel,known_loci=known_loci,rare_maf_cutoff=rare_maf_cutoff,
variant_type=variant_type,geno_missing_imputation=geno_missing_imputation,QC_label=QC_label,
Annotation_dir=Annotation_dir,Annotation_name_catalog=Annotation_name_catalog,
Use_annotation_weights=Use_annotation_weights,Annotation_name=Annotation_name)
ptv_sig_cond <- rbind(ptv_sig_cond,res_cond)
seqClose(genofile)
}
}
write.csv(ptv_sig_cond,file=paste0(output_path,"ptv_sig_cond.csv"))
### ptv_ds
ptv_ds_sig_cond <- c()
if(length(ptv_ds_sig)!=0)
{
if((class(ptv_ds_sig)[1]!="matrix")&(class(ptv_ds_sig)[1]!="data.frame"))
{
ptv_ds_sig <- matrix(ptv_ds_sig,nrow=1)
}
for(k in 1:dim(ptv_ds_sig)[1])
{
chr <- as.numeric(ptv_ds_sig[k,2])
gene_name <- as.character(ptv_ds_sig[k,1])
category <- as.character(ptv_ds_sig[k,3])
gds.path <- agds_dir[chr]
genofile <- seqOpen(gds.path)
res_cond <- Gene_Centric_Coding_cond(chr=chr,gene_name=gene_name,category=category,genofile=genofile,
obj_nullmodel=obj_nullmodel,known_loci=known_loci,rare_maf_cutoff=rare_maf_cutoff,
variant_type=variant_type,geno_missing_imputation=geno_missing_imputation,QC_label=QC_label,
Annotation_dir=Annotation_dir,Annotation_name_catalog=Annotation_name_catalog,
Use_annotation_weights=Use_annotation_weights,Annotation_name=Annotation_name)
ptv_ds_sig_cond <- rbind(ptv_ds_sig_cond,res_cond)
seqClose(genofile)
}
}
write.csv(ptv_ds_sig_cond,file=paste0(output_path,"ptv_ds_sig_cond.csv"))
## coding cond
coding_sig_cond <- rbind(plof_sig_cond[,c("Gene name","Chr","Category","#SNV","cMAC","SKAT(1,25)","Burden(1,1)","ACAT-V(1,25)","STAAR-O")],
missense_sig_cond[,c("Gene name","Chr","Category","#SNV","cMAC","SKAT(1,25)","Burden(1,1)","ACAT-V(1,25)","STAAR-O")])
coding_sig_cond <- rbind(coding_sig_cond,synonymous_sig_cond[,c("Gene name","Chr","Category","#SNV","cMAC","SKAT(1,25)","Burden(1,1)","ACAT-V(1,25)","STAAR-O")])
coding_sig_cond <- rbind(coding_sig_cond,plof_ds_sig_cond[,c("Gene name","Chr","Category","#SNV","cMAC","SKAT(1,25)","Burden(1,1)","ACAT-V(1,25)","STAAR-O")])
coding_sig_cond <- rbind(coding_sig_cond,disruptive_missense_sig_cond[,c("Gene name","Chr","Category","#SNV","cMAC","SKAT(1,25)","Burden(1,1)","ACAT-V(1,25)","STAAR-O")])
coding_sig_cond <- rbind(coding_sig_cond,ptv_sig_cond[,c("Gene name","Chr","Category","#SNV","cMAC","SKAT(1,25)","Burden(1,1)","ACAT-V(1,25)","STAAR-O")])
coding_sig_cond <- rbind(coding_sig_cond,ptv_ds_sig_cond[,c("Gene name","Chr","Category","#SNV","cMAC","SKAT(1,25)","Burden(1,1)","ACAT-V(1,25)","STAAR-O")])
write.csv(coding_sig_cond,file=paste0(output_path,"coding_sig_cond.csv"))
}else
{
### synonymous
synonymous_sig_cond <- c()
if(length(synonymous_sig)!=0)
{
if((class(synonymous_sig)[1]!="matrix")&(class(synonymous_sig)[1]!="data.frame"))
{
synonymous_sig <- matrix(synonymous_sig,nrow=1)
}
for(k in 1:dim(synonymous_sig)[1])
{
chr <- as.numeric(synonymous_sig[k,2])
gene_name <- as.character(synonymous_sig[k,1])
category <- as.character(synonymous_sig[k,3])
if(file.exists(paste0(cond_null_model_dir,cond_null_model_name,".chr",chr,".Rdata")))
{
gds.path <- agds_dir[chr]
genofile <- seqOpen(gds.path)
obj_nullmodel_cond <- get(load(paste0(cond_null_model_dir,cond_null_model_name,".chr",chr,".Rdata")))
res_cond <- Gene_Centric_Coding_cond_spa(chr=chr,gene_name=gene_name,category=category,genofile=genofile,
obj_nullmodel=obj_nullmodel_cond,known_loci=known_loci,rare_maf_cutoff=rare_maf_cutoff,
variant_type=variant_type,geno_missing_imputation=geno_missing_imputation,QC_label=QC_label,
Annotation_dir=Annotation_dir,Annotation_name_catalog=Annotation_name_catalog,
Use_annotation_weights=Use_annotation_weights,Annotation_name=Annotation_name,
SPA_p_filter=SPA_p_filter,p_filter_cutoff=p_filter_cutoff)
seqClose(genofile)
}else
{
res_cond <- synonymous_sig[k,,drop=FALSE]
res_cond[1,3] <- "synonymous_cond"
}
synonymous_sig_cond <- rbind(synonymous_sig_cond,res_cond)
}
}
write.csv(synonymous_sig_cond,file=paste0(output_path,"synonymous_sig_cond.csv"))
### plof
plof_sig_cond <- c()
if(length(plof_sig)!=0)
{
if((class(plof_sig)[1]!="matrix")&(class(plof_sig)[1]!="data.frame"))
{
plof_sig <- matrix(plof_sig,nrow=1)
}
for(k in 1:dim(plof_sig)[1])
{
chr <- as.numeric(plof_sig[k,2])
gene_name <- as.character(plof_sig[k,1])
category <- as.character(plof_sig[k,3])
if(file.exists(paste0(cond_null_model_dir,cond_null_model_name,".chr",chr,".Rdata")))
{
gds.path <- agds_dir[chr]
genofile <- seqOpen(gds.path)
obj_nullmodel_cond <- get(load(paste0(cond_null_model_dir,cond_null_model_name,".chr",chr,".Rdata")))
res_cond <- Gene_Centric_Coding_cond_spa(chr=chr,gene_name=gene_name,category=category,genofile=genofile,
obj_nullmodel=obj_nullmodel_cond,known_loci=known_loci,rare_maf_cutoff=rare_maf_cutoff,
variant_type=variant_type,geno_missing_imputation=geno_missing_imputation,QC_label=QC_label,
Annotation_dir=Annotation_dir,Annotation_name_catalog=Annotation_name_catalog,
Use_annotation_weights=Use_annotation_weights,Annotation_name=Annotation_name,
SPA_p_filter=SPA_p_filter,p_filter_cutoff=p_filter_cutoff)
seqClose(genofile)
}else
{
res_cond <- plof_sig[k,,drop=FALSE]
res_cond[1,3] <- "plof_cond"
}
plof_sig_cond <- rbind(plof_sig_cond,res_cond)
}
}
write.csv(plof_sig_cond,file=paste0(output_path,"plof_sig_cond.csv"))
### plof_ds
plof_ds_sig_cond <- c()
if(length(plof_ds_sig)!=0)
{
if((class(plof_ds_sig)[1]!="matrix")&(class(plof_ds_sig)[1]!="data.frame"))
{
plof_ds_sig <- matrix(plof_ds_sig,nrow=1)
}
for(k in 1:dim(plof_ds_sig)[1])
{
chr <- as.numeric(plof_ds_sig[k,2])
gene_name <- as.character(plof_ds_sig[k,1])
category <- as.character(plof_ds_sig[k,3])
if(file.exists(paste0(cond_null_model_dir,cond_null_model_name,".chr",chr,".Rdata")))
{
gds.path <- agds_dir[chr]
genofile <- seqOpen(gds.path)
obj_nullmodel_cond <- get(load(paste0(cond_null_model_dir,cond_null_model_name,".chr",chr,".Rdata")))
res_cond <- Gene_Centric_Coding_cond_spa(chr=chr,gene_name=gene_name,category=category,genofile=genofile,
obj_nullmodel=obj_nullmodel_cond,known_loci=known_loci,rare_maf_cutoff=rare_maf_cutoff,
variant_type=variant_type,geno_missing_imputation=geno_missing_imputation,QC_label=QC_label,
Annotation_dir=Annotation_dir,Annotation_name_catalog=Annotation_name_catalog,
Use_annotation_weights=Use_annotation_weights,Annotation_name=Annotation_name,
SPA_p_filter=SPA_p_filter,p_filter_cutoff=p_filter_cutoff)
seqClose(genofile)
}else
{
res_cond <- plof_ds_sig[k,,drop=FALSE]
res_cond[1,3] <- "plof_ds_cond"
}
plof_ds_sig_cond <- rbind(plof_ds_sig_cond,res_cond)
}
}
write.csv(plof_ds_sig_cond,file=paste0(output_path,"plof_ds_sig_cond.csv"))
### missense
missense_sig_cond <- c()
if(length(missense_sig)!=0)
{
if((class(missense_sig)[1]!="matrix")&(class(missense_sig)[1]!="data.frame"))
{
missense_sig <- matrix(missense_sig,nrow=1)
}
for(k in 1:dim(missense_sig)[1])
{
chr <- as.numeric(missense_sig[k,2])
gene_name <- as.character(missense_sig[k,1])
category <- as.character(missense_sig[k,3])
if(file.exists(paste0(cond_null_model_dir,cond_null_model_name,".chr",chr,".Rdata")))
{
gds.path <- agds_dir[chr]
genofile <- seqOpen(gds.path)
obj_nullmodel_cond <- get(load(paste0(cond_null_model_dir,cond_null_model_name,".chr",chr,".Rdata")))
res_cond <- Gene_Centric_Coding_cond_spa(chr=chr,gene_name=gene_name,category=category,genofile=genofile,
obj_nullmodel=obj_nullmodel_cond,known_loci=known_loci,rare_maf_cutoff=rare_maf_cutoff,
variant_type=variant_type,geno_missing_imputation=geno_missing_imputation,QC_label=QC_label,
Annotation_dir=Annotation_dir,Annotation_name_catalog=Annotation_name_catalog,
Use_annotation_weights=Use_annotation_weights,Annotation_name=Annotation_name,
SPA_p_filter=SPA_p_filter,p_filter_cutoff=p_filter_cutoff)
seqClose(genofile)
}else
{
res_cond <- missense_sig[k,,drop=FALSE]
res_cond[1,3] <- "missense_cond"
}
missense_sig_cond <- rbind(missense_sig_cond,res_cond)
}
}
write.csv(missense_sig_cond,file=paste0(output_path,"missense_sig_cond.csv"))
### disruptive_missense
disruptive_missense_sig_cond <- c()
if(length(disruptive_missense_sig)!=0)
{
if((class(disruptive_missense_sig)[1]!="matrix")&(class(disruptive_missense_sig)[1]!="data.frame"))
{
disruptive_missense_sig <- matrix(disruptive_missense_sig,nrow=1)
}
for(k in 1:dim(disruptive_missense_sig)[1])
{
chr <- as.numeric(disruptive_missense_sig[k,2])
gene_name <- as.character(disruptive_missense_sig[k,1])
category <- as.character(disruptive_missense_sig[k,3])
if(file.exists(paste0(cond_null_model_dir,cond_null_model_name,".chr",chr,".Rdata")))
{
gds.path <- agds_dir[chr]
genofile <- seqOpen(gds.path)
obj_nullmodel_cond <- get(load(paste0(cond_null_model_dir,cond_null_model_name,".chr",chr,".Rdata")))
res_cond <- Gene_Centric_Coding_cond_spa(chr=chr,gene_name=gene_name,category=category,genofile=genofile,
obj_nullmodel=obj_nullmodel_cond,known_loci=known_loci,rare_maf_cutoff=rare_maf_cutoff,
variant_type=variant_type,geno_missing_imputation=geno_missing_imputation,QC_label=QC_label,
Annotation_dir=Annotation_dir,Annotation_name_catalog=Annotation_name_catalog,
Use_annotation_weights=Use_annotation_weights,Annotation_name=Annotation_name,
SPA_p_filter=SPA_p_filter,p_filter_cutoff=p_filter_cutoff)
seqClose(genofile)
}else
{
res_cond <- disruptive_missense_sig[k,,drop=FALSE]
res_cond[1,3] <- "disruptive_missense_cond"
}
disruptive_missense_sig_cond <- rbind(disruptive_missense_sig_cond,res_cond)
}
}
write.csv(disruptive_missense_sig_cond,file=paste0(output_path,"disruptive_missense_sig_cond.csv"))
### ptv
ptv_sig_cond <- c()
if(length(ptv_sig)!=0)
{
if((class(ptv_sig)[1]!="matrix")&(class(ptv_sig)[1]!="data.frame"))
{
ptv_sig <- matrix(ptv_sig,nrow=1)
}
for(k in 1:dim(ptv_sig)[1])
{
chr <- as.numeric(ptv_sig[k,2])
gene_name <- as.character(ptv_sig[k,1])
category <- as.character(ptv_sig[k,3])
if(file.exists(paste0(cond_null_model_dir,cond_null_model_name,".chr",chr,".Rdata")))
{
gds.path <- agds_dir[chr]
genofile <- seqOpen(gds.path)
obj_nullmodel_cond <- get(load(paste0(cond_null_model_dir,cond_null_model_name,".chr",chr,".Rdata")))
res_cond <- Gene_Centric_Coding_cond_spa(chr=chr,gene_name=gene_name,category=category,genofile=genofile,
obj_nullmodel=obj_nullmodel_cond,known_loci=known_loci,rare_maf_cutoff=rare_maf_cutoff,
variant_type=variant_type,geno_missing_imputation=geno_missing_imputation,QC_label=QC_label,
Annotation_dir=Annotation_dir,Annotation_name_catalog=Annotation_name_catalog,
Use_annotation_weights=Use_annotation_weights,Annotation_name=Annotation_name,
SPA_p_filter=SPA_p_filter,p_filter_cutoff=p_filter_cutoff)
seqClose(genofile)
}else
{
res_cond <- ptv_sig[k,,drop=FALSE]
res_cond[1,3] <- "ptv_cond"
}
ptv_sig_cond <- rbind(ptv_sig_cond,res_cond)
}
}
write.csv(ptv_sig_cond,file=paste0(output_path,"ptv_sig_cond.csv"))
### ptv_ds
ptv_ds_sig_cond <- c()
if(length(ptv_ds_sig)!=0)
{
if((class(ptv_ds_sig)[1]!="matrix")&(class(ptv_ds_sig)[1]!="data.frame"))
{
ptv_ds_sig <- matrix(ptv_ds_sig,nrow=1)
}
for(k in 1:dim(ptv_ds_sig)[1])
{
chr <- as.numeric(ptv_ds_sig[k,2])
gene_name <- as.character(ptv_ds_sig[k,1])
category <- as.character(ptv_ds_sig[k,3])
if(file.exists(paste0(cond_null_model_dir,cond_null_model_name,".chr",chr,".Rdata")))
{
gds.path <- agds_dir[chr]
genofile <- seqOpen(gds.path)
obj_nullmodel_cond <- get(load(paste0(cond_null_model_dir,cond_null_model_name,".chr",chr,".Rdata")))
res_cond <- Gene_Centric_Coding_cond_spa(chr=chr,gene_name=gene_name,category=category,genofile=genofile,
obj_nullmodel=obj_nullmodel_cond,known_loci=known_loci,rare_maf_cutoff=rare_maf_cutoff,
variant_type=variant_type,geno_missing_imputation=geno_missing_imputation,QC_label=QC_label,
Annotation_dir=Annotation_dir,Annotation_name_catalog=Annotation_name_catalog,
Use_annotation_weights=Use_annotation_weights,Annotation_name=Annotation_name,
SPA_p_filter=SPA_p_filter,p_filter_cutoff=p_filter_cutoff)
seqClose(genofile)
}else
{
res_cond <- ptv_ds_sig[k,,drop=FALSE]
res_cond[1,3] <- "ptv_ds_cond"
}
ptv_ds_sig_cond <- rbind(ptv_ds_sig_cond,res_cond)
}
}
write.csv(ptv_ds_sig_cond,file=paste0(output_path,"ptv_ds_sig_cond.csv"))
# coding results
coding_sig_cond <- rbind(plof_sig_cond[,c("Gene name","Chr","Category","#SNV","cMAC","Burden(1,1)","STAAR-B")],
missense_sig_cond[,c("Gene name","Chr","Category","#SNV","cMAC","Burden(1,1)","STAAR-B")])
coding_sig_cond <- rbind(coding_sig_cond,synonymous_sig_cond[,c("Gene name","Chr","Category","#SNV","cMAC","Burden(1,1)","STAAR-B")])
coding_sig_cond <- rbind(coding_sig_cond,plof_ds_sig_cond[,c("Gene name","Chr","Category","#SNV","cMAC","Burden(1,1)","STAAR-B")])
coding_sig_cond <- rbind(coding_sig_cond,disruptive_missense_sig_cond[,c("Gene name","Chr","Category","#SNV","cMAC","Burden(1,1)","STAAR-B")])
coding_sig_cond <- rbind(coding_sig_cond,ptv_sig_cond[,c("Gene name","Chr","Category","#SNV","cMAC","Burden(1,1)","STAAR-B")])
coding_sig_cond <- rbind(coding_sig_cond,ptv_ds_sig_cond[,c("Gene name","Chr","Category","#SNV","cMAC","Burden(1,1)","STAAR-B")])
write.csv(coding_sig_cond,file=paste0(output_path,"coding_sig_cond.csv"))
}
}
## manhattan plot
if(manhattan_plot)
{
### plof
results_STAAR <- results_plof_genome[,c(1,2,dim(results_plof_genome)[2])]
results_m <- c()
for(i in 1:dim(results_STAAR)[2])
{
results_m <- cbind(results_m,unlist(results_STAAR[,i]))
}
colnames(results_m) <- colnames(results_STAAR)
results_m <- data.frame(results_m,stringsAsFactors = FALSE)
results_m[,2] <- as.numeric(results_m[,2])
results_m[,3] <- as.numeric(results_m[,3])
genes_info_manhattan <- dplyr::left_join(genes_info,results_m,by=c("chromosome_name"="Chr","hgnc_symbol"="Gene.name"))
genes_info_manhattan[is.na(genes_info_manhattan)] <- 1
colnames(genes_info_manhattan)[dim(genes_info_manhattan)[2]] <- "plof"
### plof_ds
results_STAAR <- results_plof_ds_genome[,c(1,2,dim(results_plof_ds_genome)[2])]
results_m <- c()
for(i in 1:dim(results_STAAR)[2])
{
results_m <- cbind(results_m,unlist(results_STAAR[,i]))
}
colnames(results_m) <- colnames(results_STAAR)
results_m <- data.frame(results_m,stringsAsFactors = FALSE)
results_m[,2] <- as.numeric(results_m[,2])
results_m[,3] <- as.numeric(results_m[,3])
genes_info_manhattan <- dplyr::left_join(genes_info_manhattan,results_m,by=c("chromosome_name"="Chr","hgnc_symbol"="Gene.name"))
genes_info_manhattan[is.na(genes_info_manhattan)] <- 1
colnames(genes_info_manhattan)[dim(genes_info_manhattan)[2]] <- "plof_ds"
### missense
if(!use_SPA)
{
results_STAAR <- results_missense_genome[,c(1,2,dim(results_missense_genome)[2]-6)]
}else
{
results_STAAR <- results_missense_genome[,c(1,2,dim(results_missense_genome)[2]-2)]
}
results_m <- c()
for(i in 1:dim(results_STAAR)[2])
{
results_m <- cbind(results_m,unlist(results_STAAR[,i]))
}
colnames(results_m) <- colnames(results_STAAR)
results_m <- data.frame(results_m,stringsAsFactors = FALSE)
results_m[,2] <- as.numeric(results_m[,2])
results_m[,3] <- as.numeric(results_m[,3])
genes_info_manhattan <- dplyr::left_join(genes_info_manhattan,results_m,by=c("chromosome_name"="Chr","hgnc_symbol"="Gene.name"))
genes_info_manhattan[is.na(genes_info_manhattan)] <- 1
colnames(genes_info_manhattan)[dim(genes_info_manhattan)[2]] <- "missense"
### disruptive_missense
results_STAAR <- results_disruptive_missense_genome[,c(1,2,dim(results_disruptive_missense_genome)[2])]
results_m <- c()
for(i in 1:dim(results_STAAR)[2])
{
results_m <- cbind(results_m,unlist(results_STAAR[,i]))
}
colnames(results_m) <- colnames(results_STAAR)
results_m <- data.frame(results_m,stringsAsFactors = FALSE)
results_m[,2] <- as.numeric(results_m[,2])
results_m[,3] <- as.numeric(results_m[,3])
genes_info_manhattan <- dplyr::left_join(genes_info_manhattan,results_m,by=c("chromosome_name"="Chr","hgnc_symbol"="Gene.name"))
genes_info_manhattan[is.na(genes_info_manhattan)] <- 1
colnames(genes_info_manhattan)[dim(genes_info_manhattan)[2]] <- "disruptive_missense"
### synonymous
results_STAAR <- results_synonymous_genome[,c(1,2,dim(results_synonymous_genome)[2])]
results_m <- c()
for(i in 1:dim(results_STAAR)[2])
{
results_m <- cbind(results_m,unlist(results_STAAR[,i]))
}
colnames(results_m) <- colnames(results_STAAR)
results_m <- data.frame(results_m,stringsAsFactors = FALSE)
results_m[,2] <- as.numeric(results_m[,2])
results_m[,3] <- as.numeric(results_m[,3])
genes_info_manhattan <- dplyr::left_join(genes_info_manhattan,results_m,by=c("chromosome_name"="Chr","hgnc_symbol"="Gene.name"))
genes_info_manhattan[is.na(genes_info_manhattan)] <- 1
colnames(genes_info_manhattan)[dim(genes_info_manhattan)[2]] <- "synonymous"
### ptv
results_STAAR <- results_ptv_genome[,c(1,2,dim(results_ptv_genome)[2])]
results_m <- c()
for(i in 1:dim(results_STAAR)[2])
{
results_m <- cbind(results_m,unlist(results_STAAR[,i]))
}
colnames(results_m) <- colnames(results_STAAR)
results_m <- data.frame(results_m,stringsAsFactors = FALSE)
results_m[,2] <- as.numeric(results_m[,2])
results_m[,3] <- as.numeric(results_m[,3])
genes_info_manhattan <- dplyr::left_join(genes_info_manhattan,results_m,by=c("chromosome_name"="Chr","hgnc_symbol"="Gene.name"))
genes_info_manhattan[is.na(genes_info_manhattan)] <- 1
colnames(genes_info_manhattan)[dim(genes_info_manhattan)[2]] <- "ptv"
### ptv_ds
results_STAAR <- results_ptv_ds_genome[,c(1,2,dim(results_ptv_ds_genome)[2])]
results_m <- c()
for(i in 1:dim(results_STAAR)[2])
{
results_m <- cbind(results_m,unlist(results_STAAR[,i]))
}
colnames(results_m) <- colnames(results_STAAR)
results_m <- data.frame(results_m,stringsAsFactors = FALSE)
results_m[,2] <- as.numeric(results_m[,2])
results_m[,3] <- as.numeric(results_m[,3])
genes_info_manhattan <- dplyr::left_join(genes_info_manhattan,results_m,by=c("chromosome_name"="Chr","hgnc_symbol"="Gene.name"))
genes_info_manhattan[is.na(genes_info_manhattan)] <- 1
colnames(genes_info_manhattan)[dim(genes_info_manhattan)[2]] <- "ptv_ds"
## ylim
coding_minp <- min(genes_info_manhattan[,(dim(genes_info_manhattan)[2]-4):dim(genes_info_manhattan)[2]])
min_y <- ceiling(-log10(coding_minp)) + 1
pch <- c(0,1,2,3,4,5,6)
figure1 <- manhattan_plot(genes_info_manhattan[,2], (genes_info_manhattan[,3]+genes_info_manhattan[,4])/2, genes_info_manhattan$plof,sig.level=alpha,pch=pch[1],col = c("blue4", "orange3"),ylim=c(0,min_y),
auto.key=T,key=list(space="top", columns=5, title="Functional Category", cex.title=1, points=TRUE,pch=pch,text=list(c("pLoF","pLoF+D","Missense","Disruptive Missense","Synonymous","PTV","PTV+D"))))
figure2 <- manhattan_plot(genes_info_manhattan[,2], (genes_info_manhattan[,3]+genes_info_manhattan[,4])/2, genes_info_manhattan$plof_ds,sig.level=alpha,pch=pch[2],col = c("blue4", "orange3"),ylim=c(0,min_y),
auto.key=T,key=list(space="top", columns=5, title="Functional Category", cex.title=1, points=TRUE,pch=pch,text=list(c("pLoF","pLoF+D","Missense","Disruptive Missense","Synonymous","PTV","PTV+D"))))
figure3 <- manhattan_plot(genes_info_manhattan[,2], (genes_info_manhattan[,3]+genes_info_manhattan[,4])/2, genes_info_manhattan$missense,sig.level=alpha,pch=pch[3],col = c("blue4", "orange3"),ylim=c(0,min_y),
auto.key=T,key=list(space="top", columns=5, title="Functional Category", cex.title=1, points=TRUE,pch=pch,text=list(c("pLoF","pLoF+D","Missense","Disruptive Missense","Synonymous","PTV","PTV+D"))))
figure4 <- manhattan_plot(genes_info_manhattan[,2], (genes_info_manhattan[,3]+genes_info_manhattan[,4])/2, genes_info_manhattan$disruptive_missense,sig.level=alpha,pch=pch[4],col = c("blue4", "orange3"),ylim=c(0,min_y),
auto.key=T,key=list(space="top", columns=5, title="Functional Category", cex.title=1, points=TRUE,pch=pch,text=list(c("pLoF","pLoF+D","Missense","Disruptive Missense","Synonymous","PTV","PTV+D"))))
figure5 <- manhattan_plot(genes_info_manhattan[,2], (genes_info_manhattan[,3]+genes_info_manhattan[,4])/2, genes_info_manhattan$synonymous,sig.level=alpha,pch=pch[5],col = c("blue4", "orange3"),ylim=c(0,min_y),
auto.key=T,key=list(space="top", columns=5, title="Functional Category", cex.title=1, points=TRUE,pch=pch,text=list(c("pLoF","pLoF+D","Missense","Disruptive Missense","Synonymous","PTV","PTV+D"))))
figure6 <- manhattan_plot(genes_info_manhattan[,2], (genes_info_manhattan[,3]+genes_info_manhattan[,4])/2, genes_info_manhattan$ptv,sig.level=alpha,pch=pch[6],col = c("blue4", "orange3"),ylim=c(0,min_y),
auto.key=T,key=list(space="top", columns=5, title="Functional Category", cex.title=1, points=TRUE,pch=pch,text=list(c("pLoF","pLoF+D","Missense","Disruptive Missense","Synonymous","PTV","PTV+D"))))
figure7 <- manhattan_plot(genes_info_manhattan[,2], (genes_info_manhattan[,3]+genes_info_manhattan[,4])/2, genes_info_manhattan$ptv_ds,sig.level=alpha,pch=pch[7],col = c("blue4", "orange3"),ylim=c(0,min_y),
auto.key=T,key=list(space="top", columns=5, title="Functional Category", cex.title=1, points=TRUE,pch=pch,text=list(c("pLoF","pLoF+D","Missense","Disruptive Missense","Synonymous","PTV","PTV+D"))))
print("Manhattan plot")
png(paste0(output_path,"gene_centric_coding_manhattan.png"), width = 9, height = 6, units = 'in', res = 600)
print(figure1)
print(figure2,newpage = FALSE)
print(figure3,newpage = FALSE)
print(figure4,newpage = FALSE)
print(figure5,newpage = FALSE)
print(figure6,newpage = FALSE)
print(figure7,newpage = FALSE)
dev.off()
}