Mercurial > repos > yufei-luo > s_mart
view commons/tools/replaceGreaterThanSymbolInFastaHeaderProgramLauncher.py @ 19:9bcfa7936eec
Deleted selected files
author | m-zytnicki |
---|---|
date | Mon, 29 Apr 2013 03:23:29 -0400 |
parents | 94ab73e8a190 |
children |
line wrap: on
line source
#!/usr/bin/env python import re from commons.pyRepetUnit.components.AbstractProgramLauncher import AbstractProgramLauncher class replaceGreaterThanSymbolInFastaHeaderProgramLauncher(AbstractProgramLauncher): def __init__( self ): AbstractProgramLauncher.__init__( self ) self._formatInFile = "fasta" def run( self ): self.checkInput() fastaHandler = open(self.getInputFile(), "r") lines = fastaHandler.readlines() fastaHandler.close() newFastaName = ".".join([self.getInputFile().split(".")[0], "preprocessed", "fasta"]) self._writePreprocessedFastaFile(lines, newFastaName) def _writePreprocessedFastaFile(self, lines, newFastaName): newFastaHandler = open(newFastaName, "w") for line in lines: if re.match(">", line): newLine = re.sub("-->|->", " to ", line) newFastaHandler.write(newLine) else: newFastaHandler.write(line) newFastaHandler.close() if __name__ == "__main__": i = replaceGreaterThanSymbolInFastaHeaderProgramLauncher() i.checkAttributesFromCmdLine() i.run()