コード例 #1
0
    def _getTrackView(self, region):
        from gold.util.RandomUtil import random

        #if not hasattr(self, '_minimalRegion'):
        #    from quick.application.UserBinSource import MinimalBinSource
        #    minimalBinList = MinimalBinSource(region.genome)
        #    self._minimalRegion = minimalBinList[0] if minimalBinList is not None else None
        #
        #if  self._minimalRegion == region:
        #    return self._origTrack.getTrackView(region)

        allChrArmRegs = GenomeInfo.getContainingChrArms(region)
        if len(allChrArmRegs) != 1:
            raise CentromerError
        chrArm = allChrArmRegs[0]

        buffer = self._getIndependencyBufferSize(region)
        sourceRegs = chrArm.exclude(
            region.getCopy().extend(-buffer).extend(buffer))
        assert len(sourceRegs) in [
            1, 2
        ], "Source region must be smaller than a tenth of a chromosome arm: %s" % region

        if not any(
                len(sourceReg) >= self.MIN_SOURCE_TO_SAMPLE_SIZE_RATIO *
                len(region) for sourceReg in sourceRegs):
            raise TooLargeBinError(
                'Source region lengths of ' + str([len(x)
                                                   for x in sourceRegs]) +
                ' are too small compared to region length of ' +
                str(len(region)) +
                ' according to MIN_SOURCE_TO_SAMPLE_SIZE_RATIO: ' +
                str(self.MIN_SOURCE_TO_SAMPLE_SIZE_RATIO))

        if len(sourceRegs) == 1:
            sourceReg = sourceRegs[0]
        else:
            firstSourceProportion = (len(sourceRegs[0]) - len(region)) / sum(
                len(sourceRegs[i]) - len(region) for i in range(2))
            sourceReg = sourceRegs[0] if random.random(
            ) < firstSourceProportion else sourceRegs[1]

        randOffset = random.randint(0, len(sourceReg) - len(region))
        start = sourceReg.start + randOffset
        end = start + len(region)
        randRegion = GenomeRegion(region.genome, region.chr, start, end)

        #rawData = RawDataStat(randRegion, self._origTrack, self._trackFormatReq)
        #tv = rawData.getResult()
        tv = self._origTrack.getTrackView(randRegion)
        assert tv.genomeAnchor != region, (region, tv.genomeAnchor,
                                           getClassName(region),
                                           getClassName(tv.genomeAnchor))
        return tv
コード例 #2
0
ファイル: Analysis.py プロジェクト: Anderrb/Dynamic-benchmark
 def _appendConverterOptions(self, track, labelKey):
     if track is None:
         return
     
     if self.getChoice(labelKey) is not None:
         assert(self.getChoice(labelKey) == getClassName(track.formatConverters[0]))
         return
     
     labelPair = (labelKey, '_Treat ' + prettyPrintTrackName(track.trackName) + ' as')
     choicePairs = [ ( getClassName(fc), fc.getOutputDescription(TrackInfo(self._genome, track.trackName).trackFormatName) ) \
                     for fc in track.formatConverters ]
     
     text = '[' + ':'.join(labelPair) + '=' + '/'.join( [':'.join(x) for x in choicePairs] ) + ']'
     self._analysisParts.append(AnalysisOption( text ))
コード例 #3
0
    def computeStep(self):
        self._trace('computeStep')

        if not self.hasResult():
            self._loadMemoizedResult()

        if self.hasResult():
            return
        for child in self._children:
            if not child.hasResult():
                child.computeStep()

        if not all([child.hasResult() for child in self._children]):
            return

        self._trace('_compute')
        #The method _compute may either return the result, or set the result variable directly:
        res = None
        with StatisticExceptionHandling(**self._kwArgs):
            res = self._compute()
            if DebugConfig.VERBOSE:
                logMessage('Result of statistic %s in region %s: %s' % (getClassName(self), self._region, res))

        if not self.hasResult():
            #Only set _result if this was not set directly by the previous call to _compute
            self._result = res

        self._storeMemoizedResult()
コード例 #4
0
    def _writeContent(self, resDictKey, fn):
        ensurePathExists(fn)
        arbitraryTV = self._results.getArbitraryLocalResult()['Result']

        assert isinstance(arbitraryTV, TrackView)
        #assert arbitraryTV.trackFormat.getFormatName() in [ 'Valued segments', 'Segments'], arbitraryTV.trackFormat.getFormatName()
        genome = arbitraryTV.genomeAnchor.genome
        #print 'GENOME: ',genome
        from gold.util.CommonFunctions import getClassName
        print type([
            self._results[key]['Result']
            for key in sorted(self._results.keys())
        ][0]), getClassName([
            self._results[key]['Result']
            for key in sorted(self._results.keys())
        ][0])
        tvGeSource = TrackViewListGenomeElementSource(
            genome, [
                self._results[key]['Result']
                for key in sorted(self._results.keys())
            ], 'Private:GK:test1:wgEncodeUchicagoTfbsK562EfosControlPk'.split(
                ':'))
        if arbitraryTV.trackFormat.getFormatName() in ['Segments']:
            BedComposer(tvGeSource).composeToFile(fn)
        else:
            StdGtrackComposer(tvGeSource).composeToFile(fn)
