view allpy/protein.py @ 373:166806efc570
base.Alignment.process: added parameters to control what to copy
also, cleaned up code
author |
Daniil Alexeyevsky <me.dendik@gmail.com> |
date |
Mon, 31 Jan 2011 19:12:05 +0300 |
parents |
0411fa851bba |
children |
5639138f619a |
line source
4 class Monomer(base.Monomer):
5 """Protein monomers: aminoacids."""
10 Monomer._initialize(data.codes.protein)
13 """User defined protein; list of protein_sequences."""
16 class Sequence(base.Sequence):
17 monomer_type = Monomer
19 class Alignment(base.Alignment):
20 sequence_type = Sequence
22 def muscle_align(self):
23 """ Simple align ths alignment using sequences (muscle)
25 uses old Monomers and Sequences objects
27 tmp_file = NamedTemporaryFile(delete=False)
28 self.save_fasta(tmp_file)
30 os.system("muscle -in %(tmp)s -out %(tmp)s" % {'tmp': tmp_file.name})
31 sequences, body = Alignment.from_file(open(tmp_file.name))
32 for sequence in self.sequences:
34 new_sequence = [i for i in sequences if sequence==i][0]
36 raise Exception("Align: Cann't find sequence %s in muscle output" % \
38 old_monomers = iter(sequence.monomers)
39 self.body[sequence] = []
40 for monomer in body[new_sequence]:
42 self.body[sequence].append(monomer)
44 old_monomer = old_monomers.next()
45 if monomer != old_monomer:
46 raise Exception("Align: alignment errors")
47 self.body[sequence].append(old_monomer)
48 os.unlink(tmp_file.name)
50 class Block(Alignment, base.Block):
53 # vim: set ts=4 sts=4 sw=4 et: