Ejemplo n.º 1
0
 def __init__(self, region, track, track2, rawStatistic, randTrackClass=None, assumptions=None, tails=None, numResamplings=2000, randomSeed=None, **kwArgs):
     if tails==None:
         if 'tail' in kwArgs:
             tailTranslator = {'more':'right-tail', 'less':'left-tail', 'different':'two-tail'}
             tails = tailTranslator[kwArgs['tail']]
             if DebugConfig.VERBOSE:
                 logMessage('Argument tail provided instead of tails to RandomizationManagerStatUnsplittable', level=logging.DEBUG)
         else:
             tails = 'right-tail' # or 'two-tail'?
             logMessage('No tails argument provided to RandomizationManagerStatUnsplittable', level=logging.DEBUG)
     
     if track2 is None:
         self._track2 = None #to allow track2 to be passed on as None to rawStatistics without error. For use by single-track MC-tests..
         
     from gold.util.RandomUtil import getManualSeed, setManualSeed
     if randomSeed is not None and randomSeed != 'Random' and getManualSeed() is None:
         setManualSeed(int(randomSeed))
     
     if 'mcSetupScheme' in kwArgs:
         kwArgs = copy(kwArgs) #to not edit original dict..
         if kwArgs['mcSetupScheme'] != 'custom':
             assert not 'maxSamples' in kwArgs #check that specific values are not redundantly set
         #
     Statistic.__init__(self, region, track, track2, rawStatistic=rawStatistic, randTrackClass=randTrackClass, assumptions=assumptions, tails=tails, numResamplings=numResamplings, randomSeed=randomSeed, **kwArgs)
     #if type(rawStatistic) is str:
     #    from gold.statistic.AllStatistics import STAT_CLASS_DICT
     #    rawStatistic = STAT_CLASS_DICT[rawStatistic]
     
     assert (randTrackClass is None) ^ (assumptions is None) # xor
     if assumptions is not None:
         assert assumptions.count('_') == 1, assumptions
         randTrackClass1, randTrackClass2 = assumptions.split('_')
     else:
         randTrackClass1 = None
         randTrackClass2 = randTrackClass
     
     self._randTrackClass1, self._randTrackClass2 = \
         [ ( globals()[clsDef] if clsDef not in ['None',''] else None ) \
             if isinstance(clsDef, basestring) else clsDef for clsDef in [randTrackClass1, randTrackClass2]]
     
     assert not (randTrackClass1 is None and randTrackClass2 is None)
     for cls in [self._randTrackClass1, self._randTrackClass2]:
         assert cls in [None, PermutedSegsAndSampledIntersegsTrack, \
                        PermutedSegsAndIntersegsTrack, RandomGenomeLocationTrack, SegsSampledByIntensityTrack, ShuffledMarksTrack, SegsSampledByDistanceToReferenceTrack, PointsSampledFromBinaryIntensityTrack]
         
     #print self._randTrackClass1, self._randTrackClass2
     self._rawStatistic = self.getRawStatisticClass(rawStatistic)
     
     #self._randTrackList = []
     self._tails = tails
     if kwArgs.get('minimal') == True:
         self._numResamplings = 1
         self._kwArgs['maxSamples'] = 1
     else:
         self._numResamplings = int(numResamplings)
     CompBinManager.ALLOW_COMP_BIN_SPLITTING = False
     self._randResults = []
     self._observation = None
     #to load r libraries for McFdr:
     McFdr._initMcFdr()
 def __init__(self, region, track, track2, rawStatistic, randTrackClass=None, assumptions=None, tails=None, numResamplings=2000, randomSeed=None, **kwArgs):
     #print 'TEMP RM:',kwArgs
     if tails==None:
         if 'tail' in kwArgs:
             tailTranslator = {'more':'right-tail', 'less':'left-tail', 'different':'two-tail'}
             tails = tailTranslator[kwArgs['tail']]
             if DebugConfig.VERBOSE:
                 logMessage('Argument tail provided instead of tails to RandomizationManagerStatUnsplittable', level=logging.DEBUG)
         else:
             tails = 'right-tail' # or 'two-tail'?
             logMessage('No tails argument provided to RandomizationManagerStatUnsplittable', level=logging.DEBUG)
     
     if track2 is None:
         self._track2 = None #to allow track2 to be passed on as None to rawStatistics without error. For use by single-track MC-tests..
         
     from gold.util.RandomUtil import getManualSeed, setManualSeed
     if randomSeed is not None and randomSeed != 'Random' and getManualSeed() is None:
         setManualSeed(int(randomSeed))
         
     Statistic.__init__(self, region, track, track2, rawStatistic=rawStatistic, randTrackClass=randTrackClass, assumptions=assumptions, tails=tails, numResamplings=numResamplings, randomSeed=randomSeed, **kwArgs)
     #if type(rawStatistic) is str:
     #    from gold.statistic.AllStatistics import STAT_CLASS_DICT
     #    rawStatistic = STAT_CLASS_DICT[rawStatistic]
     
     assert (randTrackClass is None) ^ (assumptions is None) # xor
     if assumptions is not None:
         assert assumptions.count('_') == 1, assumptions
         randTrackClass1, randTrackClass2 = assumptions.split('_')
     else:
         randTrackClass1 = None
         randTrackClass2 = randTrackClass
     
     self._randTrackClass1, self._randTrackClass2 = \
         [ ( globals()[clsDef] if clsDef not in ['None',''] else None ) \
             if type(clsDef) is str else clsDef for clsDef in [randTrackClass1, randTrackClass2] ]
     
     assert not (randTrackClass1 is None and randTrackClass2 is None)
     for cls in [self._randTrackClass1, self._randTrackClass2]:
         assert cls in [None, PermutedSegsAndSampledIntersegsTrack, \
                        PermutedSegsAndIntersegsTrack, RandomGenomeLocationTrack, SegsSampledByIntensityTrack, ShuffledMarksTrack]
         
     #print self._randTrackClass1, self._randTrackClass2
     self._rawStatistic = self.getRawStatisticClass(rawStatistic)
     
     #self._randTrackList = []
     self._tails = tails
     if kwArgs.get('minimal') == True:
         self._numResamplings = 1
         self._kwArgs['maxSamples'] = 1
     else:
         self._numResamplings = int(numResamplings)
     CompBinManager.ALLOW_COMP_BIN_SPLITTING = False
     self._randResults = []
     self._observation = None
     #to load r libraries for McFdr:
     McFdr._initMcFdr()
 def execute(choices, galaxyFn=None, username=''):
     '''Is called when execute-button is pushed by web-user.
     Should print output as HTML to standard out, which will be directed to a results page in Galaxy history.
     If getOutputFormat is anything else than HTML, the output should be written to the file with path galaxyFn.
     If needed, StaticFile can be used to get a path where additional files can be put (e.g. generated image files).
     choices is a list of selections made by web-user in each options box.
     '''
     from quick.statistic.McFdr import McFdr
     McFdr._initMcFdr()
     qvalsSet = [McFdr.adjustPvalues([float(x) for x in pvals.replace('c(','').replace(')','').split(',') ]) for pvals in choices[0].split('\n') if pvals!='']
     for i,qvals in enumerate(qvalsSet):
         print 'qvals%i = c(' % (i+1) + ','.join(str(x) for x in qvals) + ')' 
