view commons/launcher/BlatClusterLauncher.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

##@file
# Launch BlatProgramLauncher on several files in parallel on a cluster.


from pyRepet.launcher.AbstractClusterLauncher import *
from commons.launcher.BlatProgramLauncher import BlatProgramLauncher
from commons.core.coord.AlignUtils import AlignUtils
from commons.tools import srptBlasterMatcher


class BlatClusterLauncher( AbstractClusterLauncher ):
    """
    Launch Blat on several files in parallel on a cluster.
    """
    
    def __init__( self ):
        """
        Constructor.
        """
        AbstractClusterLauncher.__init__( self )
        AbstractClusterLauncher.setAcronym( self, "Blat" )
        
        self._cmdLineSpecificOptions = "s:p:A"
        
        self._exeWrapper = "BlatProgramLauncher.py"
        self._prgLauncher = BlatProgramLauncher()
        self._prgLauncher.setInputFile( GENERIC_IN_FILE )
        self._prgLauncher.setClean()
        self._prgLauncher.setVerbosityLevel( 1 )
        self._prgLauncher.setListFilesToKeep()
        self._prgLauncher.setListFilesToRemove()
        
        
    def getSpecificHelpAsString( self ):
        """
        Return the specific help as a string.
        """
        string = ""
        string += "\nspecific options:"
        string += "\n     -s: name of the subject file (format='fasta')"
        string += "\n     -p: parameters for '%s'" % ( self._prgLauncher.getProgramName() )
        string += "\n     -Z: concatenate output files"
        string += "\n     -A: same sequences (all-by-all)"
        return string
    
    
    def getSubjectFile( self ):
        return self._prgLauncher.getSubjectFile()
    
    
    def getProgramParameters( self ):
        return self._prgLauncher.getProgramParameters()
    
    
    def processOutputFile( self, tmpFile, outFile ):
        sortFile = "%s.sort" % ( tmpFile )
        AlignUtils.sortAlignFile( tmpFile, sortFile )
        if self._prgLauncher.getAllByAll():
            srptBlasterMatcher.filterRedundantMatches( sortFile,
                                                                  outFile )
            os.remove( sortFile )
        else:
            os.rename( sortFile, outFile )
            
    def setASpecificAttributeFromCmdLine( self, o, a="" ):
        if o =="-s":
            self._prgLauncher.setSubjectFile( a )
            
if __name__ == "__main__":
    i = BlatClusterLauncher()
    i.setAttributesFromCmdLine()
    i.run()