Пример #1
0
 def isStatisticInChildren(cls, job, statisticName):
     for region in job._userBinSource:
         stat = job._statClass(region, job._track, job._track2, *job._args, **job._kwArgs)
         break
     
     stat.createChildren()
     
     result = cls.searchForStatisticRecursively(stat, statisticName)
     MagicStatFactory.resetMemoDict()
     return result
Пример #2
0
 def run(self, reset=True, printProgress=PRINT_PROGRESS):
     if reset:
         MagicStatFactory.resetMemoDict()
         
     results = self._emptyResults()
     try:
         self._checkNumUserBinsIsValid()
     except Exception, e:
         results.addError(e)
         return results
 def isStatisticInChildren(cls, job, statisticName):
     for region in job._userBinSource:
         stat = job._statClass(region, job._track, job._track2, *job._args, **job._kwArgs)
         break
     
     stat.createChildren()
     
     result = cls.searchForStatisticRecursively(stat, statisticName)
     MagicStatFactory.resetMemoDict()
     return result
Пример #4
0
 def run(self, reset=True, printProgress=PRINT_PROGRESS):        
     if reset:
         MagicStatFactory.resetMemoDict()
         
     results = self._emptyResults()
     try:
         self._checkNumUserBinsIsValid()
     except Exception, e:
         results.addError(e)
         return results
 def __new__(cls, region, track, trackFormatReq, **kwArgs):
     assert isinstance(trackFormatReq, TrackFormatReq)
     return MagicStatFactory.__new__(cls,
                                     region,
                                     track,
                                     trackFormatReq=trackFormatReq,
                                     **kwArgs)
 def _setExtraParams(cls, prevChoices):        
     
     methodObj = getattr( MagicStatFactory._getClass(prevChoices[0], 'Unsplittable')  ,   '__init__')
     methodParams = ['Region','BinSpec']+[v for v in getargspec(methodObj).args if not v in ['self', 'track', 'track2', 'region']]
     defaultVals = ['','']+(list(getargspec(methodObj).defaults)  if  getargspec(methodObj).defaults and len(methodParams)>0   else [])
     
     lenDifference = len(methodParams)-len(defaultVals)
     defaultVals = ['']*(lenDifference)+ defaultVals if lenDifference>=0 else defaultVals[-lenDifference:]
     
     cls._extraParams = [value + ' (default: %s)' % defaultVals[index] for index, value in enumerate(methodParams)]
Пример #7
0
    def _setExtraParams(cls, prevChoices):

        methodObj = getattr(
            MagicStatFactory._getClass(prevChoices[0], 'Unsplittable'),
            '__init__')
        methodParams = ['Region', 'BinSpec'] + [
            v for v in getargspec(methodObj).args
            if not v in ['self', 'track', 'track2', 'region']
        ]
        defaultVals = ['', ''] + (list(getargspec(methodObj).defaults)
                                  if getargspec(methodObj).defaults
                                  and len(methodParams) > 0 else [])

        lenDifference = len(methodParams) - len(defaultVals)
        defaultVals = [''] * (
            lenDifference
        ) + defaultVals if lenDifference >= 0 else defaultVals[-lenDifference:]

        cls._extraParams = [
            value + ' (default: %s)' % defaultVals[index]
            for index, value in enumerate(methodParams)
        ]
Пример #8
0
 def __new__(cls, region, track, trackFormatReq, **kwArgs):
     assert isinstance(trackFormatReq, TrackFormatReq)
     track.addFormatReq(trackFormatReq)
     return MagicStatFactory.__new__(cls, region, track, **kwArgs)
