-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathastralt4.R
33 lines (28 loc) · 1.33 KB
/
astralt4.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
#--------------------------------------------------------------------------------------------
# HybPhyloMaker: draw phylogenetic tree with pie charts based on 'ASTRAL -t 4'
# https://github.com/tomas-fer/HybPhyloMaker
# v.1.8.0a
# Tomas Fer, 2024
# tomas.fer@natur.cuni.cz
#--------------------------------------------------------------------------------------------
#Processing scored tree from ASTRAL (with the option -t 4)
#This creates a PDF image of the rooted ASTRAL species tree with pie charts on branches
#See ASTRAL manual for explanation
require(treeio) #(implements 'read.astral')
require(ape)
#Import the tree generated with ASTRAL -t 4, i.e. with three posterior probabilities per branch
x <- read.astral("tree.tre")
#Save posterior probabilities
pp1 <- as.numeric(x[['pp1']])
pp2 <- as.numeric(x[['pp2']])
pp3 <- as.numeric(x[['pp3']])
pc <- cbind( pp1, pp2, pp3)
tree <- x@phylo
#Plot/save the tree (modify 'adj' and 'cex' values according to your needs)
pdf("tree.pdf")
scaling = 0.27*((1/length(tree$tip.label))*100) #this should automatically scale tip label according to the number of tips
if(scaling > 1){scaling = 1} # set scaling to '1' if too few tips
plot(tree, cex = scaling, label.offset = 1)
par(lty = "blank") #no lines in pie charts
nodelabels(pie = pc, adj = c(-0.2, 0.5), piecol = c("blue","red","green"), cex = 0.4)
dev.off()