Mercurial > repos > yufei-luo > s_mart
comparison commons/tools/replaceGreaterThanSymbolInFastaHeaderProgramLauncher.py @ 18:94ab73e8a190
Uploaded
| author | m-zytnicki |
|---|---|
| date | Mon, 29 Apr 2013 03:20:15 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 17:b0e8584489e6 | 18:94ab73e8a190 |
|---|---|
| 1 #!/usr/bin/env python | |
| 2 | |
| 3 import re | |
| 4 from commons.pyRepetUnit.components.AbstractProgramLauncher import AbstractProgramLauncher | |
| 5 | |
| 6 class replaceGreaterThanSymbolInFastaHeaderProgramLauncher(AbstractProgramLauncher): | |
| 7 | |
| 8 def __init__( self ): | |
| 9 AbstractProgramLauncher.__init__( self ) | |
| 10 self._formatInFile = "fasta" | |
| 11 | |
| 12 def run( self ): | |
| 13 self.checkInput() | |
| 14 fastaHandler = open(self.getInputFile(), "r") | |
| 15 lines = fastaHandler.readlines() | |
| 16 fastaHandler.close() | |
| 17 newFastaName = ".".join([self.getInputFile().split(".")[0], "preprocessed", "fasta"]) | |
| 18 | |
| 19 self._writePreprocessedFastaFile(lines, newFastaName) | |
| 20 | |
| 21 def _writePreprocessedFastaFile(self, lines, newFastaName): | |
| 22 newFastaHandler = open(newFastaName, "w") | |
| 23 for line in lines: | |
| 24 if re.match(">", line): | |
| 25 newLine = re.sub("-->|->", " to ", line) | |
| 26 newFastaHandler.write(newLine) | |
| 27 else: | |
| 28 newFastaHandler.write(line) | |
| 29 newFastaHandler.close() | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 if __name__ == "__main__": | |
| 35 i = replaceGreaterThanSymbolInFastaHeaderProgramLauncher() | |
| 36 i.checkAttributesFromCmdLine() | |
| 37 i.run() |
