-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_figureS4.R
134 lines (115 loc) · 4.32 KB
/
plot_figureS4.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
################################################################################
# libraries #
################################################################################
library(tidyverse)
################################################################################
# functions #
################################################################################
# source modified r script from evaladmix
source("~/documents/rcoimbra_phd/project_kenya/results/05_admixture/visFuns_modified.R")
################################################################################
# configurations #
################################################################################
# set subspecies factor levels
lvls.1 <- c("Nubian", "Reticulated", "Masai s. str.")
# set location factor levels
lvls.2 <- c(
"Gambella NP",
"Murchison Falls NP",
"Ruma NP",
"Kigio Wildlife Conservancy",
"Lake Nakuru NP",
"Soysambu Conservancy",
"Mwea NR",
"Aberdare Country Club",
"El Karama Conservancy",
"Loisaba Conservancy",
"Mpala Conservancy",
"Ol Pejeta Conservancy",
"Solio GR",
"Buffalo Springs NR",
"Meru NP",
"Samburu NR",
"Garissa",
"Ishaqbini Conservancy",
"Selous GR",
"Masai Mara",
"Hell's Gate NP",
"Naivasha (Private Ranches)",
"Ngong",
"Amboseli NP",
"Mbirikani",
"Nairobi NP",
"Tsavo West NP",
"Tsavo East NP"
)
################################################################################
# preparation #
################################################################################
# set working directory
setwd("~/documents/rcoimbra_phd/project_kenya")
# read bamlist used with ANGSD
bams <- read_table("results/05_admixture/bamlist", col_names = FALSE)
# import metadata
metadata <- read_csv("metadata.csv")
# create tibble with samples information
sample.info <- pull(bams, 1) %>%
str_replace_all(c("/.*/" = "", ".clean.bam" = "")) %>%
as_tibble_col(column_name = "id") %>%
left_join(metadata) %>%
mutate(
taxonomy = case_when(
str_detect(taxonomy, regex("Giraffa tippelskirchi tippelskirchi")) ~ "Masai s. str.",
str_detect(taxonomy, regex("Giraffa camelopardalis camelopardalis")) ~ "Nubian",
str_detect(taxonomy, regex("Giraffa reticulata")) ~ "Reticulated",
TRUE ~ NA_character_
)
) %>%
mutate(
taxonomy = fct_relevel(taxonomy, lvls.1),
location = fct_relevel(location, lvls.2)
)
# clean environment
rm(bams, metadata)
################################################################################
# plot evaladmix #
################################################################################
# set working directory
setwd("~/documents/rcoimbra_phd/project_kenya/results/05_admixture/")
# get input file names
files <- c(
str_sort(list.files(pattern = ".qopt"), numeric = TRUE),
str_sort(list.files(pattern = ".txt"), numeric = TRUE)
)
pop <- sample.info %>% select(location, id) %>% as.data.frame()
png(height = 9, width = 10, units = "in", res = 300)
for(i in 1:11) {
q <- read_table(files[i], col_names = FALSE) %>%
select(!last_col()) %>%
as.data.frame()
ord <- orderInds(pop = as.vector(pop[, 1]), popord = lvls.2)
r <- read.table(files[i + 11])
assign(
paste0("mat", i),
plotCorRes(
cor_mat = r,
pop = as.vector(pop[, 1]),
superpop = as.vector(sample.info$taxonomy),
ord = ord,
title = paste0("Correlation of residuals for K=", i),
max_z = 0.5,
min_z = -0.5,
cex.main = 1.2,
cex.lab = 0.4,
cex.lab.2 = 1,
cex.legend = 1.2,
rotatelabpop = 90,
adjlab = 0.015,
adjlabsuperpop = 0.165,
pop_labels = c(TRUE, TRUE),
lineswidth = 0.5,
lineswidthsuperpop = 1.5
)
)
}
invisible(dev.off())