allpy
changeset 376:2f8f56f22691
Implemented base processor for realignments (see #23)
Base processor ExternalCommand applies external command to block.
Base processor saves block as fasta, runs external command
and reads it from fasta
author | boris <bnagaev@gmail.com> |
---|---|
date | Mon, 31 Jan 2011 23:39:26 +0300 |
parents | 43f8a6dc40a8 |
children | cc6209936d8a |
files | allpy/processors.py |
diffstat | 1 files changed, 15 insertions(+), 1 deletions(-) [+] |
line diff
1.1 --- a/allpy/processors.py Mon Jan 31 20:42:42 2011 +0300 1.2 +++ b/allpy/processors.py Mon Jan 31 23:39:26 2011 +0300 1.3 @@ -1,6 +1,11 @@ 1.4 """Processors for Alignment.process and Block.process. 1.5 """ 1.6 1.7 +import os 1.8 +from tempfile import NamedTemporaryFile 1.9 + 1.10 +import base 1.11 + 1.12 class ExternalCommand(object): 1.13 """Use external command to process block. 1.14 1.15 @@ -9,9 +14,18 @@ 1.16 """ 1.17 1.18 def __init__(self, command): 1.19 - pass 1.20 + self.command = command 1.21 1.22 def __call__(self, block): 1.23 + infile = NamedTemporaryFile(delete=false) 1.24 + outfile = NamedTemporaryFile('r', delete=false) 1.25 + outfile.close() 1.26 + block.to_file(infile) 1.27 + infile.close() 1.28 + os.system(self.command % {'infile': infile.name, 'outfile': outfile.name}) 1.29 + new_block = base.Block.from_file(outfile) 1.30 + os.unlink(infile.name) 1.31 + os.unlink(outfile.name) 1.32 return new_block 1.33 1.34 class Muscle(ExternalCommand):