##' Chops sequences randomly
##'
##' @param seq The raw sequence to be chopped
##' @param len The length of the chopped pieces (for now, this a constant)
##' @param n The number of pieces to return
##' @export
##'
random_chop <- function(seq_data, len, n) {
browser()
# Calculate number of sequences
if(n == "complete") {
n <- ceiling(length(seq_data) / len)
}
# Check if seq has length n. This turns out to be a useful test if you are a crummy programmer like some people whose names I won't mention, but which rhyme with Bambrew Fleen.
if(length(seq_data) <= 1) {
warning("Sequence has length less than 1 which is messed up.")
return(NA)
}
### Make a vector of start values for the cuts
start.pos <- sample(length(seq_data), n, replace=TRUE)
# Preallocate a list to contain the "chopped" sequences
# NB I have no idea whether this actually helps
empt.vec <- rep(NA, len)
chopped.seq.list <- rep(list(empt.vec), n)
# Should use vapply for safety
# The problem is that R is trying to apply circular_cut to each element of seq (maybe?)
chopped.seq.list <- lapply(start.pos, FUN = circular_cut, seq_data = seq_data, len = len)
#chopped.seq.df <- purrr::map_dfr(start.pos, .f = circular_cut, seq = seq, len = len)
chopped.seq.list
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.