Return a copy of the current biological sequence.

Returns a copy of the current biological sequence, optionally with updated attributes specified as keyword arguments.


kwargs : dict, optional

Keyword arguments passed to the BiologicalSequence (or subclass) constructor. The returned copy will have its attributes updated based on the values in kwargs. If an attribute is missing, the copy will keep the same attribute as the current biological sequence. Valid attribute names are ‘sequence’, ‘id’, ‘description’, and ‘quality’. Default behavior is to return a copy of the current biological sequence without changing any attributes.



Copy of the current biological sequence, optionally with updated attributes based on kwargs. Will be the same type as the current biological sequence (self).


This is a shallow copy, but since biological sequences are immutable, it is conceptually the same as a deep copy.

This method is the preferred way of creating new instances from an existing biological sequence, instead of calling self.__class__(...), as the latter can be error-prone (e.g., forgetting to propagate attributes to the new instance).


Create a biological sequence:

>>> from skbio import BiologicalSequence
>>> seq = BiologicalSequence('AACCGGTT', id='id1',
...                          description='biological sequence',
...                          quality=[4, 2, 22, 23, 1, 1, 1, 9])

Create a copy of seq, keeping the same underlying sequence of characters and quality scores, while updating ID and description:

>>> new_seq = seq.copy(id='new-id', description='new description')

Note that the copied biological sequence’s underlying sequence and quality scores are the same as seq:

>>> new_seq.sequence
>>> new_seq.quality
array([ 4,  2, 22, 23,  1,  1,  1,  9])

The ID and description have been updated:

>>> new_seq.description
'new description'

The original biological sequence’s ID and description have not been changed:

>>> seq.description
'biological sequence'