Пример #9
0
    def execute(cls, choices, galaxyFn=None, username=''):

        shelveDict = {
            'track1':
            choices[3] if choices[3] != cls.NO_TRACK_SHORTNAME else None
        }
        shelveDict['track2'] = choices[
            5] if choices[5] != cls.NO_TRACK_SHORTNAME else None
        print len(choices)
        print cls._extraParams
        for i in range(len(cls._extraParams)):
            index = i * 2 + cls.FIRST_EXTRA_PARAM_BOX_NUMBER + 1
            shelveDict[index] = choices[index].strip()

        DebugInfoShelve = safeshelve.open(cls.SHELVE_FN)
        DebugInfoShelve[choices[0]] = shelveDict
        DebugInfoShelve.close()

        try:

            from gold.application.LogSetup import setupDebugModeAndLogging
            setupDebugModeAndLogging()

            print 'Getting Unsplittable statClass'
            statClassName = choices[0]
            #statClass = STAT_CLASS_DICT[statClassName]
            #try:

            print 'Preparing arguments to init'
            unsplittableStatClass = MagicStatFactory._getClass(
                statClassName, 'Unsplittable')
            genome = choices[1]

            from gold.track.Track import PlainTrack
            prefixTN1 = cls.STD_PREFIX_TN if choices[2] == 'yes' else []
            tn1 = prefixTN1 + choices[3].split(':')
            track1 = PlainTrack(
                tn1) if choices[3] != cls.NO_TRACK_SHORTNAME else None
            prefixTN2 = cls.STD_PREFIX_TN if choices[4] == 'yes' else []
            tn2 = prefixTN2 + choices[5].split(':')
            track2 = PlainTrack(
                tn2) if choices[5] != cls.NO_TRACK_SHORTNAME else None
            from gold.track.GenomeRegion import GenomeRegion
            #region = GenomeRegion(genome, 'chr1',1000,2000)
            #region2 = GenomeRegion(genome, 'chr1',5000,6000)

            kwArgs = {}
            regVal = choices[cls.FIRST_EXTRA_PARAM_BOX_NUMBER + 1]
            binSpecVal = choices[cls.FIRST_EXTRA_PARAM_BOX_NUMBER + 3]
            ubSource = UserBinSource(regVal, binSpecVal, genome=genome)
            region = list(ubSource)[0]

            if len(cls._extraParams) > 3:
                for i in range(len(cls._extraParams)):
                    paramName = choices[i * 2 +
                                        cls.FIRST_EXTRA_PARAM_BOX_NUMBER]
                    param = paramName[:paramName.find('(')].strip()
                    val = choices[i * 2 + cls.FIRST_EXTRA_PARAM_BOX_NUMBER +
                                  1].strip()
                    if val != '':
                        kwArgs[param] = val
                        shelveDict[i * 2 + cls.FIRST_EXTRA_PARAM_BOX_NUMBER +
                                   1] = val

            print 'Calling __init__'
            #
            statObj = unsplittableStatClass(region, track1, track2, **kwArgs)

            print 'Calling createChildren'
            statObj.createChildren()

            print 'Calling getResult'
            statObj.getResult()

            #except:
            #    raise

            #print 'Preparing arguments to init'
            #genome = 'hg18'
            #prefixTN = ['DNA structure'] if choices[2] == 'yes' else []
            #from gold.track.Track import PlainTrack
            #tn1 = prefixTN + choices[3].split(':')
            #track1 = PlainTrack(tn1)
            #tn2 = prefixTN + choices[5].split(':')
            #track2 = PlainTrack(tn2)
            #from gold.track.GenomeRegion import GenomeRegion
            ##region = GenomeRegion(genome, 'chr1',1000,2000)
            ##region2 = GenomeRegion(genome, 'chr1',5000,6000)
            #
            #kwArgs = {}
            #regVal = choices[cls.FIRST_EXTRA_PARAM_BOX_NUMBER+1]
            #binSpecVal = choices[cls.FIRST_EXTRA_PARAM_BOX_NUMBER+3]
            #ubSource = UserBinSource(regVal, binSpecVal, genome=choices[1])
            #region = list(UserBinSource)[0]
            #
            #if len(cls._extraParams)>2:
            #    for i in range(2,len(cls._extraParams)):
            #        paramName = choices[i*2+cls.FIRST_EXTRA_PARAM_BOX_NUMBER]
            #        param = paramName[:paramName.find('(')].strip()
            #        val = choices[i*2+cls.FIRST_EXTRA_PARAM_BOX_NUMBER+1].strip()
            #        if val !='':
            #            kwArgs[param] = val
            #            shelveDict[i*2+cls.FIRST_EXTRA_PARAM_BOX_NUMBER+1] = val
            #
            #
            ##extraParams += [v.strip() for v in choices.kwArgs.split(',')] if choices.kwArgs.strip() != '' else []
            ##args = [region, track1, track2]
            #
            #print 'Calling __init__'
            ##
            #statObj = unsplittableStatClass(region, track1, track2, **kwArgs)
            #
            #print 'Calling createChildren'
            #statObj.createChildren()
            #
            #print 'Calling getResult'
            #statObj.getResult()

            print 'Running StatJob'
            magicStatClass = STAT_CLASS_DICT[statClassName]
            #res = StatJob([region,region2],track1,track2,magicStatClass,**kwArgs).run()
            res = StatJob(ubSource, track1, track2, magicStatClass,
                          **kwArgs).run()
            from quick.application.GalaxyInterface import GalaxyInterface
            GalaxyInterface._viewResults([res], galaxyFn)

        except Exception, e:
            print 'Error: ', e
            raise
Пример #10
0
 def _updateInMemoDict(self, statKwUpdateDict):
     from gold.statistic.MagicStatFactory import MagicStatFactory
     MagicStatFactory.updateMemoDict(self, statKwUpdateDict)
