def _setDebugModeIfSelected(choices): if choices.debugMode: if choices.debugMode == DebugModes.NO_DEBUG: DebugConfig.changeMode(choices.debugMode) else: #Sets up std.out and std.err to pipe debug and error log messages, respectively, #in addition to setting the debug mode setupDebugModeAndLogging(choices.debugMode)
def getAnalysisDefinitionString(self): from gold.application.LogSetup import setupDebugModeAndLogging setupDebugModeAndLogging() analysisDef = 'dummy -> ThreeWayFocusedTrackCoveragesAtDepthsStat' analysisDef = 'dummy [extraTracks=%s] '\ % '&'.join(['|'.join(tn) for tn in self._tracks[2:] ]) + analysisDef return analysisDef
def getAnalysisDefinitionString(self): #Old version analysisDef = 'dummy [tail=different] [rawStatistic=SingleValExtractorStat] \ [childClass=ThreeWayBpOverlapStat] [resultKey=%s] %s %s -> RandomizationManagerStat' \ % ('1'*(len(self._tracks)), self._randOption, self._numResamplingsOption) from gold.application.LogSetup import setupDebugModeAndLogging setupDebugModeAndLogging() # analysisDef = 'dummy [tail=different] [rawStatistic=SingleValExtractorStat] \ # [childClass=MultitrackBpOverlapStat] [resultKey=%s] %s %s -> RandomizationManagerStat' \ # % ('1'*(len(self._tracks)), self._randOption, self._numResamplingsOption) analysisDef = 'dummy [extraTracks=%s] '\ % '&'.join(['|'.join(tn) for tn in self._tracks[2:] ]) + analysisDef return analysisDef
def doAnalysisV2(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 = [ PlainTrack(['Genes and gene subsets','Genes','Refseq']) ] results = doAnalysis(analysisSpec, analysisBins, tracks) ''' setupDebugModeAndLogging( ) #in an API setting, exceptions should not generally be hidden. Maybe this should be optional. job = StatJobV2(analysisBins, trackStructure, analysisSpec._statClassList[0], galaxyFn=None) res = job.run(printProgress=False) #Maybe printProgress should be optional return res
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 gold.application.LogSetup import setupDebugModeAndLogging setupDebugModeAndLogging() analysisDef = choices[2].replace(os.linesep, '') #from gold.application.StatRunner import AnalysisDefJob print 'Preparing arguments' genome = choices[3] prefixTN1 = cls.STD_PREFIX_TN if choices[4] == 'yes' else [] tn1 = prefixTN1 + choices[5].split(':') prefixTN2 = cls.STD_PREFIX_TN if choices[6] == 'yes' else [] tn2 = prefixTN2 + choices[7].split(':') if tn2[-1] == cls.NO_TRACK_SHORTNAME: tn2 = None #from gold.track.GenomeRegion import GenomeRegion #region = GenomeRegion(genome, 'chr1',1000,2000) #region2 = GenomeRegion(genome, 'chr1',5000,6000) #kwArgs = {} regVal = choices[8] binSpecVal = choices[9] #ubSource = UserBinSource(regVal, binSpecVal, genome=genome) from quick.application.GalaxyInterface import GalaxyInterface print tn1, tn2 GalaxyInterface.runManual([tn1, tn2], analysisDef, regVal, binSpecVal, genome, galaxyFn, username=username)
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. ''' batchLines = choices[0].split('\n') assert choices[1] in ['False','True'] verbose = (choices[1] == 'True') from gold.application.LogSetup import setupDebugModeAndLogging setupDebugModeAndLogging() try: GalaxyInterface.runBatchLines(batchLines, galaxyFn, username=username) except Exception, e: print '</div>' print traceback.format_exc() print e raise
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 gold.application.LogSetup import setupDebugModeAndLogging setupDebugModeAndLogging() targetTrackNames, targetTrackCollection, targetTrackGenome = getGSuiteDataFromGalaxyTN( choices.gSuiteFirst) targetTracksDict = OrderedDict( zip(targetTrackNames, targetTrackCollection)) refTrackNames, refTrackCollection, refTrackCollectionGenome = getGSuiteDataFromGalaxyTN( choices.gSuiteSecond) assert targetTrackGenome == refTrackCollectionGenome, 'Reference genome must be the same one in both GSuite files.' refTracksDict = OrderedDict(zip(refTrackNames, refTrackCollection)) regSpec, binSpec = UserBinMixin.getRegsAndBinsSpec(choices) analysisDef = 'dummy -> RawOverlapStat' results = OrderedDict() for targetTrackName, targetTrack in targetTracksDict.iteritems(): for refTrackName, refTrack in refTracksDict.iteritems(): result = GalaxyInterface.runManual([targetTrack, refTrack], analysisDef, regSpec, binSpec, targetTrackGenome, galaxyFn, printRunDescription=False, printResults=False) if targetTrackName not in results: results[targetTrackName] = OrderedDict() results[targetTrackName][ refTrackName] = result.getGlobalResult() targetTrackTitles = results.keys() stat = choices.statistic statIndex = STAT_LIST_INDEX[stat] title = stat + ' analysis of track collections' processedResults = [] headerColumn = [] for targetTrackName in targetTrackTitles: resultRowDict = processRawResults(results[targetTrackName]) resultColumn = [] headerColumn = [] for refTrackName, statList in resultRowDict.iteritems(): resultColumn.append(statList[statIndex]) headerColumn.append(refTrackName) processedResults.append(resultColumn) transposedProcessedResults = [list(x) for x in zip(*processedResults)] tableHeader = ['Track names'] + targetTrackTitles htmlCore = HtmlCore() htmlCore.begin() htmlCore.header(title) htmlCore.divBegin('resultsDiv') htmlCore.tableHeader(tableHeader, sortable=True, tableId='resultsTable') for i, row in enumerate(transposedProcessedResults): line = [headerColumn[i]] + row htmlCore.tableLine(line) htmlCore.tableFooter() htmlCore.divEnd() addColumnPlotToHtmlCore(htmlCore, targetTrackNames, refTrackNames, stat, title + ' plot', processedResults, xAxisRotation=315) htmlCore.hideToggle(styleClass='debug') htmlCore.end() print htmlCore
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 setUp(self): StatUnitTest.setUp(self) from gold.application.LogSetup import setupDebugModeAndLogging setupDebugModeAndLogging()