Esempio n. 1
0
class AnalysisDefJob(StatJob):
    '''
    @takes(AnalysisDefJob, str, list, list, UserBinSource)
    @returns Results
    '''
    def __init__(self,
                 analysisDef,
                 trackName1,
                 trackName2,
                 userBinSource,
                 genome=None,
                 galaxyFn=None,
                 *args,
                 **kwArgs):
        from gold.description.Analysis import Analysis

        #  to be removed later.. Just for convenience with development now..
        self._analysisDef = analysisDef
        #  self._trackName1 = trackName1
        #  self._trackName2 = trackName2

        if genome is None:
            genome = userBinSource.genome

        self._galaxyFn = galaxyFn
        self._analysis = Analysis(analysisDef, genome, trackName1, trackName2)

        track, track2 = self._analysis.getTracks()
        statistic = self._analysis.getStat()
        self._analysis.initRandomUtilAndUpdateSeedIfNeeded()

        StatJob.__init__(self, userBinSource, track, track2, statistic, *args,
                         **kwArgs)

    def run(self, printProgress=PRINT_PROGRESS):
        '''
        Runs the statistic specified in self._analysis (from analysisDef) and returns an object of class Result
        
        '''
        #Should be there for batch runs.. Should never happen from GUI..
        if self._statClass == None:
            self._handleMissingStat()
            return None

        if DebugConfig.USE_PROFILING:
            from gold.util.Profiler import Profiler
            profiler = Profiler()
            resDict = {}
            profiler.run(
                'resDict[0] = StatJob.run(self, printProgress=printProgress)',
                globals(), locals())
            res = resDict[0]
        else:
            res = StatJob.run(self, printProgress=printProgress)

        res.updateFromAnalysis(self._analysis)

        # ResultsMemoizer.flushStoredResults()

        if DebugConfig.USE_PROFILING:
            profiler.printStats()
            if DebugConfig.USE_CALLGRAPH and self._galaxyFn:
                profiler.printLinkToCallGraph(['profile_AnalysisDefJob'],
                                              self._galaxyFn)

        return res

    def _handleMissingStat(self):
        from gold.application.LogSetup import logMessage, logging
        from gold.description.RunDescription import RunDescription
        import gold.description.Analysis as AnalysisModule
        #AnalysisModule.VERBOSE = True
        msg = 'Started run with invalid statistic... Def: ' + self._analysisDef
        #+ ', Run description: ' + \
        #RunDescription.getRevEngBatchLine( self._trackName1, self._trackName2, self._analysisDef, \
        #'Not Available', 'Not Available', self._userBinSource.genome)
        logMessage(msg, level=logging.ERROR)
        raise Exception(msg)