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

allpy

view allpy/dna.py @ 1159:ae4bf19c70ec

compare-aln-3d/web: add language change buttons, save chosen language to cookies
author Boris Nagaev <bnagaev@gmail.com>
date Fri, 25 Jan 2013 18:24:20 +0400
parents afed1fd8920c
children
line source
1 import base
2 import data.codes
3 from data.genetic_code import standard_dna_code
5 import dna
6 import protein
8 class Monomer(base.Monomer):
9 """DNA monomers: nucleotides."""
10 type = 'dna'
11 types = dna
12 by_code1 = {}
13 by_code3 = {}
14 by_name = {}
15 Monomer._initialize(data.codes.dna)
17 class Sequence(base.Sequence):
18 types = dna
20 def reverse_complemented(self):
21 """Return a new sequence, reverse-complement to self.
23 Name of the sequence is name of self with apostrophe added.
24 """
25 complement = {'A': 'T', 'T': 'A', 'C': 'G', 'G': 'C'}
26 result = self.types.Sequence(
27 name=self.name +"'",
28 description=self.description,
29 source=self.source
30 )
31 for monomer in reversed(self):
32 result.append_monomer(complement.get(monomer.code1, 'N'))
33 return result
35 def translated(self, code=None, name=None, description=None, source=None):
36 """Return a new protein sequence translated from self.
38 `code` is a dict of triplet of dna `code1`s -> aminoacid `name`.
40 If `code` is not specified, the standard genetic code is used.
42 If `code` is specified, it may contain only the changed codons.
44 Class of proteins to use is `self.types.protein.Sequence`, you
45 are free to replace it at will.
47 Return new protein sequence where:
49 * `name` is self.name with "_tr" appended
50 * `description` is self.description with " translated" appended
51 * `source` is the same as self.source
52 """
53 if code:
54 code, modification = dict(standard_dna_code), code
55 code.update(modification)
56 else:
57 code = standard_dna_code
58 result = self.types.protein.Sequence([],
59 name=name or self.name + "_tr",
60 description=description or self.description + " translated",
61 source=source or self.source
62 )
63 seen_stop = False
64 for a, b, c in zip(self[::3], self[1::3], self[2::3]):
65 assert not seen_stop, "Stop-codon must be the last one"
66 triplet = a.code1 + b.code1 + c.code1
67 aa_name = code[triplet]
68 if aa_name == "Stop":
69 seen_stop = True
70 continue
71 result.append_monomer(name=aa_name)
72 return result
74 class Column(base.Column):
75 types = dna
77 class Alignment(base.Alignment):
78 types = dna
80 class Block(Alignment, base.Block):
81 pass
83 # vim: set ts=4 sts=4 sw=4 et: