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 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, index labels will be reset to the TabularMSA constructor’s default.

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'}),
...         DNA('CCG', metadata={'id': 'c'})]
>>> msa = TabularMSA(seqs)
>>> msa.index
RangeIndex(start=0, stop=3, step=1)

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

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

Assign default index:

>>> msa.reassign_index()
>>> msa.index
RangeIndex(start=0, stop=3, step=1)

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', 2], dtype='object')