How to do it...

Creating dot plots for alignment visualization can be executed using the following steps:

  1. Load the libraries and sequences:
library(Biostrings)
library(ggplot2)
library(dotplot)
seqs <- readAAStringSet(file.path(getwd(), "datasets", "ch4", "bhlh.fa"))
  1. Make a basic dot plot:
dotPlotg(as.character(seqs[[1]]), as.character(seqs[[2]] ))

  1. Change the dot plot and apply the ggplot2 themes and labels:
dotPlotg(as.character(seqs[[1]]), as.character(seqs[[2]] ), wsize=7, wstep=5, nmatch=4) + 
theme_bw() +
labs(x=names(seqs)[1], y=names(seqs)[2] )
  1. Make a function that will create a dot plot from sequences provided and the sequence index:
make_dot_plot <- function(i=1, j=1, seqs = NULL){
seqi <- as.character(seqs[[i]])
seqj <- as.character(seqs[[j]])
namei <- names(seqs)[i]
namej <- names(seqs)[j]
return( dotPlotg(seqi, seqj ) + theme_bw() + labs(x=namei, y=namej) )
}
  1. Set up data structures to run the function:
combinations <- expand.grid(1:length(seqs),1:length(seqs))
plots <- vector("list", nrow(combinations) )
  1. Run the function on all the possible combinations of pairs of sequences:
for (r in 1:nrow(combinations)){
i <- combinations[r,]$Var1[[1]]
j <- combinations[r,]$Var2[[1]]
plots[[r]] <- make_dot_plot(i,j, seqs)
}
  1. Plot the grid of plots:
cowplot::plot_grid(plotlist = plots)
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.58.143