skbio.sequence.DNASequence.k_words

DNASequence.k_words(k, overlapping=True)[source]

Get the list of words of length k

Parameters:

k : int

The word length.

overlapping : bool, optional

Defines whether the k-words should be overlapping or not overlapping.

Returns:

iterator of BiologicalSequences

Iterator of words of length k contained in the BiologicalSequence.

Raises:

ValueError

If k < 1.

Examples

>>> from skbio.sequence import BiologicalSequence
>>> s = BiologicalSequence('ACACGACGTT')
>>> [str(kw) for kw in s.k_words(4, overlapping=False)]
['ACAC', 'GACG']
>>> [str(kw) for kw in s.k_words(3, overlapping=True)]
['ACA', 'CAC', 'ACG', 'CGA', 'GAC', 'ACG', 'CGT', 'GTT']