Mercurial > repos > yufei-luo > s_mart
diff commons/tools/replaceGreaterThanSymbolInFastaHeaderProgramLauncher.py @ 18:94ab73e8a190
Uploaded
author | m-zytnicki |
---|---|
date | Mon, 29 Apr 2013 03:20:15 -0400 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/commons/tools/replaceGreaterThanSymbolInFastaHeaderProgramLauncher.py Mon Apr 29 03:20:15 2013 -0400 @@ -0,0 +1,37 @@ +#!/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()