#' Count k-mer from reads
#'
#' @docType methods
#' @name kmerScan
#' @rdname kmerScan
#'
#' @param count Count matrix of peptides.
#' @param kmer An integer.
#'
#' @return Count matrix for k-mer motif.
#'
#' @author Wubing Zhang
#' @import data.table
#' @export
#'
kmerScan <- function(count, kmer = 5){
require(data.table)
peplen = nchar(rownames(count)[1])
if(kmer>=peplen) return(count)
peptides_k = unlist(lapply(kmer:peplen, function(y){
substr(rownames(count), y-kmer+1, y)
}))
peptides_k = matrix(peptides_k, ncol = nrow(count), byrow = TRUE)
colnames(peptides_k) = rownames(count)
tmp = as.data.frame(stack(peptides_k))
tmp = cbind.data.frame(tmp, count[tmp$col,])
tmp = setDT(tmp)
newcount = tmp[, lapply(.SD, sum), .SDcols = colnames(tmp)[4:ncol(tmp)], by = value]
newcount = as.data.frame(newcount, stringsAsFactors = FALSE)
rownames(newcount) = newcount$value;
newcount = newcount[,-1]
return(newcount)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.