コード例 #5
0
    def computeStep(self):
#        if self.hasResult():
#            return

        self._trace('computeStep')
        try:
            try:
                if not self._curChild.hasResult():
                    self._curChild.computeStep()
                if not self._curChild.hasResult():
                    return
                nextRes = self._curChild.getResult()

                if DebugConfig.VERBOSE:
                    logMessage('Result of statistic %s in region %s: %s' % (getClassName(self._curChild), self._curChild._region, nextRes))

            # except NoneResultError, e:
            except (CentromerError, NoneResultError), e:
                nextRes = None
                if DebugConfig.VERBOSE:
                    logException(e, level=logging.DEBUG)
                if DebugConfig.PASS_ON_NONERESULT_EXCEPTIONS:
                    raise

            self._childResults.append(nextRes)
            tempRefHolderChild = self._curChild # To avoid children of this _curChild to be collected in the next line.
                                                # It will live long enough for createChildren to be called on new _curChild
            self._curChild.afterComputeCleanup() # In case a global analysis was run without prior local analyses
            self._curChild = None #first sets curchild to None to free memory even when self._bins.next() raises StopIteration..
            self._curChild = self._getChildObject(self._bins.next())

            self._curChild.createChildren()
コード例 #6
0
    def _createMemoItems(cls, stat, useTrackFormatAsKey=True):
        from gold.description.TrackInfo import TrackInfo

        genome = stat.getGenome()

        statId = getClassName(stat) + '_' + stat.VERSION
        configHash = stat.getConfigKey(ignoreUsername=False)

        trackHashList = []
        tracks = [stat._track]
        if hasattr(stat, '_track2') and stat._track2 is not None:
            tracks.append(stat._track2)
        for track in tracks:
            if useTrackFormatAsKey and not cls._isRandomizedTrack(track):
                trackFormatHash = TrackInfo(genome,
                                            track.trackName).trackFormatHash
                if not trackFormatHash:
                    raise MissingInfoError(
                        'Precalculated TrackFormat hash is missing from TrackInfo, '
                        'for track "{}" of genome "{}". '.format(
                            track.trackName, genome) +
                        'Please consider to repeat the preprocessing step.')
                trackHashList.append(trackFormatHash)
            else:
                trackHashList.append(track.getUniqueKey(genome))
        return [stat._region, statId, configHash] + trackHashList
コード例 #7
0
    def getTrackView(self, region):
        allowOverlaps = self._trackFormatReq.allowOverlaps()
        borderHandling = self._trackFormatReq.borderHandling()
        assert (allowOverlaps is not None)
        assert (borderHandling is not None)

        origTrackView = self._getRawTrackView(region, borderHandling,
                                              allowOverlaps)

        if self.formatConverters is None:
            self.formatConverters = getFormatConverters(
                origTrackView.trackFormat, self._trackFormatReq)

        if self.formatConverters == []:
            raise IncompatibleTracksError(prettyPrintTrackName(self.trackName) + ' with format: '\
                                          + str(origTrackView.trackFormat) +
                                          ('(' + origTrackView.trackFormat._val + ')' if origTrackView.trackFormat._val else '') + \
                                          ' does not satisfy ' + str(self._trackFormatReq))

        if not self.formatConverters[0].canHandle(origTrackView.trackFormat,
                                                  self._trackFormatReq):
            raise IncompatibleTracksError(getClassName(self.formatConverters[0]) +\
                                          ' does not support conversion from ' + str(origTrackView.trackFormat) + \
                                          ' to ' + str(self._trackFormatReq))
        return self.formatConverters[0].convert(origTrackView)
コード例 #8
0
    def _getChildObject(self, bin):
        childName = getClassName(self).replace('Splittable','')
        try:
            module = __import__('.'.join(['gold','statistic',childName]),globals(), locals(), [childName])
        except:
            module = __import__('.'.join(['quick','statistic',childName]),globals(), locals(), [childName])

        return getattr(module, childName)(bin, self._track, *self._args, **self._kwArgs)
