-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp2t.awk
More file actions
48 lines (47 loc) · 1.28 KB
/
Copy pathp2t.awk
File metadata and controls
48 lines (47 loc) · 1.28 KB
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
#############################################################################
# PHYLONET Bayesian tree format to TreeAnnotator format
#############################################################################
# p2t.awk - script that converts MCMC_SEQ Bayesian trees generated by
# PHYLONET to the format TreeAnnotator can read.
#
# Arnulf Heimsbakk <arnulf@heimsbakk.no>
#
# GNU GENERAL PUBLIC LICENSE V3.0
#
# Usage: awk -f p2t.awk PHYLONET_TREE_FILE > TREEANNOTATOR_FILE
#
# 2018-08-27 -- Til Thomas
#############################################################################
BEGIN {
print "#NEXUS\n\nBegin trees;"
tree1=""
j=0
}
/^[[:digit:]]+;|\[/ {
j++
if (j==3) {
print tree1
}
if (j%2) {
gsub(/;/, "")
newtreenum=strtonum($1)
if (newtreenum < treenum) exit(0)
treenum=newtreenum
line="tree STATE_"treenum" [&lnP="$4",posterior="$2"] = [&R]"
if (j==1){
tree1=line
line="tree STATE_0 [&lnP="$4",posterior="$2"] = [&R]"
}
printf line
} else {
line=gensub(":([[:digit:].E-]+):([[:digit:].E-]+)",
"[\\&popsize=\\2]:\\1", "g")
print line
if (j==2) {
tree1=tree1""line
}
}
}
END {
print "End;"
}