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. ''' if choices[0] == cls.INPUT_FIELD: batchStr = choices[1] else: from quick.application.ExternalTrackManager import ExternalTrackManager batchStr = open( ExternalTrackManager.extractFnFromGalaxyTN( choices[2].split(':'))).read() batchLines = [x.strip() for x in batchStr.strip().split(os.linesep)] #batchLines = [x.strip() for x in choices[0].strip().split(os.linesep)] legalBatchLines = cls._removeIllegalLines(batchLines, username) if len(legalBatchLines) > 0: GalaxyInterface.runBatchLines(batchLines=legalBatchLines, galaxyFn=galaxyFn, \ genome=None, username=username) else: return 'Your user does not have access to run these command lines.'
def directGetEnrichment(diseaseTrack, refTrackLeaf, refTrackBase, kernelType, kernelParam, useCache=True, printProgress=False): RETRIEVE_FROM_CACHE = useCache STORE_TO_CACHE = useCache if kernelType == 'gaussian': kernelParamAssignment = ',kernelStdev=%s' % kernelParam elif kernelType == 'divideByOffset': kernelParamAssignment = ',minimumOffsetValue=%s' % kernelParam elif kernelType == 'binSizeNormalized': kernelParamAssignment = '' elif kernelType == 'catCoverageNormalized': kernelParamAssignment = '' elif kernelType == 'uniform': kernelParamAssignment = '' else: raise #RuntimeError('unre' batchText = ''' @bins=%s @TNs=%s:%s @TNunion=%s hg19|track|@bins|@TNs|@TNunion|DiffRelCoverageStat(globalSource=chrs,tf1=TrivialFormatConverter,tf2=TrivialFormatConverter,withOverlaps=yes,kernelType=%s%s) ''' % (diseaseTrack, refTrackBase, refTrackLeaf, refTrackBase, kernelType, kernelParamAssignment) #print 'BATCHLINE: <br>', batchText import hashlib hashName = hashlib.sha1(batchText).hexdigest() sf = PickleStaticFile(['files', 'Caches', 'Tool7', hashName]) #shelf = safeshelve.open(sf.getDiskPath(True)) #if batchText in shelf: if RETRIEVE_FROM_CACHE and sf.fileExists(): print ',', #print 'Retrieving batch result (%s): %s' % (sf.getDiskPath(), batchText) #return shelf[batchText] return sf.loadPickledObject() else: print '.', #print 'Running batch: ', batchText #shelf.close() batchLines = batchText.split('\n') from quick.application.GalaxyInterface import GalaxyInterface res = GalaxyInterface.runBatchLines(batchLines, username='******', printResults=False, printProgress=printProgress)[0] #global TEMP_NUM_BATCH_RUNS_SO_FAR #print 'Running batchLines (%s): %s<br>Getting result: %s<br>' % (TEMP_NUM_BATCH_RUNS_SO_FAR, batchLines, res) #TEMP_NUM_BATCH_RUNS_SO_FAR += 1 #shelf = safeshelve.open(sf.getDiskPath(True)) #shelf[batchText] = res #shelf.close() res.batchText = batchText if STORE_TO_CACHE: sf.storePickledObject(res) return res
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. ''' if GalaxyInterface._userHasFullAccess(username) or len([i for i in choices[0].split('\n') if len(i.strip())>0 and i.strip()[0]=='$'])==0: runStr = choices[0] GalaxyInterface.runBatchLines(batchLines=runStr.split('\n'), galaxyFn=galaxyFn, genome=None, username=username) else: print 'Your user does not have access to run this command line.'
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. ''' genome = choices[0] batchLines = choices[1].split('\n') assert choices[2] in ['False','True'] verbose = (choices[2] == 'True') DebugAnalysisTool.setupDebugModeAndLogging(verbose=False) #set from selection box.. try: GalaxyInterface.runBatchLines(batchLines, galaxyFn, genome, username) except Exception, e: print '</div>' print traceback.format_exc() print e raise
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_batch(cls, choices, galaxyFn=None, username=''): print GalaxyInterface.getHtmlBeginForRuns(galaxyFn) html = HtmlCore() html.header('Batch run results') refSnps = cls.get_ref_snp(choices) #print refSnps batchMal = "$Tool[hb_variant_melting_profiles](" + '|'.join( ["'%s'"] * len(choices)) + ")" cmdList = [] for rs in refSnps: #if len(rs[4]) > 1: # rs = list(rs) # rs[4] = list(rs[4])[0] # rs = tuple(rs) fakeChoices = (choices.genome, 'Single', '__batch__') + rs + choices[8:] #print rs cmdList.append(batchMal % fakeChoices) #print cmdList GalaxyInterface.runBatchLines(cmdList, galaxyFn, username=username, printResults=False, printProgress=True) #print HtmlCore().styleInfoEnd() results_tsv = GalaxyRunSpecificFile(['results.tsv'], galaxyFn) results = results_tsv.getFile() dir = os.path.dirname(results_tsv.getDiskPath()) for i in range(0, len(cmdList)): header = True ri = 0 for resultline in open(os.path.join(dir, str(i), 'results.tsv')): if header: header = False if i == 0: headertxt = '#run\t' + resultline results.write(headertxt) html.tableHeader(headertxt.split('\t')) else: results.write(str(i) + '\t' + resultline) if resultline.count('?') == 0: link = '<a href="%d/html/chart-%d.html">%d (graph)</a>' % ( i, ri, i) else: link = str(i) html.tableLine([link] + resultline.split('\t')) ri += 1 results.close() html.tableFooter() # XXX: temp fix for HB/stable bug if URL_PREFIX == '/hb': print '</div>' print '<p><b>' + results_tsv.getLink('Download results') + '</b></p>' print html print GalaxyInterface.getHtmlEndForRuns()
def directGetTestResults(diseaseTrack, refTrackLeaf, refTrackBase, kernelType, kernelParam, refTrackCoverageFunction, nullmodel, mcDepth='high', useCache=True, printProgress=False): RETRIEVE_FROM_CACHE = useCache STORE_TO_CACHE = useCache if mcDepth == 'high': mcParams = 'fdrThreshold=1.0,globalPvalThreshold=0.00002,maxSamples=50000,numResamplings=100,numSamplesPerChunk=50,mThreshold=20,fdrCriterion=simultaneous' elif mcDepth == 'relatively high': mcParams = 'fdrThreshold=1.0,globalPvalThreshold=0.0001,maxSamples=10000,numResamplings=100,numSamplesPerChunk=50,mThreshold=20,fdrCriterion=simultaneous' elif mcDepth == 'moderate': mcParams = 'fdrThreshold=1.0,globalPvalThreshold=0.001,maxSamples=1000,numResamplings=50,numSamplesPerChunk=50,mThreshold=10,fdrCriterion=simultaneous' elif mcDepth == 'low': mcParams = 'fdrThreshold=1.0,globalPvalThreshold=1.0,maxSamples=10,numResamplings=10,numSamplesPerChunk=10,mThreshold=20,fdrCriterion=simultaneous' elif mcDepth == 'extremely low': mcParams = 'fdrThreshold=1.0,globalPvalThreshold=1.0,maxSamples=2,numResamplings=2,numSamplesPerChunk=10,mThreshold=20,fdrCriterion=simultaneous' else: raise if kernelType == 'gaussian': kernelParamAssignment = ',kernelStdev=%s' % kernelParam spreadParamAssignment = ',spreadParam=%s' % kernelParam elif kernelType == 'divideByOffset': kernelParamAssignment = ',minimumOffsetValue=%s' % kernelParam spreadParamAssignment = ',spreadParam=%s' % kernelParam elif kernelType == 'binSizeNormalized': kernelParamAssignment = '' spreadParamAssignment = '' elif kernelType == 'catCoverageNormalized': kernelParamAssignment = '' spreadParamAssignment = '' elif kernelType == 'binSizeNormalizedV2': kernelParamAssignment = '' spreadParamAssignment = '' assert nullmodel in [ 'RandomGenomeLocationTrack_', 'PermutedSegsAndSampledIntersegsTrack_' ] #with last option, the end result would be about the same in the corresponding three track version.. nullmodel = 'RandomGenomeLocationTrack_' elif kernelType == 'binSizeNormalizedV3': kernelParamAssignment = '' spreadParamAssignment = '' elif kernelType == 'uniform': kernelParamAssignment = '' spreadParamAssignment = '' else: raise #RuntimeError('unre' #if nullmodel=='SegsSampledByDistanceToReferenceTrack_': # exonRefTrack = ',trackNameIntensity=Genes and gene subsets^Exons^Ensembl exons' #else: # exonRefTrack = '' import urllib if kernelType == 'binSizeNormalizedV2': batchText = ''' @TraitBins = %s @TN1=%s:%s @TN2=%s @rawStat=rawStatistic=DiffRelCoverageMainValueStat @assump=assumptions=%s @randParams=randomSeed=Random,tail=more,@assump @mcParams=%s @conv=tf1=TrivialFormatConverter,tf2=TrivialFormatConverter @kernelParams=kernelType=binSizeNormalized hg19|track|@TraitBins|@TN1|@TN2|RandomizationManagerStat(@rawStat,globalSource=userbins,@mcParams,@randParams,@conv,@kernelParams,includeFullNullDistribution=yes) ''' % (urllib.quote(diseaseTrack), refTrackBase, refTrackLeaf, refTrackBase, nullmodel, mcParams, kernelType, spreadParamAssignment, kernelParamAssignment) else: batchText = ''' @TN1= %s @TN2s=%s:%s @extraTracks=%s @binning=__chrArms__|* @rawStat=rawStatistic=ThreeTrackT2inT1vsT3inT1KernelVersionStat @assump=assumptions=%s @randParams=randomSeed=Random,tail=more,@assump @mcParams=%s @conv=tf1=TrivialFormatConverter,tf2=TrivialFormatConverter @kernelParams=kernelType=%s%s%s hg19|@binning|@TN1|@TN2s|RandomizationManagerStat(@rawStat,globalSource=userbins,@mcParams,@randParams,@conv,extraTracks=@extraTracks,@kernelParams,silentProgress=yes) ''' % (diseaseTrack, refTrackBase, refTrackLeaf, refTrackCoverageFunction, nullmodel, mcParams, kernelType, spreadParamAssignment, kernelParamAssignment) # ''' #@bins=%s #@TNs=%s:%s #@TNunion=%s #hg19|track|@bins|@TNs|@TNunion|DiffRelCoverageStat(globalSource=chrs,tf1=TrivialFormatConverter,tf2=TrivialFormatConverter,withOverlaps=yes,kernelType=%s%s) #''' % (diseaseTrack, refTrackBase, refTrackLeaf, refTrackBase,kernelType, kernelParamAssignment) #print 'BATCHLINE: <br>', batchText import hashlib hashName = hashlib.sha1(batchText).hexdigest() sf = PickleStaticFile(['files', 'Caches', 'Tool7', hashName]) if RETRIEVE_FROM_CACHE and sf.fileExists(): print ',', #print 'Retrieving batch result (%s): %s' % (sf.getDiskPath(), batchText) #return shelf[batchText] return sf.loadPickledObject() else: print '.', #print 'Running batch: ', batchText #shelf.close() batchLines = batchText.split('\n') from quick.application.GalaxyInterface import GalaxyInterface res = GalaxyInterface.runBatchLines(batchLines, username='******', printResults=False, printProgress=printProgress)[0] #print 'Running batchLines (%s): %s<br>Getting result: %s<br>' % ('', batchLines, res) #TEMP_NUM_BATCH_RUNS_SO_FAR res.batchText = batchText if STORE_TO_CACHE: sf.storePickledObject(res) return res