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 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. ''' #print 'Executing...' print GalaxyInterface.getHtmlBeginForRuns(galaxyFn) print GalaxyInterface.getHtmlForToggles(withRunDescription=False) genome = choices[1] flankSize = int(choices[3]) if choices[4] == cls.REGIONS_FROM_HISTORY: from quick.extra.tfbs.GeneTargetsOfTF import GeneTargetsOfRegions regionsTn = choices[5].split(':') GeneTargetsOfRegions.findGeneTargets(genome, regionsTn, flankSize, flankSize, galaxyFn) else: tfSource = choices[4] tfChoice = choices[5] from quick.extra.tfbs.GeneTargetsOfTF import GeneTargetsOfTF GeneTargetsOfTF.findGeneTargets(genome, tfSource, tfChoice, flankSize, flankSize, galaxyFn) print GalaxyInterface.getHtmlEndForRuns()
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 needed, can call _getStaticPath 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. ''' #print 'choices: ', choices genome = choices.genome queryTrackStr = choices.history if choices.trackSource == 'history' else choices.track queryTrack = queryTrackStr.split(':') geneSource = choices.geneSource upFlankSize = downFlankSize = int(choices.flank) print GalaxyInterface.getHtmlBeginForRuns(galaxyFn) print GalaxyInterface.getHtmlForToggles(withRunDescription=False) geneIntersection = GeneIntersection(genome, geneSource, queryTrack, galaxyFn) geneIntersection.expandReferenceTrack(upFlankSize, downFlankSize) expansionStr = ', after expansion,' if not ( upFlankSize == downFlankSize == 0) else '' print '<p>There are %i %s-genes that%s intersect elements from your query track (%s).</p>' % \ (geneIntersection.getNumberOfIntersectedBins(), geneSource, expansionStr, prettyPrintTrackName(queryTrack)) idFileNamer = geneIntersection.getGeneIdStaticFileWithContent() print '<p>', idFileNamer.getLoadToHistoryLink( 'Load to history the list', 'txt'), ' of all %s IDs intersecting query track.</p>' % ( geneSource) regFileNamer = geneIntersection.getIntersectedRegionsStaticFileWithContent( ) print '<p>', regFileNamer.getLoadToHistoryLink( 'Load to history a BED file', 'bed'), ' of all %s gene regions intersecting query track.</p>' % ( geneSource) print GalaxyInterface.getHtmlEndForRuns()
def execute(self, printHtmlBeginEnd=True, printTrackNamesTable=True): print GalaxyInterface.getHtmlBeginForRuns(self._galaxyFn) core = HtmlCore() if printTrackNamesTable: core.divBegin('trackNames') dataDict = OrderedDict([(x, []) for x in self._trackNames]) tblExpandable = True if len(self._trackNames) < 11: tblExpandable = False core.tableFromDictionary(dataDict, ['Tracks under analysis'], tableId="resTable", expandable=tblExpandable) # core.tableHeader(['Tracks under analysis:']) # for trackName in self._trackNames: # core.tableLine([trackName]) # core.tableFooter() core.divEnd() print core try: results = GalaxyInterface.run(self._tracks[0], self._tracks[1], self.getAnalysisDefinitionString(), self._regSpec, self._binSpec, self._genome, self._galaxyFn, printRunDescription=False, printHtmlBeginEnd=printHtmlBeginEnd, fromMainTool=False) if self.hasVisualization(): print self.visualizeResults(results) # except: # pass finally: core2 = HtmlCore() core2.hideToggle(styleClass='infomessagesmall') print core2 print GalaxyInterface.getHtmlEndForRuns()
def writeGSuiteHiddenTrackStorageHtml(galaxyFn): from proto.config.Config import URL_PREFIX from proto.hyperbrowser.HtmlCore import HtmlCore from quick.application.GalaxyInterface import GalaxyInterface core = HtmlCore() core.append(GalaxyInterface.getHtmlBeginForRuns(galaxyFn)) core.paragraph( 'This history element contains GSuite track data, and is hidden by default.' ) core.paragraph( 'If you want to access the contents of this GSuite, please use the tool: ' '%s, selecting ' 'a primary GSuite history element that refers to the files contained ' 'in this storage.' % str(HtmlCore().link( 'Export primary tracks from a GSuite to your history', createGalaxyToolURL('hb_g_suite_export_to_history_tool')))) core.end() core.append(GalaxyInterface.getHtmlEndForRuns()) with open(galaxyFn, 'w') as outputFile: outputFile.write(str(core))
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.application.GalaxyInterface import GalaxyInterface from proto.hyperbrowser.HtmlCore import HtmlCore print GalaxyInterface.getHtmlBeginForRuns(galaxyFn) print GalaxyInterface.getHtmlForToggles(withRunDescription=False) print str(HtmlCore().styleInfoBegin(styleClass='debug')) from quick.application.ExternalTrackManager import ExternalTrackManager datasetId = ExternalTrackManager.extractIdFromGalaxyFn(ExternalTrackManager.extractFnFromGalaxyTN(choices[0]))[1] #print datasetId #print choices ##batchid = index for kjoering i batch. Ikke-batch-kjoering: 0 #batchid = 0 ##mapId = Definer hva slags type innhold i Google map-bokser (naar du trykker). Innholdet er definert (hardkodet) i GoogleMapsInterface.py: getHtmlText() og getClusterHtmlText() ##Eks: encode_tf_vs_tf if choices[1] != 'make new map id': mapId = choices[1] else: mapId = choices[2] from quick.application.ExternalTrackManager import ExternalTrackManager histHtml = open(ExternalTrackManager.extractFnFromGalaxyTN(choices[0].split(':'))).read() #rowTrackName = histHtml.split('<h3>TRACK 1</h3>')[-1].split('</b>')[1].split('\n')[0].strip()#.split(':') #colTrackName = histHtml.split('<h3>TRACK 2</h3>')[-1].split('</b>')[1].split('\n')[0].strip()#.split(':') from quick.application.GalaxyInterface import GalaxyInterface batchLine = histHtml.split('<h3>CORRESPONDING BATCH COMMAND LINE</h3>')[-1].split('<p>')[1].split('/p')[0].strip() genome = histHtml.split('<h3>GENOME</h3>')[-1].split('name:</b>')[1].split('<')[0].strip() fullAccess = GalaxyInterface.userHasFullAccess(username) from quick.batch.BatchRunner import BatchRunner batchContents = BatchRunner.parseBatchLine(batchLine, genome, fullAccess) rowTrackName = ':'.join(batchContents.cleanedTrackName1) colTrackName = ':'.join(batchContents.cleanedTrackName2) from quick.extra.CreateGoogleMapType import createMapType createMapType(mapId, genome, rowTrackName, colTrackName, 'None', 'None', 'None') from config.Config import HB_SOURCE_CODE_BASE_DIR GMapInterfaceFn = HB_SOURCE_CODE_BASE_DIR+'/quick/extra/GoogleMapsInterface.py' GMapInterfaceContent = open(GMapInterfaceFn).read() replaceStr = "'%s', 'encode_gwas_vs_dhs'" % mapId GMapInterfaceContent = GMapInterfaceContent.replace("'encode_gwas_vs_dhs'", replaceStr) open(GMapInterfaceFn,'w').write(GMapInterfaceContent) #title = navn paa Regulomet slik brukeren ser det, Eks: "ENCODE test, TFs vs TFs" title = choices[3] ##name = navn paa katalog for google map: Eks: encode_test_tf_vs_tf name = choices[4] from quick.extra.CreateGoogleMap import GoogleMapCreator from quick.extra.GoogleMapsInterface import Map onMedSeqProd = False #batchid creator = GoogleMapCreator(name, datasetId, mapId, genome=genome) creator.tile(onMedSeqProd) creator.copyResultFiles() creator.createResultShelves() creator.createIndexFile(title, genome) creator.fixPermissions() print str(HtmlCore().styleInfoEnd()) map = Map(name) row = [] row.append( str(HtmlCore().link(map.getPrettyName(), map.getUrl())) ) row.append( str(HtmlCore().link('Run description', map.getRunDescriptionUrl())) ) row.append( str(HtmlCore().link('Counts', map.getCountUrl())) ) row.append( str(HtmlCore().link('Effect size', map.getEffectSizeUrl())) ) row.append( str(HtmlCore().link('P-values', map.getPvalUrl())) ) core = HtmlCore() core.tableHeader(None) core.tableLine(row) core.tableFooter() print core print GalaxyInterface.getHtmlEndForRuns()
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 execute(cls, choices, galaxyFn=None, username=''): path = str(URL_PREFIX) dataset = choices.dataset genome = choices.genome text = choices.newtrack secondDataset = choices.newdataset inputFile = open(ExternalTrackManager.extractFnFromGalaxyTN(dataset), 'r') with inputFile as f: data = [x for x in f.readlines()] silenceRWarnings() binSourceParam = '*' regSourceParam = '*' trackNamePrep = cls.preprocessTrack(genome, dataset) if text == 'No': figUrl = '' if (len(data) > 30000): core = HtmlCore() core.styleInfoBegin(styleClass='debug') figImage = GalaxyRunSpecificFile(['VizTrackOnGenome.png'], galaxyFn) analysisDef = ' [normalizeRows=%s] [centerRows=%s] -> RawVisualizationDataStat' res = GalaxyInterface.runManual([trackNamePrep], analysisDef, regSourceParam, binSourceParam, genome, username=username, printResults=False, printHtmlWarningMsgs=False) core.styleInfoEnd() core.line('') core.tableHeader(None) rScript = VisualizeTrackPresenceOnGenome.customRExecution( res, figImage.getDiskPath(ensurePath=True), '') figUrl = figImage.getURL() print GalaxyInterface.getHtmlEndForRuns() binSourceParam = '10m' regSourceParam = '*' cls.resultPrintGeneric(genome, binSourceParam, regSourceParam, figUrl, path, trackNamePrep) else: if isinstance(trackNamePrep[0], (list, )): numTracks = len(trackNamePrep[0]) firstTrack = cls.prepareTracknameForURL(trackNamePrep[0]) trackTitle = json.dumps(trackNamePrep[1]) cls.resultPrintGSuite(genome, binSourceParam, regSourceParam, figUrl, path, firstTrack, trackTitle, numTracks) else: firstTrack = cls.prepareTracknameForURL(trackNamePrep) cls.resultPrintGeneric(genome, binSourceParam, regSourceParam, figUrl, path, firstTrack) else: trackName2 = cls.preprocessTrack(genome, secondDataset) firstTrack = cls.prepareTracknameForURL(trackNamePrep) secondTrack = cls.prepareTracknameForURL(trackName2) cls.resultPrintOverlap(genome, binSourceParam, regSourceParam, path, firstTrack, secondTrack)
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. ''' genome = choices[0] regSpec = '__chrs__' binSpec = '*' if choices[6] == 'Chromosome arms': regSpec = '__chrArms__' elif choices[6] == 'Track from history...': #put in history bins support here #print choices[4:] regSpec = ExternalTrackManager.extractFileSuffixFromGalaxyTN(choices[7].split(':')) binSpec = ExternalTrackManager.extractFnFromGalaxyTN(choices[7].split(':')) #print 'regSpec, binSpec,', regSpec, binSpec lineList, counter, tooManyBins = [], 0, False for line in open(binSpec): if line.strip() !='': if counter == cls.MAX_NUM_ROWS: tooManyBins = True break lineList.append(line) counter+= 1 if line.strip()[0] !='#' else 0 if tooManyBins: newHist = GalaxyRunSpecificFile(['newHistFile.%s' % regSpec], galaxyFn) binSpec = newHist.getDiskPath(ensurePath=True) open(binSpec, 'w').write(''.join(lineList)) print GalaxyInterface.getHtmlBeginForRuns(galaxyFn) print GalaxyInterface.getHtmlForToggles(withRunDescription=False) core = HtmlCore() core.styleInfoBegin(styleClass='debug') figImage = GalaxyRunSpecificFile(['VizTrackOnGenome.png'], galaxyFn) #StaticImage(['VizTrackOnGenome.png']) analysisDef = ' [normalizeRows=%s] [centerRows=%s] -> RawVisualizationDataStat' % \ (choices[4] == 'Scale to same size', choices[5] == 'Center') if choices[1] == 'HyperBrowser repository': trackName = choices[2].split(':') else: trackName = ExternalTrackManager.getPreProcessedTrackFromGalaxyTN(genome, choices[3].split(':')) res = GalaxyInterface.runManual([trackName], analysisDef, regSpec, binSpec, genome, username=username, printResults=False, printHtmlWarningMsgs=False) core.styleInfoEnd() core.line('') core.tableHeader(None) #visPresenter = RawVisualizationPresenter(res, galaxyFn,'')#os.path.split()[0] #htmlStreng = visPresenter.getReference('Result', fullImage=True) rScript = cls.customRExecution(res, figImage.getDiskPath(ensurePath=True), '') figUrl = figImage.getURL() figLinkText ='<img src="%s" alt="Figure" height="%i" width="800"/>' % (figUrl, 20 *min(cls.MAX_NUM_ROWS, len(res))) core.tableLine([figImage.getLink(figLinkText)]) rScriptGalaxyFile = GalaxyRunSpecificFile(['RScript.R'], galaxyFn) with open(rScriptGalaxyFile.getDiskPath(ensurePath=True), 'w') as rScriptFile: rScriptFile.write(rScript) core.tableLine([rScriptGalaxyFile.getLink('R script')]) core.tableFooter() print core print GalaxyInterface.getHtmlEndForRuns()