コード例 #9
0
 def _getChildObject(self, bin):
     childName = getClassName(self).replace('Splittable','')
     try:
         module = __import__('.'.join(['gold','statistic',childName]),globals(), locals(), [childName])
     except:
         module = __import__('.'.join(['quick','statistic',childName]),globals(), locals(), [childName])
     
     return getattr(module, childName)(bin, self._track, *self._args, **self._kwArgs)
コード例 #10
0
    def _appendConverterOptions(self, track, labelKey):
        if track is None:
            return

        if track.formatConverters is None:
            # May happen in the second track object if one analyses a track versus itself
            return
        
        if self.getChoice(labelKey) is not None:
            assert(self.getChoice(labelKey) == getClassName(track.formatConverters[0]))
            return
        
        labelPair = (labelKey, '_Treat ' + prettyPrintTrackName(track.trackName) + ' as')
        choicePairs = [ ( getClassName(fc), fc.getOutputDescription(TrackInfo(self._genome, track.trackName).trackFormatName) ) \
                        for fc in track.formatConverters ]
        
        text = '[' + ':'.join(labelPair) + '=' + '/'.join( [':'.join(x) for x in choicePairs] ) + ']'
        self._analysisParts.append(AnalysisOption( text ))
コード例 #11
0
 def _createMemoPath(cls, stat):
     genome = stat._region.genome
     #combTrackName = stat._track.trackName + (stat._track2.trackName if hasattr(stat,'_track2') else [])
     statId = getClassName(stat) + '_' + stat.VERSION
     configHash = stat.getConfigKey()
     track1Hash = stat._track.getUniqueKey(genome)
     track2Hash = (stat._track2.getUniqueKey(genome) if hasattr(stat,'_track2') else None)
     #basePath = os.sep.join([MEMOIZED_DATA_PATH, getClassName(stat)])
     return createMemoPath(stat._region, statId, configHash, track1Hash, track2Hash)
コード例 #12
0
    def getPreProcessedTrackFromGalaxyTN(cls,
                                         genome,
                                         galaxyTN,
                                         printErrors=True,
                                         printProgress=True,
                                         raiseIfAnyWarnings=False,
                                         renameExistingTracksIfNeeded=True,
                                         mergeChrFolders=True,
                                         doEncodeId=True,
                                         urlPrefix=None):
        '''
        Takes a GalaxyTN as input, pre-processes the data that GalaxyTN refers to, and finally returns
        an ExternalTN that refers to the pre-processed data and can be used as a normal track name.
        '''
        from gold.util.CommonFunctions import replaceIllegalElementsInTrackNames
        stdTrackName = cls.getStdTrackNameFromGalaxyTN(
            galaxyTN,
            allowUnsupportedSuffixes=True,
            doEncodeId=doEncodeId,
            urlPrefix=urlPrefix)
        legalTrackName = [
            replaceIllegalElementsInTrackNames(part) for part in stdTrackName
        ]

        if renameExistingTracksIfNeeded:
            cls.renameExistingStdTrackIfNeeded(genome, legalTrackName)
        fn = cls.extractFnFromGalaxyTN(galaxyTN)
        fileSuffix = cls.extractFileSuffixFromGalaxyTN(
            galaxyTN, allowUnsupportedSuffixes=True)

        if printProgress:
            print 'Preprocessing external track...<br><pre>'

        try:
            if cls.preProcess(fn,
                              legalTrackName,
                              fileSuffix,
                              genome,
                              printProgress=printProgress,
                              raiseIfAnyWarnings=raiseIfAnyWarnings,
                              mergeChrFolders=mergeChrFolders):
                if printProgress:
                    print '</pre>Finished preprocessing.<br>'
            else:
                if printProgress:
                    print '</pre>Already preprocessed, continuing...<br>'
        #except IOError:
        #    print '</pre>Already preprocessed, continuing...<br>'
        except Exception as e:
            if printErrors:
                print '</pre>An error occured during preprocessing: ', getClassName(
                    e) + ':', e, '<br>'
            raise
        #else:
        #    print '</pre>Finished preprocessing.<br>'
        return legalTrackName
コード例 #13
0
ファイル: Track.py プロジェクト: uio-bmi/track_rand
    def getUniqueKey(self, genome):
        if not self._trackId:
            self._trackId = TrackInfo(genome, self.trackName).id

        return hash((tuple(self.trackName),
                     self._trackId if self._trackId else '',
                     getClassName(self.formatConverters[0]) if self.formatConverters else '',
                     self.formatConverters[0].VERSION if self.formatConverters else '',
                     self._trackFormatReq.allowOverlaps() if self._trackFormatReq.allowOverlaps() else '',
                     self._trackFormatReq.borderHandling() if self._trackFormatReq.borderHandling() else ''))
