Skip to content

Instantly share code, notes, and snippets.

@aaiezza
Created July 14, 2017 18:13
Show Gist options
  • Save aaiezza/050edf9a162b48f8477618f4efbdfdfd to your computer and use it in GitHub Desktop.
Save aaiezza/050edf9a162b48f8477618f4efbdfdfd to your computer and use it in GitHub Desktop.
Nucleotides Sliding Window
require( zoo )
require( iterpc )
# Could be retreived from anywhere of course…
nucleotideSequence <- sample( c('A','T','C','G'), 1000, replace=TRUE, prob=c(.1,.1,.4,.4) )
windowWidth <- 3
kmers <- rollapply( nucleotideSequence, width = windowWidth, by = 1, paste, collapse='' )
possibleKmers <- apply( getall( iterpc(4, 3, c('A','T','C','G'), replace = TRUE) ), 1, paste, collapse = '' )
table( factor( kmers, levels = possibleKmers ) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment