view 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 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()