コード例 #14
0
 def _createMemoPath(cls, stat):
     genome = stat._region.genome
     #combTrackName = stat._track.trackName + (stat._track2.trackName if hasattr(stat,'_track2') else [])
     statId = getClassName(stat) + '_' + stat.VERSION
     configHash = stat.getConfigKey()
     track1Hash = stat._track.getUniqueKey(genome)
     track2Hash = (stat._track2.getUniqueKey(genome) if hasattr(
         stat, '_track2') else None)
     #basePath = os.sep.join([MEMOIZED_DATA_PATH, getClassName(stat)])
     return createMemoPath(stat._region, statId, configHash, track1Hash,
                           track2Hash)
コード例 #15
0
ファイル: Track.py プロジェクト: Anderrb/Dynamic-benchmark
 def getUniqueKey(self, genome):
     assert self.formatConverters is not None and len(self.formatConverters) == 1, 'FC: '+str(self.formatConverters)
     assert( not None in [self._trackFormatReq.allowOverlaps(), \
                          self._trackFormatReq.borderHandling()] )
     
     if not self._trackId:
         self._trackId = TrackInfo(genome, self.trackName).id
         
     return hash((tuple(self.trackName), self._trackId, getClassName(self.formatConverters[0]), \
                  self.formatConverters[0].VERSION, self._trackFormatReq.allowOverlaps(), \
                  self._trackFormatReq.borderHandling()))
コード例 #16
0
class StatJobV2(StatJob):
    def __init__(self, userBinSource, trackStructure, statClass, *args,
                 **kwArgs):
        StatJob.USER_BIN_SOURCE = userBinSource
        #if 'userBins' in kwArgs:
        #    logMessage('key "userBins" already found in kwArgs in StatJob.__init__')
        #else:
        #    kwArgs['userBins'] = userBinSource
        self._userBinSource = userBinSource
        self._trackStructure = trackStructure
        self._statClass = statClass
        self._args = args
        self._kwArgs = kwArgs

        self._numUserBins = None

    @property
    def _track(self):
        if TrackStructure.QUERY_KEY not in self._trackStructure\
        or not self._trackStructure.getQueryTrackList():
            raise ShouldNotOccurError(
                'Track structure must contain a query list of at least one track'
            )
        return self._trackStructure.getQueryTrackList()[0]

    @property
    def _track2(self):
        if TrackStructure.REF_KEY in self._trackStructure\
        and self._trackStructure.getReferenceTrackList():
            return self._trackStructure.getReferenceTrackList()[0]

        return None

#     def _emptyResults(self):

    def _getSingleResult(self, region):
        stat = self._statClass(region, self._trackStructure, *self._args,
                               **self._kwArgs)
        try:
            res = stat.getResult()
        except (CentromerError, NoneResultError), e:
            res = None
            if DebugConfig.PASS_ON_NONERESULT_EXCEPTIONS:
                raise

        #if not isinstance(res, dict):
        if not getClassName(res) in ['dict', 'OrderedDict']:
            res = {} if res is None else {self.GENERAL_RESDICTKEY: res}
            #res = {self.GENERAL_RESDICTKEY : res}

        ResultsMemoizer.flushStoredResults()
        return res, stat
コード例 #17
0
    def getDescription(self):
        import gold.description.StatDescriptionList as StatDescrModule
        statClassName = getClassName(self).replace('Unsplittable','')
        #statClassName = cls.__name__

        if statClassName == 'RandomizationManagerStat':
            assert hasattr(self, 'getRawStatisticMainClassName')
            statClassName += '_' + self.getRawStatisticMainClassName()

        if not statClassName in vars(StatDescrModule):
            return 'No description available.'
        assert type(vars(StatDescrModule)[statClassName]) is str
        return vars(StatDescrModule)[statClassName]
コード例 #18
0
    def storeMinimalResult(cls, stat):
        if stat.resultLoadedFromDisk():
            return

        if cls._shouldUseDiskMemoizationForMinimalRuns(stat):
            formatConverters = [[
                getClassName(converter) for converter in track.formatConverters
            ] if track.formatConverters else track.formatConverters
                                for track in stat.getAllTracks()]
            cls._storeMinimalMemoResult(
                stat,
                MinimalMemoResult(result=stat._result,
                                  formatConverters=formatConverters))
コード例 #19
0
    def _createMinimalMemoPath(cls, pathItems):
        return os.path.join(*(list(os.path.split(MEMOIZED_DATA_PATH)) +
                              pathItems))

        if cls._shouldUseDiskMemoizationForMinimalRuns(stat):
            formatConverters = [[
                getClassName(converter) for converter in track.formatConverters
            ] if track.formatConverters else track.formatConverters
                                for track in stat.getAllTracks()]
            cls._storeMinimalMemoResult(
                stat,
                MinimalMemoResult(result=stat._result,
                                  formatConverters=formatConverters))