Ejemplo n.º 4
0
 def execute(cls, choices, galaxyFn=None, username=''):
     '''Is called when execute-button is pushed by web-user.
     Should print output as HTML to standard out, which will be directed to a results page in Galaxy history.
     If getOutputFormat is anything else than HTML, the output should be written to the file with path galaxyFn.
     If needed, StaticFile can be used to get a path where additional files can be put (e.g. generated image files).
     choices is a list of selections made by web-user in each options box.
     '''
     from quick.statistic.McFdr import McFdr
     
     McFdr._initMcFdr()
     qvalsSet = [McFdr.adjustPvalues([float(x) for x in pvals.replace('c(','').replace(')','').split(',') ]) for pvals in choices[0].split('\n') if pvals!='']
     for i,qvals in enumerate(qvalsSet):
         print 'qvals%i = c(' % (i+1) + ','.join(str(x) for x in qvals) + ')' 
Ejemplo n.º 5
0
    def validateAndPossiblyResetLocalResults(cls, localSamplingObjects):
        #to load r libraries for McFdr:
        McFdr._initMcFdr()

        numNonDetermined = 0
        pvals = [x._getPval() for x in localSamplingObjects]
        qValues = McFdr.adjustPvalues(pvals, verbose=False)
        #First decide whether any further sampling will be needed (whether numNonDetermined==0)
        for i in range(len(localSamplingObjects)):
            localSamplingObjects[i]._adjPValue = qValues[i]
            if not localSamplingObjects[i].isMcDetermined():
                numNonDetermined += 1

        #print 'TEMP3: ', numNonDetermined
        if numNonDetermined > 0:
            #Decide which will need further sampling (through deleting result), based on individualMcDetermined
            for i in range(len(localSamplingObjects)):
                if not localSamplingObjects[i].isIndividuallyMcDetermined():
                    del localSamplingObjects[i]._result
        return numNonDetermined
