skbio.alignment.TabularMSA.reassign_index

TabularMSA.reassign_index(mapping=None, minter=None)[source]

Reassign index labels to sequences in this MSA.

State: Experimental as of 0.4.1.

Parameters:

mapping : dict-like or callable, optional

Dictionary or callable that maps existing labels to new labels. Any label without a mapping will remain the same.

minter : callable or metadata key, optional

If provided, defines an index label for each sequence. Can either be a callable accepting a single argument (each sequence) or a key into each sequence’s metadata attribute.

Raises:

ValueError

If mapping and minter are both provided.

See also

index

Notes

If neither mapping nor minter are provided, default pandas labels will be used: integer labels 0..(N-1), where N is the number of sequences.

Examples

Create a TabularMSA object with default index labels:

>>> from skbio import DNA, TabularMSA
>>> seqs = [DNA('ACG', metadata={'id': 'a'}),
...         DNA('AC-', metadata={'id': 'b'})]
>>> msa = TabularMSA(seqs)
>>> msa.index
Int64Index([0, 1], dtype='int64')

Assign new index to the MSA using each sequence’s ID as a label:

>>> msa.reassign_index(minter='id')
>>> msa.index
Index(['a', 'b'], dtype='object')

Assign default index:

>>> msa.reassign_index()
>>> msa.index
Int64Index([0, 1], dtype='int64')

Alternatively, a mapping of existing labels to new labels may be passed via mapping:

>>> msa.reassign_index(mapping={0: 'seq1', 1: 'seq2'})
>>> msa.index
Index(['seq1', 'seq2'], dtype='object')