Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/allpy/file/afed1fd8920c/allpy/dna.py
Дата изменения: Unknown
Дата индексирования: Sun Feb 3 18:34:51 2013
Кодировка:
allpy: afed1fd8920c allpy/dna.py

allpy

view allpy/dna.py @ 1091:afed1fd8920c

Added backreferences to `Seqeunce`s from `Monomer`s (closes #49) WARNING! Please note that `Sequence` API almost changed entirely! WARNING! This commit immediately obsoletes classmethods `Monomer.from_code*`, `Monomer.from_name` and `Sequence.from_monomers`. Turns out, python can not pickle sets/dicts which have keys, which inderecly reference the set/dict itself: http://bugs.python.org/issue9269 -- which is excatly what we have in abundance after this change. To allow pickling added `__getstate__` to `Monomer` to return all attributes, except `sequence` and `__setstate__` to `Sequence`, which runs through all monomers and returns the `sequence` attribute back to where it belongs. WARNING! This MAY result in unexpected behaviour in some cases. (Which should be rare enough).
author Daniil Alexeyevsky <dendik@kodomo.fbb.msu.ru>
date Sat, 02 Jun 2012 19:33:42 +0400
parents 4a9b4503a027
children c4c772e3ce86
line source
1 import base
2 import data.codes
4 import dna
6 class Monomer(base.Monomer):
7 """DNA monomers: nucleotides."""
8 type = 'dna'
9 types = dna
10 by_code1 = {}
11 by_code3 = {}
12 by_name = {}
13 Monomer._initialize(data.codes.dna)
15 class Sequence(base.Sequence):
16 types = dna
18 def reverse_complemented(self):
19 """Return a new sequence, reverse-complement to self.
21 Name of the sequence is name of self with apostrophe added.
22 """
23 complement = {'A': 'T', 'T': 'A', 'C': 'G', 'G': 'C'}
24 result = self.types.Sequence(
25 name=self.name +"'",
26 description=self.description,
27 source=self.source
28 )
29 for monomer in reversed(self):
30 result.append_monomer(complement.get(monomer.code1, 'N'))
31 return result
33 class Column(base.Column):
34 types = dna
36 class Alignment(base.Alignment):
37 types = dna
39 class Block(Alignment, base.Block):
40 pass
42 # vim: set ts=4 sts=4 sw=4 et: