# skbio.alignment.TabularMSA.append¶

TabularMSA.append(sequence, minter=None, index=None, reset_index=False)[source]

Append a sequence to the MSA without recomputing alignment.

State: Experimental as of 0.4.1.

Parameters: sequence : GrammaredSequence Sequence to be appended. Must match the dtype of the MSA and the number of positions in the MSA. minter : callable or metadata key, optional Used to create an index label for the sequence being appended. If callable, it generates a label directly. Otherwise it’s treated as a key into the sequence metadata. Note that minter cannot be combined with index nor reset_index. index : object, optional Index label to use for the appended sequence. Note that index cannot be combined with minter nor reset_index. reset_index : bool, optional If True, this MSA’s index is reset to the TabularMSA constructor’s default after appending. Note that reset_index cannot be combined with minter nor index. ValueError If exactly one choice of minter, index, or reset_index is not provided. TypeError If the sequence object isn’t a GrammaredSequence. TypeError If the type of the sequence does not match the dtype of the MSA. ValueError If the length of the sequence does not match the number of positions in the MSA.

Notes

The MSA is not automatically re-aligned when a sequence is appended. Therefore, this operation is not necessarily meaningful on its own.

Examples

Create an MSA with a single sequence labeled 'seq1':

>>> from skbio import DNA, TabularMSA
>>> msa = TabularMSA([DNA('ACGT')], index=['seq1'])
>>> msa
TabularMSA[DNA]
---------------------
Stats:
sequence count: 1
position count: 4
---------------------
ACGT
>>> msa.index
Index(['seq1'], dtype='object')


Append a new sequence to the MSA, providing its index label via index:

>>> msa.append(DNA('AG-T'), index='seq2')
>>> msa
TabularMSA[DNA]
---------------------
Stats:
sequence count: 2
position count: 4
---------------------
ACGT
AG-T
>>> msa.index
Index(['seq1', 'seq2'], dtype='object')


Append another sequence, this time resetting the MSA’s index labels to the default with reset_index. Note that since the MSA’s index is reset, we do not need to provide an index label for the new sequence via index or minter:

>>> msa.append(DNA('ACGA'), reset_index=True)
>>> msa
TabularMSA[DNA]
---------------------
Stats:
sequence count: 3
position count: 4
---------------------
ACGT
AG-T
ACGA
>>> msa.index
RangeIndex(start=0, stop=3, step=1)