view commons/launcher/YassClusterLauncher.py @ 19:9bcfa7936eec

Deleted selected files
author m-zytnicki
date Mon, 29 Apr 2013 03:23:29 -0400
parents 94ab73e8a190
children
line wrap: on
line source

#!/usr/bin/env python

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


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


class YassClusterLauncher( AbstractClusterLauncher ):
    """
    Launch Yass on several files in parallel on a cluster.
    """
    
    def __init__( self ):
        """
        Constructor.
        """
        AbstractClusterLauncher.__init__( self )
        AbstractClusterLauncher.setAcronym( self, "Yass" )
        
        self._cmdLineSpecificOptions = "s:p:A"
        
        self._exeWrapper = "YassProgramLauncher.py"
        self._prgLauncher = None
        self._prgLauncher = self.getProgramLauncherInstance()
        
        
    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 'yass'"
        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 getProgramLauncherInstance( self ):
        if self._prgLauncher == None:
            self._prgLauncher = YassProgramLauncher()
            self._prgLauncher.setInputFile( GENERIC_IN_FILE )
            self._prgLauncher.setClean()
            self._prgLauncher.setVerbosityLevel( 1 )
            self._prgLauncher.setListFilesToKeep()
            self._prgLauncher.setListFilesToRemove()
        return self._prgLauncher
    
    
    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 )
            
            
if __name__ == "__main__":
    i = YassClusterLauncher()
    i.setAttributesFromCmdLine()
    i.run()