dot_plot_data <- function (seq1, seq2, wsize = 1, wstep = 1, nmatch = 1,...) { cat("Modification of dotPlot function in package seqinr.\n") cat("The function returns a matrix for plotting.\n") cat("Row names contain Sequence1, Col names Sequence2.\n") cat("Use the reshape2 package to convert and plot with ggplot2 and geom_raster.\n") require(seqinr) if (nchar(seq1[1]) > 1) stop("seq1 should be provided as a vector of single chars") if (nchar(seq2[1]) > 1) stop("seq2 should be provided as a vector of single chars") if (wsize < 1) stop("non allowed value for wsize") if (wstep < 1) stop("non allowed value for wstep") if (nmatch < 1) stop("non allowed value for nmatch") if (nmatch > wsize) stop("nmatch > wsize is not allowed") mkwin <- function(seq, wsize, wstep) { sapply(seq(from = 1, to = length(seq) - wsize + 1, by = wstep), function(i) c2s(seq[i:(i + wsize - 1)])) } wseq1 <- mkwin(seq1, wsize, wstep) wseq2 <- mkwin(seq2, wsize, wstep) if (nmatch == wsize) { xy <- outer(wseq1, wseq2, "==") } else { "%==%" <- function(x, y) colSums(sapply(x, s2c) == sapply(y, s2c)) >= nmatch xy <- outer(wseq1, wseq2, "%==%") } # xy is a matrix, write row names and column names for reference colnames(xy) <- wseq2 rownames(xy) <- wseq1 return(xy) }