Пример #11
0
    def execute(cls, choices, galaxyFn=None, username=''):
        
        shelveDict = {'track1':choices[3] if choices[3]!=cls.NO_TRACK_SHORTNAME else None}
        shelveDict['track2'] = choices[5] if choices[5]!=cls.NO_TRACK_SHORTNAME else None
        print len(choices)
        print cls._extraParams
        for i in range(len(cls._extraParams)):
            index = i*2+cls.FIRST_EXTRA_PARAM_BOX_NUMBER+1
            shelveDict[index] = choices[index].strip()
        
        DebugInfoShelve = safeshelve.open(cls.SHELVE_FN)
        DebugInfoShelve[choices[0]] = shelveDict
        DebugInfoShelve.close()
        
            
        try:
            
            cls.setupDebugModeAndLogging(verbose=False) #add box to select this
            
            print 'Getting Unsplittable statClass'
            statClassName = choices[0]        
            #statClass = STAT_CLASS_DICT[statClassName]
            #try:
                
                
            
            print 'Preparing arguments to init'
            unsplittableStatClass = MagicStatFactory._getClass(statClassName, 'Unsplittable')            
            genome = choices[1]
            
            from gold.track.Track import PlainTrack
            prefixTN1 = cls.STD_PREFIX_TN if choices[2] == 'yes' else []
            tn1 = prefixTN1 + choices[3].split(':') 
            track1 = PlainTrack(tn1) if choices[3]!=cls.NO_TRACK_SHORTNAME else None
            prefixTN2 = cls.STD_PREFIX_TN if choices[4] == 'yes' else []
            tn2 = prefixTN2 + choices[5].split(':')
            track2 = PlainTrack(tn2) if choices[5]!=cls.NO_TRACK_SHORTNAME else None
            from gold.track.GenomeRegion import GenomeRegion
            #region = GenomeRegion(genome, 'chr1',1000,2000)
            #region2 = GenomeRegion(genome, 'chr1',5000,6000)
            
            kwArgs = {}
            regVal = choices[cls.FIRST_EXTRA_PARAM_BOX_NUMBER+1]
            binSpecVal = choices[cls.FIRST_EXTRA_PARAM_BOX_NUMBER+3]
            ubSource = UserBinSource(regVal, binSpecVal, genome=genome)
            region = list(ubSource)[0]

            if len(cls._extraParams)>3:
                for i in range(len(cls._extraParams)):
                    paramName = choices[i*2+cls.FIRST_EXTRA_PARAM_BOX_NUMBER]
                    param = paramName[:paramName.find('(')].strip()
                    val = choices[i*2+cls.FIRST_EXTRA_PARAM_BOX_NUMBER+1].strip()
                    if val !='':
                        kwArgs[param] = val
                        shelveDict[i*2+cls.FIRST_EXTRA_PARAM_BOX_NUMBER+1] = val
                        
    
            print 'Calling __init__'
            #
            statObj = unsplittableStatClass(region, track1, track2, **kwArgs)
            
            print 'Calling createChildren'
            statObj.createChildren()
    
            print 'Calling getResult'
            statObj.getResult()
        
            #except:
            #    raise

            #print 'Preparing arguments to init'
            #genome = 'hg18'
            #prefixTN = ['DNA structure'] if choices[2] == 'yes' else []
            #from gold.track.Track import PlainTrack
            #tn1 = prefixTN + choices[3].split(':') 
            #track1 = PlainTrack(tn1)
            #tn2 = prefixTN + choices[5].split(':')
            #track2 = PlainTrack(tn2)
            #from gold.track.GenomeRegion import GenomeRegion
            ##region = GenomeRegion(genome, 'chr1',1000,2000)
            ##region2 = GenomeRegion(genome, 'chr1',5000,6000)
            #
            #kwArgs = {}
            #regVal = choices[cls.FIRST_EXTRA_PARAM_BOX_NUMBER+1]
            #binSpecVal = choices[cls.FIRST_EXTRA_PARAM_BOX_NUMBER+3]
            #ubSource = UserBinSource(regVal, binSpecVal, genome=choices[1])
            #region = list(UserBinSource)[0]
            #
            #if len(cls._extraParams)>2:
            #    for i in range(2,len(cls._extraParams)):
            #        paramName = choices[i*2+cls.FIRST_EXTRA_PARAM_BOX_NUMBER]
            #        param = paramName[:paramName.find('(')].strip()
            #        val = choices[i*2+cls.FIRST_EXTRA_PARAM_BOX_NUMBER+1].strip()
            #        if val !='':
            #            kwArgs[param] = val
            #            shelveDict[i*2+cls.FIRST_EXTRA_PARAM_BOX_NUMBER+1] = val
            #
            #
            ##extraParams += [v.strip() for v in choices.kwArgs.split(',')] if choices.kwArgs.strip() != '' else []        
            ##args = [region, track1, track2] 
            #
            #print 'Calling __init__'
            ##
            #statObj = unsplittableStatClass(region, track1, track2, **kwArgs)
            #
            #print 'Calling createChildren'
            #statObj.createChildren()
            #
            #print 'Calling getResult'
            #statObj.getResult()
            
            print 'Running StatJob'
            magicStatClass = STAT_CLASS_DICT[statClassName]
            #res = StatJob([region,region2],track1,track2,magicStatClass,**kwArgs).run()
            res = StatJob(ubSource,track1,track2,magicStatClass,**kwArgs).run()
            from quick.application.GalaxyInterface import GalaxyInterface
            GalaxyInterface._viewResults([res],galaxyFn)
            
        except Exception, e:
            print 'Error: ',e
            raise
Пример #12
0
 def _updateInMemoDict(self, statKwUpdateDict):
     from gold.statistic.MagicStatFactory import MagicStatFactory
     MagicStatFactory.updateMemoDict(self, statKwUpdateDict)