allpy
changeset 378:dd94230c6f08
fixed bugs; usecase1.py works (see #23) (see #1)
author | boris <bnagaev@gmail.com> |
---|---|
date | Tue, 01 Feb 2011 17:11:33 +0300 |
parents | cc6209936d8a |
children | 5639138f619a |
files | allpy/base.py allpy/processors.py test/usecase1.py |
diffstat | 3 files changed, 13 insertions(+), 14 deletions(-) [+] |
line diff
1.1 --- a/allpy/base.py Tue Feb 01 00:20:24 2011 +0300 1.2 +++ b/allpy/base.py Tue Feb 01 17:11:33 2011 +0300 1.3 @@ -49,9 +49,8 @@ 1.4 """Create all relevant subclasses of Monomer.""" 1.5 # NB. The table uses letters d, r, p for types, 1.6 # while we use full words; hence, we compare by first letter 1.7 - for type, code1, is_modified, code3, name in codes: 1.8 - if type[0] == cls.type[0]: 1.9 - cls._subclass(name, code1, code3, is_modified) 1.10 + for code1, is_modified, code3, name in codes: 1.11 + cls._subclass(name, code1, code3, is_modified) 1.12 1.13 @classmethod 1.14 def from_code1(cls, code1): 1.15 @@ -107,7 +106,7 @@ 1.16 @classmethod 1.17 def from_monomers(cls, monomers=[], name=None, description=None, source=None): 1.18 """Create sequence from a list of monomer objecst.""" 1.19 - result = cls() 1.20 + result = cls(monomers) 1.21 if name: 1.22 result.name = name 1.23 if description: 1.24 @@ -194,7 +193,7 @@ 1.25 """ 1.26 assert format == 'fasta', "We don't support other formats yet" 1.27 for (name, description, body) in fasta.parse_file(file): 1.28 - self.append_row(body, name, description, file.name, gaps) 1.29 + self.append_row_from_string(body, name, description, file.name, gaps) 1.30 return self 1.31 1.32 def to_file(self, file, format='fasta'): 1.33 @@ -314,7 +313,7 @@ 1.34 def _wipe(self): 1.35 """Make all positions gaps (but keep sequences intact).""" 1.36 for column in self.columns: 1.37 - for sequence in column: 1.38 + for sequence in list(column.keys()): 1.39 del column[sequence] 1.40 1.41 def _merge(self, dst, new, merge): 1.42 @@ -358,7 +357,7 @@ 1.43 """Replace alignment contents with those of other alignment.""" 1.44 if copy_contents: 1.45 self._replace_sequence_contents(new, copy_descriptions) 1.46 - self._replace_column_conents(new) 1.47 + self._replace_column_contents(new) 1.48 1.49 def process(self, function, copy_descriptions=True, copy_contents=True): 1.50 """Apply function to the alignment (or block); inject results back.
2.1 --- a/allpy/processors.py Tue Feb 01 00:20:24 2011 +0300 2.2 +++ b/allpy/processors.py Tue Feb 01 17:11:33 2011 +0300 2.3 @@ -15,14 +15,13 @@ 2.4 self.command = command 2.5 2.6 def __call__(self, block): 2.7 - infile = NamedTemporaryFile(delete=false) 2.8 - outfile = NamedTemporaryFile('r', delete=false) 2.9 - outfile.close() 2.10 + infile = NamedTemporaryFile(delete=False) 2.11 + outfile = NamedTemporaryFile('r', delete=False) 2.12 block.to_file(infile) 2.13 infile.close() 2.14 os.system(self.command % {'infile': infile.name, 'outfile': outfile.name}) 2.15 - Alignment = block.__base__ 2.16 - new_alignment = Alignment().append_file(outfile)) 2.17 + Alignment = block.__class__ 2.18 + new_alignment = Alignment().append_file(outfile) 2.19 os.unlink(infile.name) 2.20 os.unlink(outfile.name) 2.21 return new_alignment
3.1 --- a/test/usecase1.py Tue Feb 01 00:20:24 2011 +0300 3.2 +++ b/test/usecase1.py Tue Feb 01 17:11:33 2011 +0300 3.3 @@ -1,4 +1,5 @@ 3.4 from allpy import protein 3.5 +from allpy import processors 3.6 3.7 # Create sequences from string representation of sequence body 3.8 sequence_1 = protein.Sequence.from_string("mkstf", name="E2E4") 3.9 @@ -8,7 +9,7 @@ 3.10 alignment = protein.Alignment() 3.11 alignment.append_sequence(sequence_1) 3.12 alignment.append_sequence(sequence_2) 3.13 -alignment.realign("muscle") 3.14 +alignment.process(processors.Muscle()) 3.15 3.16 # For each sequence, print number of gaps and non-gaps in alignment 3.17 for row in alignment.rows(): 3.18 @@ -32,4 +33,4 @@ 3.19 print " ".join(map(str, gaps)) 3.20 3.21 # Write alignment to file 3.22 -alignment.to_fasta(open("new_file.fasta", "w")) 3.23 +alignment.to_file(open("new_file.fasta", "w"))