Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/allpy/raw-rev/21c2358cb5e7
Дата изменения: Unknown
Дата индексирования: Tue Oct 2 07:32:37 2012
Кодировка:

# HG changeset patch
# User Daniil Alexeyevsky
# Date 1292514665 -10800
# Node ID 21c2358cb5e729edff5b61a02cbcab55abbc416b
# Parent c305a80cdb759b4206f1f65a812a5def88cceae5
Implemented allpy.base.Alignment row/column model: methods rows(), *_as_lists()

diff -r c305a80cdb75 -r 21c2358cb5e7 allpy/base.py
--- a/allpy/base.py Thu Dec 16 18:35:56 2010 +0300
+++ b/allpy/base.py Thu Dec 16 18:51:05 2010 +0300
@@ -199,6 +199,9 @@
self.sequences = []
self.columns = []

+ # Alignment modification methods
+ # ==============================
+
def append_sequence(self, sequence):
"""Add sequence to alignment.

@@ -218,6 +221,9 @@
self.columns[j][seq] = sequence[i]
self.sequences.append(sequence)

+ # Alignment IO methods
+ # ====================
+
@classmethod
def from_fasta(cls, file):
"""Create new alignment from FASTA file."""
@@ -237,6 +243,69 @@
line = "".join(map(char, row))
fasta.save_file(file, line, seq.name, seq.description)

+ # Data access methods for alignment
+ # =================================
+
+ def rows(self):
+ """Return list of rows (temporary objects) in alignment.
+
+ Each row is a dictionary of { column : monomer }.
+
+ For gap positions there is no key for the column in row.
+
+ Each row has attribute `sequence` pointing to the sequence the row is
+ describing.
+
+ Modifications of row have no effect on the alignment.
+ """
+ # For now, the function returns a list rather than iterator.
+ # It is yet to see, whether memory performance here becomes critical,
+ # or is random access useful.
+ rows = []
+ for sequence in self.sequences:
+ row = util.UserDict()
+ row.sequence = sequence
+ for column in self.columns:
+ if sequence in column:
+ row[column] = column[sequence]
+ rows.append(row)
+ return rows
+
+ def rows_as_lists(self):
+ """Return list of rows (temporary objects) in alignment.
+
+ Each row here is a list of either monomer or None (for gaps).
+
+ Each row has attribute `sequence` pointing to the sequence of row.
+
+ Modifications of row have no effect on the alignment.
+ """
+ rows = []
+ for sequence in self.sequences:
+ row = util.UserList()
+ row.sequence = sequence
+ for column in self.columns:
+ row.append(column.get(sequence))
+ rows.append(row)
+ return rows
+
+ def columns_as_lists(self):
+ """Return list of columns (temorary objects) in alignment.
+
+ Each column here is a list of either monomer or None (for gaps).
+
+ Items of column are sorted in the same way as alignment.sequences.
+
+ Modifications of column have no effect on the alignment.
+ """
+ columns = []
+ for column in self.columns:
+ col = []
+ for sequence in self.sequences:
+ col.append(column.get(sequence))
+ columns.append(col)
+ return columns
+
## Unclean code follows

def length(self):