Skip to content

Commit 3086d52

Browse files
author
schultzm
committed
Added ladderise options to both the plotTree.R standalone script, and to the plotTree.R shiny version. Changes added at lines 76 and lines 84 to 100.
1 parent 8b5546f commit 3086d52

2 files changed

Lines changed: 36 additions & 6 deletions

File tree

plotTree.R

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,31 @@ return(list(m=as.matrix(m),w=w,h=h))
7373
}
7474

7575

76-
plotTree<-function(tree,heatmapData=NULL,barData=NULL,infoFile=NULL,blockFile=NULL,snpFile=NULL,gapChar="?",genome_size=5E6,blwd=5,block_colour="black",snp_colour="red",genome_offset=0,colourNodesBy=NULL,infoCols=NULL,outputPDF=NULL,outputPNG=NULL,w,h,heatmap.colours=rev(gray(seq(0,1,0.1))),tip.labels=F,tipLabelSize=1,offset=0,tip.colour.cex=0.5,legend=T,legend.pos="bottomleft",ancestral.reconstruction=F,cluster=NULL,tipColours=NULL,lwd=1.5,axis=F,axisPos=3,edge.color="black",infoCex=0.8,colLabelCex=0.8,treeWidth=10,infoWidth=10,dataWidth=30,edgeWidth=1,labelHeight=10,mainHeight=100,barDataWidth=10,blockPlotWidth=10,barDataCol=2,heatmapBreaks=NULL,heatmapDecimalPlaces=1,vlines.heatmap=NULL,vlines.heatmap.col=2,heatmap.blocks=NULL,pie.cex=0.5) {
76+
plotTree<-function(tree,ladderise=NULL,heatmapData=NULL,barData=NULL,infoFile=NULL,blockFile=NULL,snpFile=NULL,gapChar="?",genome_size=5E6,blwd=5,block_colour="black",snp_colour="red",genome_offset=0,colourNodesBy=NULL,infoCols=NULL,outputPDF=NULL,outputPNG=NULL,w,h,heatmap.colours=rev(gray(seq(0,1,0.1))),tip.labels=F,tipLabelSize=1,offset=0,tip.colour.cex=0.5,legend=T,legend.pos="bottomleft",ancestral.reconstruction=F,cluster=NULL,tipColours=NULL,lwd=1.5,axis=F,axisPos=3,edge.color="black",infoCex=0.8,colLabelCex=0.8,treeWidth=10,infoWidth=10,dataWidth=30,edgeWidth=1,labelHeight=10,mainHeight=100,barDataWidth=10,blockPlotWidth=10,barDataCol=2,heatmapBreaks=NULL,heatmapDecimalPlaces=1,vlines.heatmap=NULL,vlines.heatmap.col=2,heatmap.blocks=NULL,pie.cex=0.5) {
7777

7878
require(ape)
7979

80-
# PREPARE TREE AND GET TIP ORDER
80+
# PREPARE TREE, CHOOSE LADDERISATION OR NOT, AND GET TIP ORDER
8181
if (is.character(tree)){
8282
t<-read.tree(tree)
8383
}
8484
else t<-tree
85-
tl<-ladderize(t)
85+
if (is.null(ladderise))
86+
{
87+
tl<-t
88+
}
89+
else if (ladderise=="descending")
90+
{
91+
tl<-ladderize(t, T)
92+
}
93+
else if (ladderise=="ascending")
94+
{
95+
tl<-ladderize(t, F)
96+
}
97+
else if (!is.null(ladderise))
98+
{
99+
print("Ladderise option should be exactly 'ascending' or 'descending'. Any other command will raise this error. Leave option empty to order branches as per input tree.")
100+
}
86101
tips<-tl$edge[,2]
87102
tip.order<-tips[tips<=length(tl$tip.label)]
88103
tip.label.order<-tl$tip.label[tip.order] # for ordering data. note that for tiplabel(), the order is the same as in t$tip (= tl$tip)

plotTreeShiny/plotTree.R

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,31 @@ return(list(m=as.matrix(m),w=w,h=h))
7373
}
7474

7575

76-
plotTree<-function(tree,heatmapData=NULL,barData=NULL,infoFile=NULL,blockFile=NULL,snpFile=NULL,gapChar="?",genome_size=5E6,blwd=5,block_colour="black",snp_colour="red",genome_offset=0,colourNodesBy=NULL,infoCols=NULL,outputPDF=NULL,outputPNG=NULL,w,h,heatmap.colours=rev(gray(seq(0,1,0.1))),tip.labels=F,tipLabelSize=1,offset=0,tip.colour.cex=0.5,legend=T,legend.pos="bottomleft",ancestral.reconstruction=F,cluster=NULL,tipColours=NULL,lwd=1.5,axis=F,axisPos=3,edge.color="black",infoCex=0.8,colLabelCex=0.8,treeWidth=10,infoWidth=10,dataWidth=30,edgeWidth=1,labelHeight=10,mainHeight=100,barDataWidth=10,blockPlotWidth=10,barDataCol=2,heatmapBreaks=NULL,heatmapDecimalPlaces=1,vlines.heatmap=NULL,vlines.heatmap.col=2,heatmap.blocks=NULL,pie.cex=0.5) {
76+
plotTree<-function(tree,ladderise=NULL,heatmapData=NULL,barData=NULL,infoFile=NULL,blockFile=NULL,snpFile=NULL,gapChar="?",genome_size=5E6,blwd=5,block_colour="black",snp_colour="red",genome_offset=0,colourNodesBy=NULL,infoCols=NULL,outputPDF=NULL,outputPNG=NULL,w,h,heatmap.colours=rev(gray(seq(0,1,0.1))),tip.labels=F,tipLabelSize=1,offset=0,tip.colour.cex=0.5,legend=T,legend.pos="bottomleft",ancestral.reconstruction=F,cluster=NULL,tipColours=NULL,lwd=1.5,axis=F,axisPos=3,edge.color="black",infoCex=0.8,colLabelCex=0.8,treeWidth=10,infoWidth=10,dataWidth=30,edgeWidth=1,labelHeight=10,mainHeight=100,barDataWidth=10,blockPlotWidth=10,barDataCol=2,heatmapBreaks=NULL,heatmapDecimalPlaces=1,vlines.heatmap=NULL,vlines.heatmap.col=2,heatmap.blocks=NULL,pie.cex=0.5) {
7777

7878
require(ape)
7979

80-
# PREPARE TREE AND GET TIP ORDER
80+
# PREPARE TREE, CHOOSE LADDERISATION OR NOT, AND GET TIP ORDER
8181
if (is.character(tree)){
8282
t<-read.tree(tree)
8383
}
8484
else t<-tree
85-
tl<-ladderize(t)
85+
if (is.null(ladderise))
86+
{
87+
tl<-t
88+
}
89+
else if (ladderise=="descending")
90+
{
91+
tl<-ladderize(t, T)
92+
}
93+
else if (ladderise=="ascending")
94+
{
95+
tl<-ladderize(t, F)
96+
}
97+
else if (!is.null(ladderise))
98+
{
99+
print("Ladderise option should be exactly 'ascending' or 'descending'. Any other command will raise this error. Leave option empty to order branches as per input tree.")
100+
}
86101
tips<-tl$edge[,2]
87102
tip.order<-tips[tips<=length(tl$tip.label)]
88103
tip.label.order<-tl$tip.label[tip.order] # for ordering data. note that for tiplabel(), the order is the same as in t$tip (= tl$tip)

0 commit comments

Comments
 (0)