Mercurial > repos > yufei-luo > s_mart
diff commons/tools/removeDescriptionInFastaHeaderProgramLauncher.py @ 31:0ab839023fe4
Uploaded
| author | m-zytnicki |
|---|---|
| date | Tue, 30 Apr 2013 14:33:21 -0400 |
| parents | 94ab73e8a190 |
| children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/commons/tools/removeDescriptionInFastaHeaderProgramLauncher.py Tue Apr 30 14:33:21 2013 -0400 @@ -0,0 +1,37 @@ +#!/usr/bin/env python + +import re +from commons.pyRepetUnit.components.AbstractProgramLauncher import AbstractProgramLauncher + +class removeDescriptionInFastaHeaderProgramLauncher(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 = line.split(" ",1)[0] + "\n" + newFastaHandler.write(newLine) + else: + newFastaHandler.write(line) + newFastaHandler.close() + + + + +if __name__ == "__main__": + i = removeDescriptionInFastaHeaderProgramLauncher() + i.checkAttributesFromCmdLine() + i.run()
