-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph_BEDCOMPARE_MEAN_RSV_SIMs.R
191 lines (157 loc) · 7.49 KB
/
graph_BEDCOMPARE_MEAN_RSV_SIMs.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
#!/usr/bin/R
# this script plots:
# 1) the TPR and FDR vs the read support threshold for the TEMP absence caller
# 2) the TPR and FDR vs the read support threshold for the TELOCATE reference caller
# USE: graph_BEDCOMPARE_MEAN_RSV_SIMs.R
library(tidyr)
library(dplyr)
library(ggplot2)
library(gtable)
library(cowplot)
#Read Support Cutoff for TEMP
file_list=c("/Users/kristen/Documents/transposon_figure_data/simulations/depth_TPFD_files/RSV_SIM",
"/Users/kristen/Documents/transposon_figure_data/simulations/depth_TPFD_files/RSV_SIM_half",
"/Users/kristen/Documents/transposon_figure_data/simulations/depth_TPFD_files/RSV_SIM_quarter",
"/Users/kristen/Documents/transposon_figure_data/simulations/depth_TPFD_files/RSV_SIM_tenth")
#loop through the coverage level simulations
for (i in file_list){
print(i)
setwd(i)
fileID<-basename(i)
print(file)
if (fileID=="RSV_SIM"){ID<-"130x Depth of Coverage"}
if (fileID=="RSV_SIM_half"){ID<-"65x Depth of Coverage"}
if (fileID=="RSV_SIM_quarter"){ID<-"32.5x Depth of Coverage"}
if (fileID=="RSV_SIM_tenth"){ID<-"13x Depth of Coverage"}
summarydata <- read.table("BEDCOMPARE_MEANS.txt",header=TRUE)
TEMP <- summarydata[(summarydata$M2=="new_CT_run_3_N2_temp_nonredundant.bed_F")& summarydata$fam=="family_aware", ]
SD_TEMP <- summarydata[(summarydata$M2=="new_CT_run_3_N2_temp_nonredundant.bed_F_error")& summarydata$fam=="family_aware", ]
merged_TEMP<-merge(TEMP,SD_TEMP, by="DistanceCutoff")
merged_ALL<-merged_TEMP
#collapse 2 columns to prep for faceting
names(merged_ALL)
merged<-merged_ALL %>%
gather(rate_name, rate_value, TPR.x:FDR.x)
#gather(rate_name, rate_value, TPR.x:FDR.x, FNR.x)
#separate TPR and FDR and associate with the proper error number
names(merged)
TPR<- merged[(merged$rate_name=="TPR.x"),c(1:7,8,10:11)]
FDR<- merged[(merged$rate_name=="FDR.x"),c(1:7,9,10:11)]
#rename TPR.y and FDR.y to error
#rename TPR.y and FDR.y to error
colnames(TPR)[8] <- "error"
colnames(FDR)[8] <- "error"
names(TPR)
names(FDR)
final <-rbind(TPR,FDR)
names(final)
levels(final$rate_name)
final$rate_name <- factor(final$rate_name,
levels = c("TPR.x", "FDR.x"),
labels = c("TPR", "FDR"))
a <- ggplot(data = final, aes(x = DistanceCutoff, y = rate_value))
a <- a + geom_line(color="black")+ xlim(0,31)+
geom_errorbar(aes(ymin=rate_value-error, ymax=rate_value+error),color="black") +
geom_point(data = subset(final, rate_name=="TPR"),aes(x=0, y=100),alpha=0)+
geom_point(data = subset(final, rate_name=="FDR"),aes(x=0, y=0),alpha=0)+
geom_vline(xintercept=c(3,3), linetype="dashed", color="gray52")+
facet_grid(rate_name ~ .,scale="free_y")+
theme(strip.background = element_blank(),
strip.text.x = element_text(size = 9, colour = "black",face="bold"),
strip.text.y = element_text(size = 9, colour = "black",face="bold",angle=90),
panel.background = element_rect(fill = "white"),
axis.ticks =element_line(colour = "black"),
axis.text.y = element_text(colour = "black",size=8),
axis.text.x = element_text(colour = "black",size=8),
axis.line=element_line(linetype="solid"),
axis.line.y = element_line(colour = "black"),
axis.line.x = element_line(colour = "black"),
axis.title=element_text(size=8),
axis.title.x=element_text(face="bold"),
plot.title = element_text(size=9),
legend.position=('none'))+
labs(x = "Minimum Read Support Threshold", y="",title=ID)+
scale_y_continuous(expand = c(0,0)) + scale_x_continuous(expand = c(0,0),limits=c(0,31))
a
#flip y-axis facet labels
a<- ggplotGrob(a)
a$layout[a$layout$name == "strip-right",c("l", "r")] <- 2
plot(a)
grid.draw(a)
filename <- paste("rs_temp",fileID, sep ="_")
filename <- paste(filename,"tiff", sep =".")
ggsave(filename,dpi=300, width=7.5,height=3.5,units="in")
#Read Support Cutoff for TELOCATE
summarydata <- read.table("BEDCOMPARE_MEANS.txt",header=TRUE)
TELOCATE <- summarydata[(summarydata$M2=="new_CT_run_3_N2_telocate_nonredundant.bed_F")& summarydata$fam=="family_aware", ]
SD_TELOCATE <- summarydata[(summarydata$M2=="new_CT_run_3_N2_telocate_nonredundant.bed_F_error")& summarydata$fam=="family_aware", ]
merged_TELOCATE<-merge(TELOCATE,SD_TELOCATE, by="DistanceCutoff")
merged_ALL<-merged_TELOCATE
#collapse 2 columns to prep for faceting
names(merged_ALL)
merged<-merged_ALL %>%
gather(rate_name, rate_value, TPR.x:FDR.x)
#gather(rate_name, rate_value, TPR.x:FDR.x, FNR.x)
#separate TPR and FDR and associate with the proper error number
names(merged)
TPR<- merged[(merged$rate_name=="TPR.x"),c(1:7,8,10:11)]
FDR<- merged[(merged$rate_name=="FDR.x"),c(1:7,9,10:11)]
#FNR<- merged[(merged$rate_name=="FNR.x"),c(1:7,10:12)]
#rename TPR.y and FDR.y to error
#rename TPR.y and FDR.y to error
colnames(TPR)[8] <- "error"
colnames(FDR)[8] <- "error"
names(TPR)
names(FDR)
final <-rbind(TPR,FDR)
#final <-rbind(TPR,FDR,FNR)
names(final)
levels(final$rate_name)
final$rate_name <- factor(final$rate_name,
levels = c("TPR.x", "FDR.x"),
labels = c("TPR", "FDR"))
m <- ggplot(data = final, aes(x = DistanceCutoff, y = rate_value))
m <- m + geom_line(color="black")+ xlim(0,31)+
geom_errorbar(aes(ymin=rate_value-error, ymax=rate_value+error),color="black") +
geom_point(data = subset(final, rate_name=="TPR"),aes(x=0, y=100),alpha=0)+
geom_point(data = subset(final, rate_name=="FDR"),aes(x=0, y=0),alpha=0)+
geom_vline(xintercept=c(3,3), linetype="dashed", color="gray52")+
facet_grid(rate_name ~ .,scale="free_y")+
theme(strip.background = element_blank(),
strip.text.x = element_text(size = 9, colour = "black",face="bold"),
strip.text.y = element_text(size = 9, colour = "black",face="bold",angle=90),
panel.background = element_rect(fill = "white"),
axis.ticks =element_line(colour = "black"),
axis.text.y = element_text(colour = "black",size=8),
axis.text.x = element_text(colour = "black",size=8),
axis.line=element_line(linetype="solid"),
axis.line.y = element_line(colour = "black"),
axis.line.x = element_line(colour = "black"),
axis.title=element_text(size=8),
axis.title.x=element_text(face="bold"),
plot.title = element_text(size=9),
legend.position=('none'))+
labs(x = "Minimum Read Support Threshold", y="",title=ID)+
scale_y_continuous(expand = c(0,0)) + scale_x_continuous(expand = c(0,0),limits=c(0,31))
m
#flip y-axis facet labels
m <- ggplotGrob(m)
m$layout[m$layout$name == "strip-right",c("l", "r")] <- 2
plot(m)
grid.draw(m)
filename <- paste("rs_telocate",fileID, sep ="_")
filename <- paste(filename,"tiff", sep =".")
ggsave(filename,dpi=300, width=7.5,height=3.5,units="in")
if (fileID=="RSV_SIM"){first<-a;m_first<-m}
if (fileID=="RSV_SIM_half"){second<-a;m_second<-m}
if (fileID=="RSV_SIM_quarter"){third<-a;m_third<-m}
if (fileID=="RSV_SIM_tenth"){fourth<-a;m_fourth<-m}
}
setwd("/Users/kristen/Documents/transposon_figure_data/simulations/depth_TPFD_files/")
a_all<-plot_grid(first,second,third,fourth,labels=c("A","B","C","D"))
m_all<-plot_grid(m_first,m_second,m_third,m_fourth,labels=c("A","B","C","D"))
setwd("/Users/kristen/Documents/transposon_figure_data/figures")
ggsave(a_all,filename="Combined_Temp.tiff",dpi=300, width=7.5,height=5,units="in")
ggsave(m_all,filename="Combined_Telocate.tiff",dpi=300, width=7.5,height=5,units="in")
ggsave(a_all,filename="Combined_Temp.png",dpi=300, width=7.5,height=5,units="in")
ggsave(m_all,filename="Combined_Telocate.png",dpi=300, width=7.5,height=5,units="in")