skbio.sequence.Sequence.count#

Sequence.count(subsequence, start=None, end=None)[source]#

Count occurrences of a subsequence in this sequence.

Parameters:
subsequencestr, Sequence, or 1D np.ndarray (np.uint8 or ‘|S1’)

Subsequence to count occurrences of.

startint, optional

The position at which to start counting (inclusive).

endint, optional

The position at which to stop counting (exclusive).

Returns:
int

Number of occurrences of subsequence in this sequence.

Raises:
ValueError

If subsequence is of length 0.

TypeError

If subsequence is a Sequence object with a different type than this sequence.

Examples

>>> from skbio import Sequence
>>> s = Sequence('GGUCG')
>>> s.count('G')
3
>>> s.count('GG')
1
>>> s.count('T')
0
>>> s.count('G', 2, 5)
1