skbio.alignment.Alignment.subalignment

Alignment.subalignment(seqs_to_keep=None, positions_to_keep=None, invert_seqs_to_keep=False, invert_positions_to_keep=False)[source]

Returns new Alignment that is a subset of the current Alignment

Parameters:

seqs_to_keep : list, optional

A list of sequence ids to be retained in the resulting Alignment. If this is not passed, the default will be to retain all sequences.

positions_to_keep : list, optional

A list of position ids to be retained in the resulting Alignment. If this is not passed, the default will be to retain all positions.

invert_seqs_to_keep : bool, optional

If True, the sequences identified in seqs_to_keep will be discarded, rather than retained.

invert_positions_to_keep : bool, optional

If True, the sequences identified in positions_to_keep will be discarded, rather than retained.

Returns:

Alignment

The specified subalignment.

Examples

>>> from skbio.alignment import Alignment
>>> from skbio.sequence import DNA
>>> seqs = [DNA("A-CCGGG", id="s1"),
...         DNA("ATCC--G", id="s2"),
...         DNA("ATCCGGA", id="s3")]
>>> a1 = Alignment(seqs)
>>> a1
<Alignment: n=3; mean +/- std length=7.00 +/- 0.00>
>>> a1.subalignment(seqs_to_keep=["s1", "s2"])
<Alignment: n=2; mean +/- std length=7.00 +/- 0.00>
>>> a1.subalignment(seqs_to_keep=["s1", "s2"],
...         invert_seqs_to_keep=True)
<Alignment: n=1; mean +/- std length=7.00 +/- 0.00>
>>> a1.subalignment(positions_to_keep=[0, 2, 3, 5])
<Alignment: n=3; mean +/- std length=4.00 +/- 0.00>
>>> a1.subalignment(positions_to_keep=[0, 2, 3, 5],
...         invert_positions_to_keep=True)
<Alignment: n=3; mean +/- std length=3.00 +/- 0.00>
>>> a1.subalignment(seqs_to_keep=["s1", "s2"],
...         positions_to_keep=[0, 2, 3, 5])
<Alignment: n=2; mean +/- std length=4.00 +/- 0.00>