Package csb :: Package bio :: Package sequence :: Class AbstractAlignment

[frames] | no frames]

# Class AbstractAlignment

source code

    object --+
             |
            AbstractAlignment

Known Subclasses:
  - A3MAlignment
  - , SequenceAlignment
  - , StructureAlignment

Base class for all alignment objects.

Provides 1-based access to the alignment.rows and alignment.columns. Alignment rows can also be accessed by sequence ID. In addition, all alignments support 0-based slicing:

    >>> alignment[rows, columns]
    AbstractAlignment (sub-alignment)

where

- `rows` can be a slice, tuple of row indexes or tuple of sequence IDs
- columns can be a slice or tuple of column indexes

For example:

    >>> alignment[:, 2:]
    AbstractAlignment     # all rows, columns [3, alignment.length]
    >>> alignment[(0, 'seqx'), (3, 5)]
    AbstractAlignment     # rows #1 and 'seq3', columns #4 and #5

Note: if `strict` is False and there are `sequences` with redundant identifiers, those sequences will be added to the `rows` collection with :An suffix, where n is a serial number. Therefore, rows['ID'] will return only one sequence, the first sequence with id=ID. All remaining sequences can be retrieved with `rows['ID:A1']`, {rows['ID:A2']}, etc. However, the sequence objects will remain intact, e.g. {rows['ID:A1'].id} still returns 'ID' and not 'ID:A1'.

Nested Classes
| __metaclass__ Metaclass for defining Abstract Base Classes (ABCs).

Instance Methods

__getitem__(self, spec) | source code

__init__(self, sequences, strict=True) x.__init__(...) initializes x; see help(type(x)) for signature | source code

__iter__(self) | source code

add(self, sequence) Append a new sequence to the alignment. | source code

str

format(self, format=FASTA, headers=True) Format the alignment as a string. | source code

bool

gap_at(self, column) Return True of `column` contains at least one gap. | source code

AbstractAlignment

subregion(self, start, end) Extract a sub-alignment, ranging from `start` to `end` columns. | source code

Inherited from `object`: `__delattr__`, `__format__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__repr__`, `__setattr__`, `__sizeof__`, `__str__`, `__subclasshook__`

Class Variables
| __abstractmethods__ = ``frozenset([``'``_construct``'``])``

Properties
ColumnIndexer | columns 1-based access to the alignment columns
int | length Number of columns in the alignment
AlignmentRowsTable | rows 1-based access to the alignment entries (sequences)
int | size Number of rows (sequences) in the alignment
Inherited from `object`: `__class__`

Method Details

### __init__(self, sequences, strict=True)
(Constructor)

source code

x.__init__(...) initializes x; see help(type(x)) for signature

Parameters:
  - `sequences` (list of AbstractSequences) - alignment entries (must have equal length)
  - `strict` (bool) - if True, raise {DuplicateSequenceError} when a duplicate ID is found (default=True)
Overrides: object.__init__
  (inherited documentation)

### add(self, sequence)

source code

Append a new sequence to the alignment.

Parameters:
  - `sequence` (AbstractSequence)
Raises:
  - `SequenceError` - if the new sequence is too short/long
  - `DuplicateSequenceError` - if a sequence with same ID already exists

### format(self, format=FASTA, headers=True)

source code

Format the alignment as a string.

Parameters:
  - `format` (EnumItem) - alignment format type, member of AlignmentFormats
  - `headers` (bool) - if False, omit headers
Returns: str

### gap_at(self, column)

source code

Return True of `column` contains at least one gap.

Parameters:
  - `column` (int) - column number, 1-based
Returns: bool

### subregion(self, start, end)

source code

Extract a sub-alignment, ranging from `start` to `end` columns.

Parameters:
  - `start` (int) - starting column, 1-based
  - `end` (int) - ending column, 1-based
Returns: AbstractAlignment
  a new alignment of the current type
Raises:
  - `ColumnPositionError` - if start/end is out of range

Property Details

### columns

1-based access to the alignment columns

Get Method:
  unreachable.columns(self) - 1-based access to the alignment columns
Type:
  ColumnIndexer

### length

Number of columns in the alignment

Get Method:
  unreachable.length(self) - Number of columns in the alignment
Type:
  int

### rows

1-based access to the alignment entries (sequences)

Get Method:
  unreachable.rows(self) - 1-based access to the alignment entries (sequences)
Type:
  AlignmentRowsTable

### size

Number of rows (sequences) in the alignment

Get Method:
  unreachable.size(self) - Number of rows (sequences) in the alignment
Type:
  int