-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFigure_S4.R
149 lines (88 loc) · 6.84 KB
/
Figure_S4.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
#!/usr/bin/env Rscript
# Figure_S4.R
# Plots of variance for windows binned by pi, four different window sizes - Figure S4.
# Written for "Evaluating statistics for the identification of introgressed loci"
# by Simon H. Martin, John W. Davey and Chris D. Jiggins
# John Davey: [email protected]
# Simon Martin: [email protected]
# August 2014
png("Figure_S4.png", width = 4000, height = 4000, res = 400)
par(mar = c(4,4,1,1), mfrow = c(2,2))
ABBA_table <- read.csv("Heliconius_autosome_windows_5kb.csv", as.is = T)
ABBA_table_Z <- read.csv("Heliconius_Zchromosome_windows_5kb.csv", as.is = T)
ABBA_table <- rbind(ABBA_table, ABBA_table_Z)
#filter for windows with enough sites above the minimum data cutoff
ABBA_table <- subset(ABBA_table, sitesOverMinExD >= 3000)
#calculate mean Pi in the three pops
mean_Pi <- apply(ABBA_table[,c("P1_pi", "P2_pi", "P3_pi")], 1, mean, na.rm = T)
### variances in mean_Pi bins
pi_cuts <- cut(mean_Pi, seq(0,0.04,0.01))
D_vars <- sapply(1:length(levels(pi_cuts)), function(x){var(ABBA_table$D[pi_cuts == levels(pi_cuts)[x] & ABBA_table$D >= 0], na.rm = T)})
fd_vars <- sapply(1:length(levels(pi_cuts)), function(x){var(ABBA_table$fd[pi_cuts == levels(pi_cuts)[x] & ABBA_table$D >= 0] , na.rm = T)})
fG_vars <- sapply(1:length(levels(pi_cuts)), function(x){var(ABBA_table$fG[pi_cuts == levels(pi_cuts)[x] & ABBA_table$D >= 0 & ABBA_table$fG >= 0 & ABBA_table$fG <= 1], na.rm = T)})
fhom_vars <- sapply(1:length(levels(pi_cuts)), function(x){var(ABBA_table$fhom[pi_cuts == levels(pi_cuts)[x] & ABBA_table$D >= 0 & ABBA_table$fhom >= 0 & ABBA_table$fhom <= 1], na.rm = T)})
plot(D_vars, type = "b", pch = 19, xlab = expression(paste(pi, " bin")), xaxt = "n", ylab = "Variance", ylim = c(0,0.1))
axis(1, at=1:6, labels = c("0 - 0.01", "0.01 - 0.02", "0.02 - 0.03", "0.03 - 0.04", "0.04 - 0.05", "0.05 - 0.06"), las = 1)
points(fd_vars, type = "b")
points(fG_vars, type = "b", pch = 2)
points(fhom_vars, type = "b", pch = 3)
mtext(2,text = "A", las = 2, at = 0.1, line = 2.5, cex = 1.5)
legend(3,0.1, legend = c(expression(italic("D")), expression(italic("f"["G"])), expression(italic("f"["hom"])), expression(italic("f"["d"]))), pch = c(19,2,3,1), bty = "n")
ABBA_table <- read.csv("Heliconius_autosome_windows_10kb.csv", as.is = T)
ABBA_table_Z <- read.csv("Heliconius_Zchromosome_windows_10kb.csv", as.is = T)
ABBA_table <- rbind(ABBA_table, ABBA_table_Z)
#filter for windows with enough sites above the minimum data cutoff
ABBA_table <- subset(ABBA_table, sitesOverMinExD >= 6000)
#calculate mean Pi in the three pops
mean_Pi <- apply(ABBA_table[,c("P1_pi", "P2_pi", "P3_pi")], 1, mean, na.rm = T)
### variances in mean_Pi bins
pi_cuts <- cut(mean_Pi, seq(0,0.04,0.01))
D_vars <- sapply(1:length(levels(pi_cuts)), function(x){var(ABBA_table$D[pi_cuts == levels(pi_cuts)[x] & ABBA_table$D >= 0], na.rm = T)})
fd_vars <- sapply(1:length(levels(pi_cuts)), function(x){var(ABBA_table$fd[pi_cuts == levels(pi_cuts)[x] & ABBA_table$D >= 0] , na.rm = T)})
fG_vars <- sapply(1:length(levels(pi_cuts)), function(x){var(ABBA_table$fG[pi_cuts == levels(pi_cuts)[x] & ABBA_table$D >= 0 & ABBA_table$fG >= 0 & ABBA_table$fG <= 1], na.rm = T)})
fhom_vars <- sapply(1:length(levels(pi_cuts)), function(x){var(ABBA_table$fhom[pi_cuts == levels(pi_cuts)[x] & ABBA_table$D >= 0 & ABBA_table$fhom >= 0 & ABBA_table$fhom <= 1], na.rm = T)})
plot(D_vars, type = "b", pch = 19, xlab = expression(paste(pi, " bin")), xaxt = "n", ylab = "Variance", ylim = c(0,0.1))
axis(1, at=1:6, labels = c("0 - 0.01", "0.01 - 0.02", "0.02 - 0.03", "0.03 - 0.04", "0.04 - 0.05", "0.05 - 0.06"), las = 1)
points(fd_vars, type = "b")
points(fG_vars, type = "b", pch = 2)
points(fhom_vars, type = "b", pch = 3)
mtext(2,text = "B", las = 2, at = 0.1, line = 2.5, cex = 1.5)
ABBA_table <- read.csv("Heliconius_autosome_windows_20kb.csv", as.is = T)
ABBA_table_Z <- read.csv("Heliconius_Zchromosome_windows_20kb.csv", as.is = T)
ABBA_table <- rbind(ABBA_table, ABBA_table_Z)
#filter for windows with enough sites above the minimum data cutoff
ABBA_table <- subset(ABBA_table, sitesOverMinExD >= 12000)
#calculate mean Pi in the three pops
mean_Pi <- apply(ABBA_table[,c("P1_pi", "P2_pi", "P3_pi")], 1, mean, na.rm = T)
### variances in mean_Pi bins
pi_cuts <- cut(mean_Pi, seq(0,0.04,0.01))
D_vars <- sapply(1:length(levels(pi_cuts)), function(x){var(ABBA_table$D[pi_cuts == levels(pi_cuts)[x] & ABBA_table$D >= 0], na.rm = T)})
fd_vars <- sapply(1:length(levels(pi_cuts)), function(x){var(ABBA_table$fd[pi_cuts == levels(pi_cuts)[x] & ABBA_table$D >= 0] , na.rm = T)})
fG_vars <- sapply(1:length(levels(pi_cuts)), function(x){var(ABBA_table$fG[pi_cuts == levels(pi_cuts)[x] & ABBA_table$D >= 0 & ABBA_table$fG >= 0 & ABBA_table$fG <= 1], na.rm = T)})
fhom_vars <- sapply(1:length(levels(pi_cuts)), function(x){var(ABBA_table$fhom[pi_cuts == levels(pi_cuts)[x] & ABBA_table$D >= 0 & ABBA_table$fhom >= 0 & ABBA_table$fhom <= 1], na.rm = T)})
plot(D_vars, type = "b", pch = 19, xlab = expression(paste(pi, " bin")), xaxt = "n", ylab = "Variance", ylim = c(0,0.1))
axis(1, at=1:6, labels = c("0 - 0.01", "0.01 - 0.02", "0.02 - 0.03", "0.03 - 0.04", "0.04 - 0.05", "0.05 - 0.06"), las = 1)
points(fd_vars, type = "b")
points(fG_vars, type = "b", pch = 2)
points(fhom_vars, type = "b", pch = 3)
mtext(2,text = "C", las = 2, at = 0.1, line = 2.5, cex = 1.5)
ABBA_table <- read.csv("Heliconius_autosome_windows_50kb.csv", as.is = T)
ABBA_table_Z <- read.csv("Heliconius_Zchromosome_windows_50kb.csv", as.is = T)
ABBA_table <- rbind(ABBA_table, ABBA_table_Z)
#filter for windows with enough sites above the minimum data cutoff
ABBA_table <- subset(ABBA_table, sitesOverMinExD >= 24000)
#calculate mean Pi in the three pops
mean_Pi <- apply(ABBA_table[,c("P1_pi", "P2_pi", "P3_pi")], 1, mean, na.rm = T)
### variances in mean_Pi bins
pi_cuts <- cut(mean_Pi, seq(0,0.04,0.01))
D_vars <- sapply(1:length(levels(pi_cuts)), function(x){var(ABBA_table$D[pi_cuts == levels(pi_cuts)[x] & ABBA_table$D >= 0], na.rm = T)})
fd_vars <- sapply(1:length(levels(pi_cuts)), function(x){var(ABBA_table$fd[pi_cuts == levels(pi_cuts)[x] & ABBA_table$D >= 0] , na.rm = T)})
fG_vars <- sapply(1:length(levels(pi_cuts)), function(x){var(ABBA_table$fG[pi_cuts == levels(pi_cuts)[x] & ABBA_table$D >= 0 & ABBA_table$fG >= 0 & ABBA_table$fG <= 1], na.rm = T)})
fhom_vars <- sapply(1:length(levels(pi_cuts)), function(x){var(ABBA_table$fhom[pi_cuts == levels(pi_cuts)[x] & ABBA_table$D >= 0 & ABBA_table$fhom >= 0 & ABBA_table$fhom <= 1], na.rm = T)})
plot(D_vars, type = "b", pch = 19, xlab = expression(paste(pi, " bin")), xaxt = "n", ylab = "Variance", ylim = c(0,0.1))
axis(1, at=1:6, labels = c("0 - 0.01", "0.01 - 0.02", "0.02 - 0.03", "0.03 - 0.04", "0.04 - 0.05", "0.05 - 0.06"), las = 1)
points(fd_vars, type = "b")
points(fG_vars, type = "b", pch = 2)
points(fhom_vars, type = "b", pch = 3)
mtext(2,text = "D", las = 2, at = 0.1, line = 2.5, cex = 1.5)
dev.off()