#################################################################################################################################### ### Source Code: ### ### Tyrannosauroid integument reveals conflicting patterns of gigantism and feather evolution. ### ### Phil R. Bell, Nicolás E. Campione, W. Scott Persons IV, Philip J. Currie, Peter L. Larson, Darren H. Tanke, Robert T. Bakker ### #################################################################################################################################### ## Required Packages ## library(xlsx) #reads Excel file library(RColorBrewer) #provides different sets of colours # Analytical Packages library(ape) library(phytools) library(strap) library(paleotree) ## New Functions ## full.analysis <- function(tree, scale.meth) { data <- new.data[tree$tip.label,] #matches data and tree tip names #tree.scaled <- DatePhylo(tree,ages = as.matrix(data[,c("FAD","LAD")]),method = scale.meth,rlen = 1) #time-scales tree tree.scaled <- timePaleoPhy(tree,timeData = as.matrix(data[,c("FAD","LAD")]),type = scale.meth,vartime = 1) #time-scales tree #size analysis (continuous data) size.trait <- data[,"FL"]; names(size.trait) <- data[,"Genus"] #size proxy anc.size <- fastAnc(tree.scaled,log10(size.trait)) #ancestral state estimation (Brownian Motion) par(mfrow = c(1,2),mar = c(5,4,1,0)+0.1) phenogram(tree.scaled,c(log10(size.trait),anc.size),ylab = "log10 Femur Length",fsize = 0.55) #skin analysis (discrete data) missing <- which(is.na(data$Integ.1)) #missing data skin.trait <- data[,"Integ.2"]; names(skin.trait) <- data[,"Genus"] #skin coding anc.skin <- ace(skin.trait[-missing],drop.tip(tree.scaled,missing),type = "discrete") #ancestral state estimation plotTree(drop.tip(tree.scaled,missing),node.numbers = FALSE,setEnv = TRUE,offset = 0.5) nodelabels(node = 8:13,pie = anc.skin$lik.anc,piecol = brewer.pal(3,name = "Blues")[2:3],cex = 1.5) tiplabels(pch = 21,bg = brewer.pal(3,name = "Blues")[c(2,2,2,2,2,3,3)],cex = 1.5) legend("topright",legend = c("Scales","Filaments"),pch = 19,col = brewer.pal(3,name = "Blues")[2:3],bty = "n") #par(mfrow = c(3,2),mar = c(1,1,1,1)) #for(i in 1:6) pie(anc.skin$lik.anc[i,],col = brewer.pal(3,name = "Blues")[2:3],main = paste("Node",i+7,sep = " ")) #results return(list(Tree = tree.scaled,Size = size.trait,Size.Results = anc.size, Skin.Results = anc.skin)) } ## Data & Tree ## new.data <- read.xlsx("Data.xlsx",sheetIndex = 1) rownames(new.data) <- new.data$Genus BCtree.par <- read.nexus("BCtree-Parsimony") BCtree.bay <- read.nexus("BMtree-Bayesian") plotTree(BCtree.par) plotTree(BCtree.bay) ## Analysis ## pdf(file = "results.pdf",width = 8.27,height = 2.92) #save output to pdf file pars.equal <- full.analysis(BCtree.par,scale.meth = "equal") pars.mbl <- full.analysis(BCtree.par,scale.meth = "mbl") bays.equal <- full.analysis(BCtree.bay,scale.meth = "equal") bays.mbl <- full.analysis(BCtree.bay,scale.meth = "mbl") dev.off()