-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfst.R
67 lines (55 loc) · 1.93 KB
/
fst.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
library("adegenet")
library("hierfstat")
library("pegas")
library("dplyr")
library("xtable")
source("scripts/read_data.R")
#plains_only <- subspecies[-c(1:3, 63)] %>% as.character
geno_sorted[geno_sorted == 2] <- "11"
geno_sorted[geno_sorted == 1] <- "01"
geno_sorted[geno_sorted == 0] <- "00"
africaZebras <- df2genind(geno_sorted,
ploidy = 2,
sep="",
pop = species)
result <- pairwise.fst(africaZebras, res.type = "matrix") %>% round(digits = 3)
result[result %>% upper.tri(diag = T)] <- NA
result %>% xtable
africaZebras <- df2genind(geno_sorted[species == "plains",],
ploidy = 2,
sep="",
pop = factor(as.character(subspecies[species == "plains"]),
levels = levels(subspecies)[1:5]))
result <- pairwise.fst(africaZebras, res.type = "matrix") %>% round(digits = 3)
result[result %>% upper.tri(diag = T)] <- NA
result %>% xtable
# borensis <- geno_sorted[subspecies == "borensis",]
# burchelli <- geno_sorted[subspecies == "burchelli",]
# both <- rbind(borensis, burchelli)
#
#
# ht <- function(myColumn) {
# hom1 <- sum(myColumn == "00")
# het <- sum(myColumn == "01")
# hom2 <- sum(myColumn == "11")
# p <- (hom1 * 2 + het) / (2 * length(myColumn))
# q <- (hom2 * 2 + het) / (2 * length(myColumn))
# result <- 2 * p * q
# return(result)
# }
#
# hs <- function(column1, column2) {
# (ht(column1) * length(column1) + ht(column2) * length(column2)) /
# (length(column1) + length(column2))
# }
#
# hs(borensis[,598], burchelli[,598])
#
# fst <- function(both, one, second) {
# result = (ht(both) - hs(one, second)) / ht(both)
# }
#
# ht_res <- apply(X = both, MARGIN = 2, FUN = ht) %>% mean
# hs_res <- 1:680 %>% as.list %>% lapply(FUN = function(i) hs(borensis[,i], burchelli[, i])) %>% unlist %>% mean
#
# (ht_res - hs_res) / ht_res