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)]
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) ]
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
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