Skip to main content
`Ctrl`+`K`

# skbio.sequence.GrammaredSequence.count

GrammaredSequence.count(subsequence, start=None, end=None)

  Count occurrences of a subsequence in this sequence.

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

      Subsequence to count occurrences of.

    start int, optional

      The position at which to start counting (inclusive).

    end int, 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