comparison commons/tools/removeDescriptionInFastaHeaderProgramLauncher.py @ 31:0ab839023fe4

Uploaded
author m-zytnicki
date Tue, 30 Apr 2013 14:33:21 -0400
parents 94ab73e8a190
children
comparison
equal deleted inserted replaced
30:5677346472b5 31:0ab839023fe4
1 #!/usr/bin/env python
2
3 import re
4 from commons.pyRepetUnit.components.AbstractProgramLauncher import AbstractProgramLauncher
5
6 class removeDescriptionInFastaHeaderProgramLauncher(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 = line.split(" ",1)[0] + "\n"
26 newFastaHandler.write(newLine)
27 else:
28 newFastaHandler.write(line)
29 newFastaHandler.close()
30
31
32
33
34 if __name__ == "__main__":
35 i = removeDescriptionInFastaHeaderProgramLauncher()
36 i.checkAttributesFromCmdLine()
37 i.run()