コード例 #20
0
    def getDescription(self):
        import gold.description.StatDescriptionList as StatDescrModule
        statClassName = getClassName(self).replace('Unsplittable','')
        #statClassName = cls.__name__

        if statClassName == 'RandomizationManagerStat':
            assert hasattr(self, 'getRawStatisticMainClassName')
            statClassName += '_' + self.getRawStatisticMainClassName()
            
        if not statClassName in vars(StatDescrModule):
            return 'No description available.'
        assert type(vars(StatDescrModule)[statClassName]) is str
        return vars(StatDescrModule)[statClassName]
コード例 #21
0
    def computeStep(self):
        self._trace('computeStep')

        if not self.hasResult():
            self._loadMemoized()
        if self.hasResult():
            return
        for child in self._children:
            if not child.hasResult():
                child.computeStep()

        if not all([child.hasResult() for child in self._children]):
            return

        self._trace('_compute')
        #The method _compute may either return the result, or set the result variable directly:
        res = None
        with StatisticExceptionHandling(**self._kwArgs):
            res = self._compute()
            # import os
            # import psutil
            # process = psutil.Process(os.getpid())
            # print process.memory_info().rss
            if DebugConfig.VERBOSE:
                logMessage('Result of statistic %s in region %s: %s' %
                           (getClassName(self), self._region, res))

        #try:
        #    self._trace('_compute')
        #    #The method _compute may either return the result, or set the result variable directly:
        #    res = self._compute()
        #
        #except (TooLargeBinError, TooSmallBinError, CentromerError),e:
        #    logException(e)
        #    raise
        #except (ZeroDivisionError, FloatingPointError, TypeError, ValueError),e:
        #    #print 'Error: ', e.__class__.__name__, e
        #    res = None
        #    if DebugConfig.VERBOSE or e.__class__ in [TypeError, ValueError]:
        #        logException(e, message='kwArgs: ' + str(self._kwArgs))
        #    if DebugConfig.PASS_ON_COMPUTE_EXCEPTIONS:
        #        raise

        if not self.hasResult():
            #Only set _result if this was not set directly by the previous call to _compute
            self._result = res

        self._storeResult()
コード例 #22
0
 def _compute(self):
     from collections import OrderedDict
     #res = {}
     res = OrderedDict()
     for childStat in self._children:
         childRes = childStat.getResult()
         #print '1',str(self._region), str(childRes)
         if not isinstance(childRes, dict):
             childRes = {getClassName(childStat).replace('Unsplittable','').replace('Splittable',''):childRes}
         #print '2',str(self._region), str(childRes)
         for key in childRes:
             assert not key in res
             res[key] = childRes[key]
         #print '3',str(self._region), str(res)
         #res.update(  childRes)
     return res
コード例 #23
0
    def _getSingleResult(self, region):
        #print 'Kw Here: ', self._kwArgs, 'args here: ', self._args
        
        stat = self._statClass(region, self._trackStructure, *self._args, **self._kwArgs)
        try:
            res = stat.getResult()
        except (CentromerError, NoneResultError):
            res = None
            if DebugConfig.PASS_ON_NONERESULT_EXCEPTIONS:  # @UndefinedVariable
                raise
            
        #if not isinstance(res, dict):
        if not getClassName(res) in ['dict', 'OrderedDict']:
            res = {} if res is None else {self.GENERAL_RESDICTKEY : res}
            #res = {self.GENERAL_RESDICTKEY : res}

        ResultsMemoizer.flushStoredResults()
        return res, stat
コード例 #24
0
ファイル: ResultsViewer.py プロジェクト: uio-bmi/track_rand
    def _generateErrorText(self, coreCls):
        allErrors = self._results.getAllErrors()
        if len(allErrors) == 0:
            return ''

        core = coreCls()
        for exception in self._results.getAllErrors():
            if isinstance(exception, InvalidRunSpecException):
                self._errorBox(
                    core,
                    'No results are available for this job, as the specification of the run was invalid: ',
                    exception)
            else:
                self._errorBox(
                    core,
                    'No results are available for this job, as an error of type %s occured: '
                    % getClassName(exception), exception)

        return str(core)
