def _createChildren(self):
     if self._useMC:
         rawStat = wrapClass(BasicCustomRStat, {'scriptFn':self._scriptFn})
         #self._addChild( RandomizationManagerStat(self._region, self._track, self._track2, rawStat, \
         #                                         ReshuffledRandomizedTrack, numResamplings=20 ) )
         self._addChild( RandomizationManagerStat(self._region, self._track, self._track2, rawStat, \
                                                      PermutedSegsAndSampledIntersegsTrack, numResamplings=20 ) )
     else:
         self._addChild(BasicCustomRStat(self._region, self._track, self._track2, self._scriptFn))
def test2():
    myTrack = Track(['melting'])
    myTrack2 = Track(['genes', 'refseq'])
    userBinSource = UserBinSource('chr1:0-10', '10')

    res = StatRunner.run(userBinSource, myTrack, myTrack2,
                         wrapClass(CustomRStat, {'scriptFn': fn}))
    resColl = ResultsCollection()
    resColl.addResults(None, res)
    print resColl.getHtmlString()
Beispiel #3
0
def doAnalysis(analysisSpec, analysisBins, trackStructure):
    '''Performs an analysis,
    as specified by analysisSpec object,
    in each bin specified by analysisBins,
    on data sets specified in tracks.

    Typical usage:
    analysisSpec = AnalysisSpec(AvgSegLenStat)
    analysisSpec.addParameter("withOverlaps","no")
    analysisBins = GlobalBinSource('hg18')
    tracks = [ Track(['Genes and gene subsets','Genes','Refseq']) ]
    results = doAnalysis(analysisSpec, analysisBins, tracks)
    '''

    # TODO: handle multiple tracks analysis
    # assert len(tracks) in [1,2] #for now..
    # in an API setting, exceptions should not generally be hidden.
    # Maybe this should be optional.
    # setupDebugModeAndLogging()
    silenceRWarnings()
    silenceNumpyWarnings()

    if isinstance(trackStructure, TrackStructureV2):
        analysisDef = AnalysisDefHandler(analysisSpec.getDefAfterChoices())
        statClass = analysisDef._statClassList[0]
        validStatClass = wrapClass(
            statClass,
            keywords=analysisDef.getChoices(filterByActivation=True))
        job = StatJob(analysisBins, trackStructure, validStatClass)
    else:
        tracks = trackStructure
        if len(tracks) > 2:
            from gold.util.CommonConstants import MULTIPLE_EXTRA_TRACKS_SEPARATOR
            analysisSpec.addParameter(
                'extraTracks',
                MULTIPLE_EXTRA_TRACKS_SEPARATOR.join([
                    '^'.join([quote(part) for part in x.trackName])
                    for x in tracks[2:]
                ]))
        job = AnalysisDefJob(analysisSpec.getDefAfterChoices(),
                             tracks[0].trackName,
                             tracks[1].trackName if len(tracks) > 1 else None,
                             analysisBins,
                             galaxyFn=None)

    res = job.run(printProgress=False)  # printProgress should be optional?
    return res
Beispiel #4
0
                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?
                #self.setConverters( self._track.formatConverters, self._track2.formatConverters if self._track2 is not None else None)
                #self._updateOptions()
                if DebugConfig.VERBOSE:
                    logMessage(statClass.__name__ + ': OK')
#                        print statClass.__name__ + ': OK'
                return validStatClass
            finally:
                self.resetTracks()
        
        return None
    
    def _appendConverterOptions(self, track, labelKey):
        if track is None:
            return
Beispiel #5
0
                        any(x in str(e) for x in ["has no attribute '_track2'","'NoneType' object has no attribute"]):
                        if DebugConfig.VERBOSE:
                            logException(e, message='(Warning: error in _determineStatClass for stat: %s)' % statClass.__name__)
                    else:
                        logException(e, message='(Error in _determineStatClass, with statClass %s)' % statClass.__name__)
                        #if VERBOSE:
                        #    print 'Warning: exception in getStat: ', \
                        #        statClass.__name__ + ': ' + e.__class__.__name__ + ': ' + str(e)
                        #    traceback.print_exc(file=sys.stdout)
                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() )
                    #self.setConverters( self._track.formatConverters, self._track2.formatConverters if self._track2 is not None else None)
                    #self._updateOptions()
                    if DebugConfig.VERBOSE:
                        logMessage(statClass.__name__ + ': OK')
#                        print statClass.__name__ + ': OK'
                    return validStatClass
        
        return None
    
    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]))