Go to home
Go to 1. monocentrics Vignette
Go to 2. holocentrics Vignette
Go to 3. groups Vignette
Go to 5. human Vignette
This guide shows the files to plot idiograms alongside a phylogeny
1 Load package
visit gitlab for installation instructions https://gitlab.com/ferroao/idiogramFISH
2 ggtree of iqtree and monocentrics
idiogramFISH comes with two trees and data.frames with chr. and marks’ data for the correspondent OTUs, first we will plot a tree produced with iqtree (Nguyen et al., 2015)
Load the iqtree:
We will use phytools for that (Revell, 2019)
require(ggplot2)
require(phytools)
require(ggpubr)
require(grid) #pushViewport
require(ggtree)
# list.files(system.file('extdata', package = 'my_package') )
# find path of iqtree file
iqtreeFile <- system.file("extdata", "eightSpIqtree.treefile", package = "idiogramFISH")
# load file as phylo object
iqtreephylo <- read.newick(iqtreeFile) # phytools
# transform tree
iqtreephyloUM <- force.ultrametric(iqtreephylo, method= "extend") # phytools
Make a ggtree (Yu and Lam, 2019)
Modify optionally graphical parameters with ggplot and ggpubr: (Kassambara, 2019; Wickham et al., 2019)
gbuil2 <- ggplot_build(ggtreeOf8) # get ggplot_built
gtgbuild <- ggplot_gtable(gbuil2) # get gtable from ggplot_built
gtgbuild$layout$clip[gtgbuild$layout$name == "panel"] <- "off" # modify gtable
ggtreeOf8 <- as_ggplot(gtgbuild) # back to ggplot
gtgbuildgg2 <- ggtreeOf8 + theme(plot.margin = unit(c(1,9.5,3,1.5), "cm") ) # top right bottom left - modify margins
Our plot of the tree is ready, let’s get the order of species in tree
Order OTUs of data.frame of chr. data
Apply order of phylogeny to data.frame
# make a vector without missing OTUs
desiredFiltered <- intersect(desiredOrder,allChrSizeSample$OTU)
# establish desired order
allChrSizeSample$OTU <- factor(allChrSizeSample$OTU, levels = desiredFiltered)
# order
allChrSizeSample <- allChrSizeSample[order(allChrSizeSample$OTU),]
Now we have to establish where are the OTUs in the tree, that don’t have chr. data
# Establish position of OTUs before missing data OTUs
matchres <- match(desiredOrder,desiredFiltered)
matchres[is.na(matchres)] <- "R"
reps <- rle(matchres)
posOTUsBeforeMissing <- as.numeric(matchres[which(matchres=="R")-1][which(matchres[which(matchres=="R")-1]!="R")] )
# This are the OTUs that come before missing chr. data OTUs
BeforeMissing <- desiredFiltered[posOTUsBeforeMissing]
# This is the amount of missing OTUs, spaces to add (ghost karyotypes)
valuesOfMissRepsBefore <- reps$lengths[which(reps$values=="R")]
Plotting
Now we are ready to plot adding those arguments for addMissingOTUAfter
and missOTUspacings
# plot to png file
png(file="firstplot.png" ,width=962,height=962 )
par(omi=rep(0,4) , mar=c(0,1,2,1),
mfrow=c(1,2) ) # one row two columns
par(fig=c(0,.3,0,1)) # location of left ghost plot
plot.new() # ghost plot to the left
par(fig=c(.3,1,0,1)) # location of right plot
plotIdiograms(allChrSizeSample, # data.frame of Chr. Sizes
allMarksSample, # d.f. of Marks (inc. cen. marks)
dfMarkColor = mydfMaColor, # d.f. of mark characteristics
roundness = 10.5, # roundness of vertices
dotRoundCorr = .8, # correct roundness aspect ratio
lwd.chr=.5, # width of lines
orderBySize = FALSE, # don't order chr. by size
centromereSize = 1.3, # apparent cen. size
OTUTextSize = 1, # Size of OTU name
chrWidth =3, # width of chr.
chrSpacing = 3, # horizontal spacing of chr.
karHeiSpace = 1.8, # karyotype vertical relative size with spacing
nameChrIndexPos=4, # move the name of chr. indexes to left
morpho=TRUE, # add chr. morphology
chrIndex = TRUE, # add chr. indices
karIndex = TRUE, # add karyotype indices
markLabelSpacer = 0 # spaces from rightmost chr. to legend
,markLabelSize = 1 # font size of legend
,legend="aside" # position of legends
,ylimTopMod = -.3 # modify ylim top margin
,ylimBotMod=.9 # modify ylim bottom margin
,xlimRightMod=2 # modify right xlim
,rulerPos = -0.7 # position of rulers
,rulerNumberSize = .35 # font size of ruler number
,rulerNumberPos = .4 # position of ruler numbers
,addMissingOTUAfter = BeforeMissing # OTUs after which there are ghost karyotypes - empty spaces
,missOTUspacings = valuesOfMissRepsBefore # number of ghost karyotypes
)
# plot to the left the ggtree
pushViewport(viewport(layout = grid.layout(1, 2)))
pushViewport(viewport(layout.pos.col = 1, layout.pos.row = 1))
print(gtgbuildgg2,newpage=F)
# close png
dev.off()
3 plot of revBayes tree and holocentrics
Function plotIdiogramsHolo
deprecated after ver. 1.5.1
Now we are going to plot a tree from revBayes (Höhna et al., 2017)
First, load the revBayes tree:
require(ggplot2)
require(phytools)
require(ggpubr)
require(grid) #pushViewport
require(ggtree)
require(treeio)
# find path of iqtree file
revBayesFile <- system.file("extdata", "revBayesTutorial.tree", package = "idiogramFISH")
# load file as phylo object
revBayesPhylo <- read.beast(revBayesFile) # ggtree or treeio
# transform tree
revBayesPhyloUM <- force.ultrametric(revBayesPhylo@phylo, method= "extend") # phytools
Then, get order of OTUs in tree
Order OTUs of data.frame of chr. data
First, create some data for holocentrics
allChrSizeSampleHolo <- allChrSizeSample
allChrSizeSampleHolo <- allChrSizeSampleHolo[,c("OTU","chrName","longArmSize")]
colnames(allChrSizeSampleHolo)[which(names(allChrSizeSampleHolo)=="longArmSize")]<-"chrSize"
allMarksSampleHolo <- allMarksSample
allMarksSampleHolo <- allMarksSampleHolo[which(allMarksSampleHolo$markArm!="cen"),]
allMarksSampleHolo <- allMarksSampleHolo[c("OTU","chrName","markName","markDistCen","markSize")]
colnames(allMarksSampleHolo)[which(names(allMarksSampleHolo)=="markDistCen")] <- "markPos"
allMarksSampleHolo[which(allMarksSampleHolo$markName=="5S"),]$markSize <- .5
Apply order of phylogeny to data.frame
# make a vector without missing OTUs
desiredFiltered <- intersect(desiredorderRevB,allChrSizeSampleHolo$OTU)
# establish desired order
allChrSizeSampleHolo$OTU <- factor(allChrSizeSampleHolo$OTU, levels = desiredFiltered)
# order
allChrSizeSampleHolo <- allChrSizeSampleHolo[order(allChrSizeSampleHolo$OTU),]
Now we have to establish where are the OTUs in the tree, that don’t have chr. data
# Establish position of OTUs before missing data OTUs
matchres <- match(desiredorderRevB,desiredFiltered)
matchres[is.na(matchres)] <- "R"
reps <- rle(matchres)
posOTUsBeforeMissing <- as.numeric(matchres[which(matchres=="R")-1][which(matchres[which(matchres=="R")-1]!="R")] )
# This are the OTUs that come before missing chr. data OTUs
BeforeMissingPlot2 <- desiredFiltered[posOTUsBeforeMissing]
# This is the amount of missing OTUs, spaces to add (ghost karyotypes)
valuesOfMissRepsBeforePlot2 <- reps$lengths[which(reps$values=="R")]
Plotting
Now we are ready to plot adding those arguments for addMissingOTUAfter
and missOTUspacings
# plot to png file
png(file=paste0("secondplot.png" ),width=962,height=700)
{
par(omi=rep(0,4) , mar=c(0,0,0,0), mfrow=c(1,2))
par(fig=c(0,.3,0,1))
plot(revBayesPhyloUM)
par(fig=c(0.3,1,0,1), new=TRUE)
par(mar=c(3,0,0,0))
# Function plotIdiogramsHolo deprecated after ver. 1.5.1
plotIdiograms(allChrSizeSampleHolo, # chr. size data.frame
allMarksSampleHolo, # data.frame of marks' positions
dfMarkColor = mydfMaColor, # d.f. of mark characteristics
roundness = 10.5, # vertices roundness
dotRoundCorr = 0.9, # correction of roundness of dots and vertices
chrWidth =2, # width of chr.
chrSpacing = 1.5, # horizontal spacing among chr.
karHeiSpace = 2, # vertical size of kar. including spacing
karIndex = TRUE # add karyotype index
,OTUTextSize = 1 # Size of OTU name
,addMissingOTUAfter = BeforeMissingPlot2 # add ghost OTUs after these names
,missOTUspacings = valuesOfMissRepsBeforePlot2 # how many ghosts, respectively
,lwd.chr=.5 # line width
,legend="aside" # make legend to the right
,markLabelSpacer = 0 # dist. of legend to rightmost chr.
,markLabelSize = 1 # font size of legend
,legendWidth = 2.3 # width of square or dots of legend
,ylimTopMod = - .3 # modify ylim of top
,ylimBotMod = - 1.5 # modify ylim of bottom
,xlimRightMod=2 # modify xlim of right
,rulerPos = - 0.7 # position of ruler
,rulerNumberSize = .35 # font size of number of ruler
,rulerNumberPos = .4 # position of ruler number
)
}
# close png
dev.off()
4 plot of revBayes tree and holocentrics and monocentrics
Available for ver. > 1.5.1
Create data.frames with both types of karyotypes (Wickham, 2016)
# Select this OTU from the monocen.
monosel<-c("Species_F","Species_C","Species_A")
# chr.
allChrSizeSampleSel <- allChrSizeSample [which(allChrSizeSample$OTU %in% monosel ),]
# marks
allMarksSampleSel <- allMarksSample [which(allMarksSample$OTU %in% monosel ),]
# Select the others from the holocen.
holosel <- setdiff(unique(allChrSizeSampleHolo$OTU),monosel)
# chr.
allChrSizeSampleHoloSel <- allChrSizeSampleHolo[which(allChrSizeSampleHolo$OTU %in% holosel ),]
# marks
allMarksSampleHoloSel <- allMarksSampleHolo [which(allMarksSampleHolo$OTU %in% holosel ),]
# merge chr d.fs
mixChrSize <- plyr::rbind.fill(allChrSizeSampleSel,allChrSizeSampleHoloSel)
# merge marks' d.fs
mixMarks <- plyr::rbind.fill(allMarksSampleSel,allMarksSampleHoloSel)
Get the desiredorderRevB
object from above to continue:
# make a vector without missing OTUs
desiredFiltered <- intersect(desiredorderRevB, mixChrSize$OTU)
# establish desired order
mixChrSize$OTU <- factor(mixChrSize$OTU, levels = desiredFiltered)
# order data.frame
mixChrSize <- mixChrSize[order(mixChrSize$OTU),]
# Establish position of OTUs before missing data OTUs
matchres <- match(desiredorderRevB,desiredFiltered)
matchres[is.na(matchres)] <- "R"
reps <- rle(matchres)
posOTUsBeforeMissing <- as.numeric(matchres[which(matchres=="R")-1][which(matchres[which(matchres=="R")-1]!="R")] )
# This are the OTUs that come before missing chr. data OTUs
BeforeMissingPlot2 <- desiredFiltered[posOTUsBeforeMissing]
# This is the amount of missing OTUs, spaces to add (ghost karyotypes)
valuesOfMissRepsBeforePlot2 <- reps$lengths[which(reps$values=="R")]
Plotting
Now we are ready to plot adding those arguments for addMissingOTUAfter
and missOTUspacings
# plot to png file
png(file=paste0("thirdplot.png" ),width=962,height=1000)
{
par(omi=rep(0,4) , mar=c(0,0,0,0), mfrow=c(1,2))
par(fig=c(0,.25,0,1))
plot(revBayesPhyloUM)
par(fig=c(0.25,1,0,1), new=TRUE)
par(mar=c(3,0,0,0))
plotIdiograms(mixChrSize, # chr. size data.frame
mixMarks, # data.frame of marks' positions (inc. cen. marks)
dfMarkColor = mydfMaColor, # d.f. of mark characteristics
origin="b", # position measured from bottom of chr.
karHeiSpace=2.2, # karyotype height with spacing included
roundness = 10.5, # vertices roundness
dotRoundCorr = 1.0, # correction of roundness of dots and vertices
chrWidth =1.8, # width of chr.
chrSpacing = 1.5, # horizontal spacing among chr.
karIndex = TRUE # add karyotype index
,OTUTextSize = 1 # Size of OTU name
,addMissingOTUAfter = BeforeMissingPlot2 # add ghost OTUs after these names
,missOTUspacings = valuesOfMissRepsBeforePlot2 # how many ghosts, respectively
,lwd.chr=.5 # line width
,legend="aside" # make legend to the right
,markLabelSpacer = 0 # dist. of legend to rightmost chr.
,markLabelSize = 1 # font size of legend
,legendWidth = 2 # width of square or dots of legend
,ylimTopMod = -.3 # modify ylim of top
,ylimBotMod = -1.8 # modify ylim of bottom
,xlimRightMod=2 # modify xlim of right
,rulerPos = -0.7 # position of ruler
,rulerNumberSize = .35 # font size of number of ruler
,rulerNumberPos = .4 # position of ruler number
)
}
# close png
dev.off()
Höhna S, Landis MJ, Heath TA. 2017. Phylogenetic inference using RevBayes Current Protocols in Bioinformatics, 2017(March): 6.16.1–6.16.34. https://doi.org/10.1002/cpbi.22
Kassambara A. 2019. Ggpubr: ’Ggplot2’ based publication ready plots. https://CRAN.R-project.org/package=ggpubr
Nguyen L-T, Schmidt HA, Haeseler A von, Minh BQ. 2015. IQ-TREE: a fast and effective stochastic algorithm for estimating maximum-likelihood phylogenies Molecular biology and evolution, 32(1): 268–274. https://doi.org/10.1093/molbev/msu300
Revell LJ. 2019. Phytools: Phylogenetic tools for comparative biology (and other things). https://CRAN.R-project.org/package=phytools
Wickham H. 2016. Plyr: Tools for splitting, applying and combining data. https://CRAN.R-project.org/package=plyr
Wickham H, Chang W, Henry L, Pedersen TL, Takahashi K, Wilke C, Woo K, Yutani H. 2019. Ggplot2: Create elegant data visualisations using the grammar of graphics. https://CRAN.R-project.org/package=ggplot2
Yu G, Lam TT-Y. 2019. Ggtree: An r package for visualization and annotation of phylogenetic trees with their covariates and other associated data. https://yulab-smu.github.io/treedata-book/