LEXF: Enumerating k-mers Lexicographically
Assume that an alphabet has a predetermined order; that is, we write the alphabet as a permutation , where . For instance, the English alphabet is organized as .
Given two strings and having the same length , we say that precedes in the lexicographic order (and write ) if the first symbol that doesn’t match satisfies in .
Given: A collection of at most 10 symbols defining an ordered alphabet, and a positive integer ().
Return: All strings of length that can be formed from the alphabet, ordered lexicographically (use the standard order of symbols in the English alphabet).
A C G T 2
AA AC AG AT CA CC CG CT GA GC GG GT TA TC TG TT
Error in library(gtools): there is no package called 'gtools'
library(magrittr) f <- "lexf.txt" raw <- read_file(f) %>% strsplit(split = "\n") %>% unlist() a <- raw %>% strsplit(split = " ") %>% unlist() n <- as.numeric(raw) p <- permutations(length(a), n, v = a, repeats.allowed = TRUE)
Error in permutations(length(a), n, v = a, repeats.allowed = TRUE): could not find function "permutations"
apply(p, 1, paste, collapse = "") %>% cat(sep = "\n")
Error in apply(p, 1, paste, collapse = ""): object 'p' not found