view commons/tools/replaceGreaterThanSymbolInFastaHeaderProgramLauncher.py @ 31:0ab839023fe4

Uploaded
author m-zytnicki
date Tue, 30 Apr 2013 14:33:21 -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()