skbio.core.sequence.ProteinSequence.k_words

ProteinSequence.k_words(k, overlapping=True, constructor=<type 'str'>)[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.

constructor : type, optional

The constructor for the returned k-words.

Returns:

iterator

Iterator of words of length k contained in the BiologicalSequence.

Raises:

ValueError

If k < 1.

Examples

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