R/plot_sliding_window.R

Defines functions plot_sliding_window

Documented in plot_sliding_window

#' plot_sliding_window
#'
#' By Coghlan (2011)
#'
#' @param windowsize Size of window
#' @param inputseq Sequence to analyze
#'
#' @export

plot_sliding_window <- function(windowsize, inputseq)
{
  starts <- seq(1, length(inputseq)-windowsize, by = windowsize)
  n <- length(starts)    # Find the length of the vector "starts"
  chunkGCs <- numeric(n) # Make a vector of the same length as
  # vector "starts", but just containing zeroes

  for (i in 1:n) {
    chunk <- inputseq[starts[i]:(starts[i]+windowsize-1)]
    chunkGC <- seqinr::GC(chunk)
    print(chunkGC)
    chunkGCs[i] <- chunkGC
  }

  plot(starts,
       chunkGCs,
       type="b",
       xlab="Nucleotide start position",
       ylab="GC content")
}
brouwern/compbio4all documentation built on Dec. 19, 2021, 11:47 a.m.