skbio.sequence.RNA.iter_kmers

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

Generate kmers of length k from this sequence.

State: Stable as of 0.4.0.

Parameters
  • k (int) – The kmer length.

  • overlap (bool, 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'