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

# HG changeset patch
# User Daniil Alexeyevsky
# Date 1296590888 -10800
# Node ID df571a5233fb3c4efc567f22495086c3f62946d1
# Parent d66d470a9c0aefa04a1981315353433957faeb6b
Changed the way related types are stored for Alignment, Block, Sequence, Monomer

Now each of them has attribute 'type', which is an object with four attributes:
- Alignment
- Block
- Sequence
- Monomer

diff -r d66d470a9c0a -r df571a5233fb allpy/base.py
--- a/allpy/base.py Tue Feb 01 18:46:23 2011 +0300
+++ b/allpy/base.py Tue Feb 01 23:08:08 2011 +0300
@@ -4,6 +4,9 @@
import util
import fasta

+# import this very module as means of having all related classes in one place
+import base
+
default_gaps = set((".", "-", "~"))
"""Set of characters to recoginze as gaps when parsing alignment."""

@@ -13,6 +16,9 @@
type = None
"""Either of 'dna', 'rna', 'protein'."""

+ types = base
+ """Mapping of related types. SHOULD be redefined in subclasses."""
+
by_code1 = {}
"""A mapping from 1-letter code to Monomer subclass."""

@@ -90,14 +96,10 @@
* source -- str denoting source of the sequence

Any of them may be empty (i.e. hold empty string)
-
- Class attributes:
-
- * monomer_type -- type of monomers in sequence, must be redefined when
- subclassing
"""

- monomer_type = Monomer
+ types = base
+ """Mapping of related types. SHOULD be redefined in subclasses."""

name = ''
description = ''
@@ -118,7 +120,7 @@
@classmethod
def from_string(cls, string, name='', description='', source=''):
"""Create sequences from string of one-letter codes."""
- monomer = cls.monomer_type.from_code1
+ monomer = cls.types.Monomer.from_code1
monomers = [monomer(letter) for letter in string]
return cls.from_monomers(monomers, name, description, source)

@@ -136,16 +138,8 @@
class Alignment(object):
"""Alignment. It is a list of Columns."""

- alignment_type = None
- """Related Alignment class. SHOULD be redefined when subclassing."""
- # Actually given value at EOF, since name Alignment is not yet defined
-
- block_type = None
- """Related Block class. SHOULD be redefined when subclassing."""
- # Actually given value at EOF, since name Block is not yet defined
-
- sequence_type = Sequence
- """Type of sequences in alignment. SHOULD be redefined when subclassing."""
+ types = base
+ """Mapping of related types. SHOULD be redefined in subclasses."""

sequences = None
"""Ordered list of sequences in alignment. Read, but DO NOT FIDDLE!"""
@@ -171,7 +165,7 @@
def append_row_from_string(self, string,
name='', description='', source='', gaps=default_gaps):
"""Add row from a string of one-letter codes and gaps. Return self."""
- Sequence = self.sequence_type
+ Sequence = self.types.Sequence
not_gap = lambda (i, char): char not in gaps
without_gaps = util.remove_each(string, gaps)
sequence = Sequence.from_string(without_gaps, name, description, source)
@@ -392,6 +386,9 @@
the column.
"""

+ types = base
+ """Mapping of related types. SHOULD be redefined in subclasses."""
+
def __hash__(self):
"""Return hash by identity."""
return id(self)
@@ -434,7 +431,4 @@
block.columns = columns
return block

-Alignment.alignment_type = Alignment
-Alignment.block_type = Block
-
# vim: set ts=4 sts=4 sw=4 et:
diff -r d66d470a9c0a -r df571a5233fb allpy/dna.py
--- a/allpy/dna.py Tue Feb 01 18:46:23 2011 +0300
+++ b/allpy/dna.py Tue Feb 01 23:08:08 2011 +0300
@@ -1,25 +1,24 @@
import base
import data.codes

+import dna
+
class Monomer(base.Monomer):
"""DNA monomers: nucleotides."""
type = 'dna'
+ types = dna
by_code1 = {}
by_code3 = {}
by_name = {}
Monomer._initialize(data.codes.dna)

class Sequence(base.Sequence):
- monomer_type = Monomer
+ types = dna
+
+class Alignment(base.Alignment):
+ types = dna

class Block(Alignment, base.Block):
pass

-class Alignment(base.Alignment):
- sequence_type = Sequence
- block_type = Block
- # alignment_type is defined at EOF, since name Alignment undefined yet
-
-Alignment.alignment_type = Alignment
-
# vim: set ts=4 sts=4 sw=4 et:
diff -r d66d470a9c0a -r df571a5233fb allpy/protein.py
--- a/allpy/protein.py Tue Feb 01 18:46:23 2011 +0300
+++ b/allpy/protein.py Tue Feb 01 23:08:08 2011 +0300
@@ -1,9 +1,12 @@
import base
import data.codes

+import protein
+
class Monomer(base.Monomer):
"""Protein monomers: aminoacids."""
type = 'protein'
+ types = protein
by_code1 = {}
by_code3 = {}
by_name = {}
@@ -14,15 +17,13 @@
pass

class Sequence(base.Sequence):
- monomer_type = Monomer
+ types = protein

class Block(Alignment, base.Block):
pass

class Alignment(base.Alignment):
- sequence_type = Sequence
- block_type = Block
- # alignment_type is defined at EOF, since name Alignment undefined yet
+ types = protein

def muscle_align(self):
""" Simple align ths alignment using sequences (muscle)
@@ -52,6 +53,4 @@
self.body[sequence].append(old_monomer)
os.unlink(tmp_file.name)

-Alignment.alignment_type = Alignment
-
# vim: set ts=4 sts=4 sw=4 et:
diff -r d66d470a9c0a -r df571a5233fb allpy/rna.py
--- a/allpy/rna.py Tue Feb 01 18:46:23 2011 +0300
+++ b/allpy/rna.py Tue Feb 01 23:08:08 2011 +0300
@@ -1,25 +1,24 @@
import base
import data.codes

+import rna
+
class Monomer(base.Monomer):
"""RNA monomers: nucleotides."""
type = 'rna'
+ types = rna
by_code1 = {}
by_code3 = {}
by_name = {}
Monomer._initialize(data.codes.rna)

class Sequence(base.Sequence):
- monomer_type = Monomer
+ types = rna

class Block(Alignment, base.Block):
pass

class Alignment(base.Alignment):
- sequence_type = Sequence
- block_type = Block
- # alignment_type is defined at EOF, since name Alignment undefined yet
-
-Alignment.alignment_type = Alignment
+ types = rna

# vim: set ts=4 sts=4 sw=4 et: