-
Notifications
You must be signed in to change notification settings - Fork 1
/
Embeding.R
86 lines (72 loc) · 2.39 KB
/
Embeding.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
source("FinalStats.R")
statDistanceMatrix = function(tip) {
nstat <-2
outputdir <- "./trees"
inputdir <- "./trees"
inputfile <- paste(inputdir,"/tr",tip,".tre",sep="")
trees <- read.tree(inputfile, keep.multi = TRUE)
n <- length(trees)
statMatrix <- matrix(0, nrow = n, ncol= nstat)
for (j in (1:n)) {
root <- trees[[j]]
tree <- setTree(root, tip)
parents <- setParents(tree, tip)
Nis <- setNis (root)
MHat <- setMaxDist4node2tips(parents, tip)
NTips <- extractNTips(tree, tip)
cherries <- extractCherries(tree, tip)
pitchforks <- extractPitchforks(tree, tip)
Width <- extractWidth(Nis,MHat, tip)
# # calculate Ic
statMatrix[j,1] <- statIc(root)
#
# # calculate Sackin
statMatrix[j,2] <- statSackin(root)
#
}
DM = matrix(0, nrow= n, ncol = n)
DM = as.matrix(dist(statMatrix, method= "euclidean", diag = FALSE, upper = FALSE, p = 2))
Ds <- DM^2
H=diag(rep(1,n))-1/n
XD <- -(1/2) * H %*% Ds %*% H
eye = eigen(XD , symmetric = TRUE, EISPACK = FALSE)
values <- eye$values
vectors <- eye$vectors
treeLocation = matrix(0, nrow = n , ncol = 2)
for (i in (1:n)){
treeLocation[i, 1] <- (values[1]^(1/2)) * vectors[i, 1]
treeLocation[i, 2] <- (values[2]^(1/2)) * vectors[i, 2]
}
layout(matrix(c(1,1,2,3), 2, 2, byrow = TRUE))
hist(1)
hist(2)
hist(3)
title = paste("Distibution of Trees with ", tip , " Leaves")
plot(treeLocation, main = list (title, col= "black" ), xlab = "X", ylab = "Y")
idx = which(treeLocation[,1]==max(treeLocation[,1]))
plot (trees[[idx[1]]], type="c", main = list("Outlier with maximum X value" , col = "black") )
idx = which(treeLocation[,1]==min(treeLocation[,1]))
plot (trees[[idx[1]]], type="c",main = list("Outlier with minimum X value" , col = "black") )
}
nstat <- 2
met = 'NNI'
main = function(tip,met,nstat){
ntip=tip
inputdir <- "./trees"
inputfile <- paste(inputdir,"/tr",tip,".tre",sep="")
trees <- read.tree(inputfile, keep.multi = TRUE)
# fill the Stat Matrix
n <- length(trees)
statMatrix <- matrix(0, nrow = n, ncol= nstat)
for (j in (1:n)) {
root <- trees[[j]]
Nis <- setNis (root)
statMatrix[j,1] <- statIc(root)
statMatrix[j,2] <- statSackin(root)
}
}
Colless=statMatrix[,1]
Sakin=statMatrix[,2]
plot(Colless,Sakin)
plot(trees[[which(Sakin==max(Sakin))]])
plot(trees[[which(SaKin==max(Sakin))]])