Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/allpy/file/696d314ad718/allpy/protein.py
Дата изменения: Unknown
Дата индексирования: Mon Feb 4 04:29:26 2013
Кодировка:
allpy: 696d314ad718 allpy/protein.py

allpy

view allpy/protein.py @ 322:696d314ad718

Added to base.Monomer missing properties: code1, code3, name, is_modified
author Daniil Alexeyevsky <me.dendik@gmail.com>
date Fri, 17 Dec 2010 00:35:31 +0300
parents be9c3cacd009
children e3bcb9f8d7b0
line source
1 import base
3 class MonomerType(base.MonomerType):
4 by_code1 = {}
5 by_code3 = {}
6 by_name = {}
8 class Monomer(base.Monomer):
9 """Protein monomers: aminoacids."""
10 monomer_type = MonomerType
12 MonomerType._initialize('p')
13 MonomerType.instance_type = Monomer
15 class Protein(list):
16 """User defined protein; list of protein_sequences."""
17 pass
19 class Sequence(base.Sequence):
20 monomer_type = Monomer
22 class Alignment(base.Alignment):
23 sequence_type = Sequence
25 def muscle_align(self):
26 """ Simple align ths alignment using sequences (muscle)
28 uses old Monomers and Sequences objects
29 """
30 tmp_file = NamedTemporaryFile(delete=False)
31 self.save_fasta(tmp_file)
32 tmp_file.close()
33 os.system("muscle -in %(tmp)s -out %(tmp)s" % {'tmp': tmp_file.name})
34 sequences, body = Alignment.from_fasta(open(tmp_file.name))
35 for sequence in self.sequences:
36 try:
37 new_sequence = [i for i in sequences if sequence==i][0]
38 except:
39 raise Exception("Align: Cann't find sequence %s in muscle output" % \
40 sequence.name)
41 old_monomers = iter(sequence.monomers)
42 self.body[sequence] = []
43 for monomer in body[new_sequence]:
44 if not monomer:
45 self.body[sequence].append(monomer)
46 else:
47 old_monomer = old_monomers.next()
48 if monomer != old_monomer:
49 raise Exception("Align: alignment errors")
50 self.body[sequence].append(old_monomer)
51 os.unlink(tmp_file.name)
53 class Block(Alignment, base.Block):
54 pass
56 # vim: set ts=4 sts=4 sw=4 et: