-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path005D_get_full_manhattan_plot.R
129 lines (114 loc) · 4.85 KB
/
005D_get_full_manhattan_plot.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
date_tag = "210317"
source(paste0("/.mounts/labs/reimandlab/private/users/oocsenas/CA2M/",
# source(paste0("/.mounts/labs/reimandlab/private/users/jreimand/CA2M/",
date_tag,
"/bin/000_HEADER.R"))
input_data_dir = "/.mounts/labs/reimandlab/private/users/oocsenas/CA2M/INPUT_DATA/"
#Load in error dt paths
q_val_dt = fread(pff("/data/005C_qvaldt_100KBerrorwindows.csv"))[,c(1, 2, 3, 6, 7, 10, 11, 12, 14, 15, 16, 17, 18, 19, 25, 26)]
#Convert chr to numeric
q_val_dt$chr = as.numeric(unlist(lapply(q_val_dt$chr,
function(x) (unlist(strsplit(x, split = "chr"))[2]))))
#Melt data table
q_val_dt.m = melt(q_val_dt, id.vars = c("chr", "start"))
#Cap significance for visualization purposes
q_val_dt.m$value[which(q_val_dt.m$value < 10^-20)] = 10^-20
#Get significant points
q_val_dt.m$sig = ifelse(q_val_dt.m$value < 0.05, "yes", "no")
#Get PCAWG colours
PCAWG_colours = readRDS(paste0(input_data_dir, "PCAWG_colour_palette.RDS"))
q_val_dt.m$colour_sig = ifelse(q_val_dt.m$sig == "yes",
as.character(q_val_dt.m$variable),
"gray")
#Create cumulative base pair position
q_val_dt.m$cum_bp = q_val_dt.m$start + hg38$cumlen[match(q_val_dt.m$chr,
hg38$chrom)]
# q_val_dt.m = na.omit(q_val_dt.m)
q_val_dt.m$colour_sig = factor(q_val_dt.m$colour_sig)
q_val_dt.m$sig = factor(q_val_dt.m$sig)
#PCAWG palette
PCAWG_pal = as.character(PCAWG_colours)[match(tolower(levels(q_val_dt.m$colour_sig)),
names(PCAWG_colours))]
PCAWG_pal[6] = "#D3D3D3"
p1_rast = ggplot(q_val_dt.m, aes(x = cum_bp, y = -1*log10(value)))+
geom_point_rast(data = q_val_dt.m[sig=="no"],
shape = 21,
size = 1.5,
alpha = 0.75,
aes(fill = colour_sig, colour = sig))+
geom_point(data = q_val_dt.m[sig=="yes"],
shape = 21,
size = 1.5,
alpha = 0.75,
aes(fill = colour_sig, colour = sig))+
theme_bw()+
scale_fill_manual(values = PCAWG_pal,
breaks = levels(q_val_dt.m$colour_sig)[-6],
guide = F)+
scale_colour_manual(values = c("grey", "black"),
guide = F)+
geom_hline(yintercept = -1*log10(0.05),
colour = "red",
linetype = "dashed")+
scale_x_continuous(breaks = (hg38$cumlen[1:22] + hg38$cumlen[2:23])/2,
labels = 1:22)+
labs(x = "Chromosome",
fill = "Project Code",
y = "-log10 (q-value)")+
theme(
panel.border = element_blank(),
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank(),
axis.text.x = element_text(vjust = 8, size = 7),
axis.text.y = element_text(size = 7),
axis.title = element_text(size = 9),
axis.ticks.x = element_blank())+
geom_vline(xintercept = hg38$cumlen[1:23],
linetype = "dashed",
colour = "grey",
alpha = 0.5)
pdf(pff("/data/005D_14cancertypes_manhattan_plot_sig_rast.pdf"), width = 9.5, height = 4)
p1_rast
dev.off()
#Get legend
p1_legend = ggplot(q_val_dt.m, aes(x = cum_bp, y = -1*log10(value)))+
geom_point_rast(data = q_val_dt.m[sig=="no"],
shape = 21,
size = 1.5,
alpha = 0.75,
aes(fill = colour_sig, colour = sig))+
geom_point(data = q_val_dt.m[sig=="yes"],
shape = 21,
size = 1.5,
alpha = 0.75,
aes(fill = colour_sig, colour = sig))+
theme_bw()+
scale_fill_manual(values = PCAWG_pal,
breaks = levels(q_val_dt.m$colour_sig)[-6])+
scale_colour_manual(values = c("grey", "black"),
guide = F)+
geom_hline(yintercept = -1*log10(0.05),
colour = "red",
linetype = "dashed")+
scale_x_continuous(breaks = (hg38$cumlen[1:22] + hg38$cumlen[2:23])/2,
labels = 1:22)+
labs(x = "Chromosome",
fill = "Project Code",
y = "-log10 (q-value)")+
theme(
panel.border = element_blank(),
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank(),
axis.text.x = element_text(vjust = 8, size = 7),
axis.text.y = element_text(size = 7),
axis.title = element_text(size = 9),
axis.ticks.x = element_blank())+
geom_vline(xintercept = hg38$cumlen[1:23],
linetype = "dashed",
colour = "grey",
alpha = 0.5)
legend_full <- cowplot::get_legend(p1_legend)
pdf(pff("/data/005D_14cancertypes_manhattan_plot_LEGEND.pdf"), width = 4, height = 4)
grid.newpage()
grid.draw(legend_full)
dev.off()