コード例 #25
0
 def getPreProcessedTrackFromGalaxyTN(cls, genome, galaxyTN, printErrors=True, raiseIfAnyWarnings=False):
     'Takes a GalaxyTN as input, pre-processes the data that GalaxyTN refers to, and finally returns an ExternalTN that refers to the pre-processed data and can be used as a normal track name.'
     stdTrackName = cls.getStdTrackNameFromGalaxyTN(galaxyTN)
     cls.renameExistingStdTrackIfNeeded(genome, stdTrackName)
     fn = cls.extractFnFromGalaxyTN(galaxyTN)
     fileSuffix = cls.extractFileSuffixFromGalaxyTN(galaxyTN)
     
     print 'Preprocessing external track...<br><pre>'
     try:
         if cls.preProcess(fn, stdTrackName, fileSuffix, genome, raiseIfAnyWarnings=raiseIfAnyWarnings):
             print '</pre>Finished preprocessing.<br>'
         else:
             print '</pre>Already preprocessed, continuing...<br>'
     #except IOError:
     #    print '</pre>Already preprocessed, continuing...<br>'
     except Exception,e:
         if printErrors:
             print '</pre>An error occured during preprocessing: ', getClassName(e) + ':', e, '<br>'
         raise
コード例 #26
0
 def _compute(self):
     from collections import OrderedDict
     #res = {}
     res = OrderedDict()
     for childStat in self._children:
         childRes = childStat.getResult()
         #print '1',str(self._region), str(childRes)
         if not isinstance(childRes, dict):
             childRes = {
                 getClassName(childStat).replace('Unsplittable', '').replace(
                     'Splittable', ''):
                 childRes
             }
         #print '2',str(self._region), str(childRes)
         for key in childRes:
             assert not key in res
             res[key] = childRes[key]
         #print '3',str(self._region), str(res)
         #res.update(  childRes)
     return res
コード例 #27
0
    def getUniqueKey(self, genome):
        itemsToBeHashed = [tuple(self.trackName)]
        itemsToBeHashed.append(self._getTrackId(genome))

        if self._trackFormatReq is not None:
            if self._trackFormatReq.allowOverlaps() is not None:
                itemsToBeHashed.append(self._trackFormatReq.allowOverlaps())
            itemsToBeHashed.append(self._trackFormatReq.borderHandling())

        itemsToBeHashed.append(getClassName(self.formatConverters[0]) if self.formatConverters else '')
        # TODO: Move away from fixed VERSION, as these in practice are never updated. Also for statistics.
        itemsToBeHashed.append(self.formatConverters[0].VERSION if self.formatConverters else '')

        from config.DebugConfig import DebugConfig
        if DebugConfig.VERBOSE:
            from gold.application.LogSetup import logMessage
            logMessage('Unique key items for track "{}": '.format(self.trackName) +
                       ', '.join(str(_) for _ in itemsToBeHashed))

        return hash(tuple(itemsToBeHashed))
コード例 #28
0
ファイル: Track.py プロジェクト: Anderrb/Dynamic-benchmark
 def getTrackView(self, region):
     allowOverlaps = self._trackFormatReq.allowOverlaps()
     borderHandling = self._trackFormatReq.borderHandling()
     assert(allowOverlaps is not None) 
     assert(borderHandling is not None) 
     
     origTrackView = self._getRawTrackView(region, borderHandling, allowOverlaps)
     
     if self.formatConverters is None:
         self.formatConverters = getFormatConverters(origTrackView.trackFormat, self._trackFormatReq)
     
     if self.formatConverters == []:
         raise IncompatibleTracksError(prettyPrintTrackName(self.trackName) + ' with format: '\
                                       + str(origTrackView.trackFormat) +
                                       ('(' + origTrackView.trackFormat._val + ')' if origTrackView.trackFormat._val else '') + \
                                       ' does not satisfy ' + str(self._trackFormatReq))
     
     if not self.formatConverters[0].canHandle(origTrackView.trackFormat, self._trackFormatReq):
         raise IncompatibleTracksError(getClassName(self.formatConverters[0]) +\
                                       ' does not support conversion from ' + str(origTrackView.trackFormat) + \
                                       ' to ' + str(self._trackFormatReq))
     return self.formatConverters[0].convert(origTrackView)
