skbio.sequence.Sequence.iter_kmers#

Sequence.iter_kmers(k, overlap=True)[source]#

Generate kmers of length k from this sequence.

Parameters:
kint

The kmer length.

overlapbool, optional

Defines whether the kmers should be overlapping or not.

Yields:
Sequence

kmer of length k contained in this sequence.

Raises:
ValueError

If k is less than 1.

Examples

>>> from skbio import Sequence
>>> s = Sequence('ACACGACGTT')
>>> for kmer in s.iter_kmers(4, overlap=False):
...     str(kmer)
'ACAC'
'GACG'
>>> for kmer in s.iter_kmers(3, overlap=True):
...     str(kmer)
'ACA'
'CAC'
'ACG'
'CGA'
'GAC'
'ACG'
'CGT'
'GTT'