skbio.sequence.Protein.__getitem__#

Protein.__getitem__(indexable)[source]#

Slice this sequence.

Parameters:
indexableint, slice, iterable (int and slice), 1D array_like (bool)

The position(s) to return from this sequence. If indexable is an iterable of integers, these are assumed to be indices in the sequence to keep. If indexable is a 1D array_like of booleans, these are assumed to be the positions in the sequence to keep.

Returns:
Sequence

New sequence containing the position(s) specified by indexable in this sequence. Positional metadata will be sliced in the same manner and included in the returned sequence. metadata is included in the returned sequence.

Notes

This drops the self.interval_metadata from the returned new Sequence object.

Examples

>>> from skbio import Sequence
>>> s = Sequence('GGUCGUGAAGGA')

Obtain a single character from the sequence:

>>> s[1]
Sequence
-------------
Stats:
    length: 1
-------------
0 G

Obtain a slice:

>>> s[7:]
Sequence
-------------
Stats:
    length: 5
-------------
0 AAGGA

Obtain characters at the following indices:

>>> s[[3, 4, 7, 0, 3]]
Sequence
-------------
Stats:
    length: 5
-------------
0 CGAGC

Obtain characters at positions evaluating to True:

>>> s = Sequence('GGUCG')
>>> index = [True, False, True, 'a' == 'a', False]
>>> s[index]
Sequence
-------------
Stats:
    length: 3
-------------
0 GUC