Ejemplo n.º 6
0
    def inferAdjustedPvalues(self):
        pValKey = self.getPvalKey()
        if pValKey is None or self.FDR_KEY in self.getResDictKeys():
            return

        regKeys = self.getAllRegionKeys()
        #regPVals = [ self[reg].get(pValKey) if (self[reg].get(pValKey) is not None) else numpy.nan for reg in regKeys]
        #
        #from gold.application.RSetup import r
        #regFdrVals = r('p.adjust')(r.unlist(regPVals), self.FDR_KEY)
        regPVals = [self[reg].get(pValKey) for reg in regKeys]
        from quick.statistic.McFdr import McFdr
        McFdr._initMcFdr()  #to load r libraries..
        regFdrVals = McFdr.adjustPvalues(regPVals, verbose=False)

        #if len(regPVals) == 1:
        #    regFdrVals = [regFdrVals]
        assert len(regFdrVals) == len(regKeys), 'fdr: ' + str(
            len(regFdrVals)) + ', regs: ' + str(len(regKeys))
        for i, reg in enumerate(regKeys):
            self[reg][self.FDR_KEY] = (regFdrVals[i] if regPVals[i] is not None
                                       else numpy.nan)

        if self._globalResult is None:
            keys = self.getResDictKeys()
            self._globalResult = OrderedDict(zip((keys), [None] * len(keys)))

        #self._globalResult[self.FDR_KEY] = self.getSignBinsText(regFdrVals, self.FDR_THRESHOLD)
        #if self._globalResult[pValKey] is None:
        #self._globalResult[pValKey] = self.getSignBinsText(regPVals, self.PVALUE_THRESHOLD)

        tempGlobalResult = self._globalResult
        self._globalResult = OrderedDict()

        self._globalResult.update([(pValKey, tempGlobalResult[pValKey])])
        self._globalResult.update([(self.FDR_KEY, None)])
        self._globalResult.update([(key, tempGlobalResult[key])
                                   for key in tempGlobalResult.keys()
                                   if key != pValKey])

        self._resDictKeys = None  #resetting..
Ejemplo n.º 7
0
    def inferAdjustedPvalues(self):
        pValKey = self.getPvalKey()                
        if pValKey is None or self.FDR_KEY in self.getResDictKeys():
            return

        from gold.application.RSetup import r
        
        regKeys = self.getAllRegionKeys()
        #regPVals = [ self[reg].get(pValKey) if (self[reg].get(pValKey) is not None) else numpy.nan for reg in regKeys]
        #
        #from gold.application.RSetup import r
        #regFdrVals = r('p.adjust')(r.unlist(regPVals), self.FDR_KEY)
        regPVals = [ self[reg].get(pValKey) for reg in regKeys]
        from quick.statistic.McFdr import McFdr
        McFdr._initMcFdr() #to load r libraries..
        regFdrVals = McFdr.adjustPvalues(regPVals, verbose=False)
        
        #if len(regPVals) == 1:
        #    regFdrVals = [regFdrVals]
        assert len(regFdrVals) == len(regKeys), 'fdr: ' + str(len(regFdrVals)) + ', regs: ' + str(len(regKeys))
        for i, reg in enumerate(regKeys):
            self[reg][self.FDR_KEY] = (regFdrVals[i] if regPVals[i] is not None else numpy.nan)
            
        
        if self._globalResult is None:
            keys = self.getResDictKeys()
            self._globalResult = OrderedDict(zip((keys), [None]*len(keys)))
        
        #self._globalResult[self.FDR_KEY] = self.getSignBinsText(regFdrVals, self.FDR_THRESHOLD)
        #if self._globalResult[pValKey] is None:
            #self._globalResult[pValKey] = self.getSignBinsText(regPVals, self.PVALUE_THRESHOLD)
        
        tempGlobalResult = self._globalResult
        self._globalResult = OrderedDict()
        
        self._globalResult.update([(pValKey, tempGlobalResult[pValKey])])    
        self._globalResult.update([(self.FDR_KEY, None)])
        self._globalResult.update([(key, tempGlobalResult[key]) for key in tempGlobalResult.keys() if key != pValKey])
        
        self._resDictKeys = None #resetting..