コード例 #29
0
    def execute(self):
        outputFormat = self.params["datatype"] if self.params.has_key("datatype") else "html"
        if outputFormat in ["html", "customhtml", "hbfunction"]:
            self.stdoutToHistory()
        # print self.params

        for i in range(len(self.inputIds)):
            id = self.inputIds[i]
            choice = self.params[id] if self.params.has_key(id) else ""

            opts = self._getOptionsBox(i, choice)
            if opts == "__genome__":
                id = "dbkey"
                choice = self.params[id] if self.params.has_key(id) else ""

            #            if isinstance(opts, tuple):
            #                if opts[0] == '__hidden__':
            #                    choice = unquote(choice)

            if opts == "__genomes__" or (isinstance(opts, tuple) and opts[0] == "__multihistory__"):
                values = {}
                for key in self.params.keys():
                    if key.startswith(id + "|"):
                        values[key.split("|")[1]] = self.params[key]
                choice = OrderedDict(
                    sorted(values.items(), key=lambda t: int(t[0]) if opts[0] == "__multihistory__" else t[0])
                )

            if isinstance(opts, dict):
                values = type(opts)()
                for k, v in opts.items():
                    if self.params.has_key(id + "|" + k):
                        values[k] = self.params[id + "|" + k]
                    else:
                        values[k] = False
                choice = values

            if isinstance(opts, bool):
                choice = True if choice == "True" else False

            self.inputValues.append(choice)

        if self.params.has_key("Track_state"):
            self.inputValues.append(unquote(self.params["Track_state"]))

        ChoiceTuple = namedtuple("ChoiceTuple", self.inputIds)
        choices = ChoiceTuple._make(self.inputValues)

        # batchargs = '|'.join([';'.join(c.itervalues()) if not isinstance(c, str) else c for c in choices])
        # batchargs = '|'.join([repr(c.items()) if not isinstance(c, str) else c for c in choices])

        # print choices
        if outputFormat == "html":
            print """
            <html>
                <head>
                    <script type="text/javascript" src="%(prefix)s/static/scripts/jquery.js"></script>
                    <link href="%(prefix)s/static/style/base.css" rel="stylesheet" type="text/css" />
                </head>
                <body>
                    <p style="text-align:right"><a href="#debug" onclick="$('.debug').toggle()">Toggle debug</a></p>
                    <pre>
            """ % {
                "prefix": URL_PREFIX
            }
        #    print '<div class="debug">Corresponding batch run line:\n', '$Tool[%s](%s)</div>' % (self.toolId, batchargs)

        username = self.params["userEmail"] if "userEmail" in self.params else ""
        self._executeTool(getClassName(self.prototype), choices, galaxyFn=self.jobFile, username=username)

        if outputFormat == "html":
            print """
コード例 #30
0
    def _generateErrorText(self, coreCls):
        allErrors = self._results.getAllErrors()
        if len(allErrors) == 0:
            return ''

        core = coreCls()
        for exception in self._results.getAllErrors():
            if isinstance(exception, InvalidRunSpecException):
                self._errorBox(core, 'No results are available for this job, as the specification of the run was invalid: ', exception)
            else:
                self._errorBox(core, 'No results are available for this job, as an error of type %s occured: ' % getClassName(exception), exception)
        
        return str(core)
コード例 #31
0
            results.setGlobalResult( None )
            return None
            
        
    def _getSingleResult(self, region):
        #print 'Kw Here: ', self._kwArgs
        stat = self._statClass(region, self._track, self._track2, *self._args, **self._kwArgs)
        try:
            res = stat.getResult()
        except (CentromerError, NoneResultError),e:
            res = None
            if DebugConfig.PASS_ON_NONERESULT_EXCEPTIONS:
                raise
            
        #if not isinstance(res, dict):
        if not getClassName(res) in ['dict', 'OrderedDict']:
            res = {} if res is None else {self.GENERAL_RESDICTKEY : res}
            #res = {self.GENERAL_RESDICTKEY : res}

        ResultsMemoizer.flushStoredResults()
        return res, stat
    
    def getNumUserBins(self):
        if self._numUserBins is None:
            self._numUserBins = sum(1 for el in self._userBinSource)
        return self._numUserBins

    def _checkNumUserBinsIsValid(self):
        numUserBins = self.getNumUserBins()
        if numUserBins < 1:
            raise InvalidFormatError('Zero analysis bins specified.')
コード例 #32
0
            self._curChild = None  #first sets curchild to None to free memory even when self._bins.next() raises StopIteration..
            self._curChild = self._getChildObject(self._bins.next())

            self._curChild.createChildren()
            #self._binIndex += 1
        except StopIteration:
            #if self._binIndex == len(self._bins):
            self._trace('_combineResults')

            with StatisticExceptionHandling(**self._kwArgs):
                ret = None
                ret = self._combineResults()

            if DebugConfig.VERBOSE:  # @UndefinedVariable
                logMessage('Global result of statistic %s: %s' %
                           (getClassName(self), ret))

            if not self.hasResult():
                self._result = ret
            del self._bins

    def afterComputeCleanup(self):
        #        assert self._curChild is None, 'Error with: ' + getClassName(self) +' '+str(self._track.trackName) + (' '+str(self._track2.trackName) if hasattr(self, '_track2') else '')
        if hasattr(self, '_childResults'):
            del self._childResults

    def _getChildObject(self, bin):
        childName = getClassName(self).replace('Splittable', '')
        try:
            module = __import__('.'.join(['gold', 'statistic', childName]),
                                globals(), locals(), [childName])
コード例 #33
0
def getRandTrackClass(randTrackClassName):
    randTrackClass =  ( globals()[randTrackClassName] if randTrackClassName not in ['None',''] else None ) \
        if isinstance(randTrackClassName, basestring) else randTrackClassName

    assert randTrackClass in [None, PermutedSegsAndSampledIntersegsTrack, \
                       PermutedSegsAndIntersegsTrack, RandomGenomeLocationTrack, SegsSampledByIntensityTrack, ShuffledMarksTrack, SegsSampledByDistanceToReferenceTrack], getClassName(randTrackClass)
    return randTrackClass
コード例 #34
0
                if DebugConfig.VERBOSE:
                    logException(e, level=logging.DEBUG,
                                 message='(Warning: error in _determineStatClass for stat: %s)' % statClass.__name__)
                if DebugConfig.PASS_ON_VALIDSTAT_EXCEPTIONS:
                    raise
            except OSError, e:
                if DebugConfig.VERBOSE:
                    logException(e, message='(Error in _determineStatClass, with statClass %s)' % statClass.__name__)
                if DebugConfig.PASS_ON_VALIDSTAT_EXCEPTIONS:
                    raise
                elif not 'withOverlaps' in str(e):
                    raise


            except Exception, e:
                if getClassName(e) == 'AttributeError' and \
                        any(x in str(e) for x in ["has no attribute '_track2'", "'NoneType' object has no attribute"]):
                    if DebugConfig.VERBOSE:
                        logException(e, level=logging.DEBUG, message='(Warning: error in _determineStatClass for stat: %s)' % statClass.__name__)
                else:
                    logException(e, message='(Error in _determineStatClass, with statClass %s)' % statClass.__name__)
                if DebugConfig.PASS_ON_VALIDSTAT_EXCEPTIONS:
                    raise

            else:
                #self._reversed = reversed
                #self._conversionsUsed = len(trackA.conversionsUsed) > 0 or \
                #    ((trackB is not None) and len(trackB.conversionsUsed) > 0)
                ##self._validStatClass = functools.partial(statClass, **self.getChoices())
                #functools.update_wrapper(self._validStatClass, statClass)
                validStatClass = wrapClass(statClass, keywords=self.getChoices(filterByActivation=True) ) #fixme: Perhaps return validStatClass, self.getChoices() instead?
コード例 #35
0
            self._curChild.createChildren()
            #self._binIndex += 1
        except StopIteration:
            #if self._binIndex == len(self._bins):
            self._trace('_combineResults')

            ret = None
            with StatisticExceptionHandling(**self._kwArgs):
                ret = self._combineResults()

            if not self.hasResult():
                self._result = ret

            if DebugConfig.VERBOSE:
                logMessage('Global result of statistic %s: %s' % (getClassName(self), self._result))

            del self._bins

    def afterComputeCleanup(self):
#        assert self._curChild is None, 'Error with: ' + getClassName(self) +' '+str(self._track.trackName) + (' '+str(self._track2.trackName) if hasattr(self, '_track2') else '')
        if hasattr(self, '_childResults'):
            del self._childResults

    def _getChildObject(self, bin):
        childName = getClassName(self).replace('Splittable','')
        try:
            module = __import__('.'.join(['gold','statistic',childName]),globals(), locals(), [childName])
        except:
            module = __import__('.'.join(['quick','statistic',childName]),globals(), locals(), [childName])
コード例 #36
0
ファイル: StatRunner.py プロジェクト: uio-bmi/track_rand
        
    def _getSingleResult(self, region):
        #print 'Kw Here: ', self._kwArgs, 'args here: ', self._args
        # print self._statClass
        stat = self._statClass(region, self._trackStructure, *self._args, **self._kwArgs)
        try:
            res = stat.getResult()
        except (CentromerError, NoneResultError),e:
            res = None
            if DebugConfig.VERBOSE:
                logException(e, level=logging.DEBUG)
            if DebugConfig.PASS_ON_NONERESULT_EXCEPTIONS:
                raise
            
        #if not isinstance(res, dict):
        if not getClassName(res) in ['dict', 'OrderedDict']:
            res = {} if res is None else {self.GENERAL_RESDICTKEY : res}
            #res = {self.GENERAL_RESDICTKEY : res}

        ResultsMemoizer.flushStoredResults()
        return res, stat
    
    def getNumUserBins(self):
        if self._numUserBins is None:
            self._numUserBins = sum(1 for el in self._userBinSource)
        return self._numUserBins

    def _checkNumUserBinsIsValid(self):
        numUserBins = self.getNumUserBins()
        if numUserBins < 1:
            raise InvalidFormatError('Zero analysis bins specified.')