skbio.alignment.Alignment.iter_positions

Alignment.iter_positions(constructor=None)[source]

Generator of Alignment positions (i.e., columns)

Parameters:

constructor : type, optional

Constructor function for creating the positional values. By default, these will be the same type as corresponding skbio.sequence.BiologicalSequence in the SequenceCollection object, but you can pass a skbio.sequence.BiologicalSequence class here to ensure that they are all of consistent type, or str to have them returned as strings.

Returns:

GeneratorType

Generator of lists of positional values in the SequenceCollection (effectively the transpose of the alignment).

See also

iter

Examples

>>> from skbio.alignment import Alignment
>>> from skbio.sequence import DNA
>>> sequences = [DNA('ACCGT--', id="seq1"),
...              DNA('AACCGGT', id="seq2")]
>>> a1 = Alignment(sequences)
>>> for position in a1.iter_positions():
...     print(position)
[<DNASequence: A (length: 1)>, <DNASequence: A (length: 1)>]
[<DNASequence: C (length: 1)>, <DNASequence: A (length: 1)>]
[<DNASequence: C (length: 1)>, <DNASequence: C (length: 1)>]
[<DNASequence: G (length: 1)>, <DNASequence: C (length: 1)>]
[<DNASequence: T (length: 1)>, <DNASequence: G (length: 1)>]
[<DNASequence: - (length: 1)>, <DNASequence: G (length: 1)>]
[<DNASequence: - (length: 1)>, <DNASequence: T (length: 1)>]
>>> for position in a1.iter_positions(constructor=str):
...     print(position)
['A', 'A']
['C', 'A']
['C', 'C']
['G', 'C']
['T', 'G']
['-', 'G']
['-', 'T']