def getIntersectedRegionsStaticFileWithContent(self): intersectedRegs = self.getIntersectedReferenceBins() staticFile = GalaxyRunSpecificFile( self._getFileId('intersected_regions.bed'), self._galaxyFn) self.writeRegionListToBedFile(intersectedRegs, staticFile.getDiskPath()) return staticFile
def __init__(self, tf, chipSeqPeaks, pwm, tracks, galaxyFn): self.tf = tf self.chipSeqPeaks = chipSeqPeaks self.pwm = pwm assert len(tracks) == 2 self.track = tracks[0] self.mutationTrack = tracks[1] self.galaxyFn = galaxyFn self.bedPwmDiffScore = GalaxyRunSpecificFile( ['pwmDiffScore', self.pwm + '_'.join(self.track), 'pwmDiff.bed'], self.galaxyFn) self.pwmDiffScore = GalaxyRunSpecificFile( ['pwmDiffScore', self.pwm + '_'.join(self.track), 'pwmDiff.html'], self.galaxyFn) self.gtrackDiffScore = GalaxyRunSpecificFile([ 'pwmDiffScore', self.pwm + '_'.join(self.track), 'pwmDiff.gtrack' ], self.galaxyFn) self.mutatedFasta = GalaxyRunSpecificFile( ['fastaFiles', '_'.join(self.track), 'mutatedFastseq.fasta'], self.galaxyFn) self.regularFasta = GalaxyRunSpecificFile( ['fastaFiles', '_'.join(self.track), 'regularFastseq.fasta'], self.galaxyFn) self.maxPwmDiff = None self.avgPwmDiff = None self.numPwmDiff = 0
def MakeGlobalResultsDiv(cls, totResDict, visResults, core, galaxyFn): #core.divBegin(divId='globalResDiv', style='display:none') core._str+='<div class="tabbertab">\n <h2>Global Result</h2>\n<div class="tabber" id="GlobalRes">\n' # tab for table yLabels = sorted([v for v in totResDict.keys() if v]) dataList = [totResDict[v] for v in yLabels] xLabels = ['Gene source', 'Exon area', 'Intron area', 'Inter-gene area', 'Total'] if len(yLabels)>0: core._str += '<div class="tabbertab">\n <h2>Table</h2>\n' cls.makeHtmlTable(dataList, xLabels, yLabels, 'Global', core, 'Normal') core._str+='</div>\n' core._str += '<div class="tabbertab">\n <h2>Visualization</h2>' figImage = GalaxyRunSpecificFile(['VizTrackOnGenome.png'], galaxyFn) cls.makeTrackImage(visResults, figImage.getDiskPath(ensurePath=True), '') figUrl = figImage.getURL() core.line('<img src="%s" alt="Figure" height="%i" width="800"/>' % (figUrl, max([200,30*min(100, len(visResults))]) )) if len(yLabels)>0: cls.putPieChartsOnPage('', core, xLabels, yLabels, dataList) core._str+='</div>\n</div>\n</div>\n'
def execute(cls, choices, galaxyFn=None, username=''): #rsids = choices.rsid.split() if choices.run == 'Batch': #print rsids return cls.execute_batch(choices, galaxyFn, username) elif choices.batch != '__batch__': print '<div class="debug">' results = GalaxyRunSpecificFile(['html'], galaxyFn) dir = os.path.dirname(results.getDiskPath(ensurePath=True)) os.mkdir(dir + '/html') #print '<div class="debug">' cls.choices = choices cls.run_varmelt(dir, choices) url = results.getURL() if choices.run == 'Single' and choices.batch != '__batch__': print '</div></pre>' core = HtmlCore() core.header('Primer3 candidates') VariantMeltingProfile.primer3_table_header(core) VariantMeltingProfile.primer3_resultsfile_header(dir) for r in range(0, int(choices.numReturn)): datafile = dir + '/tempdata.' + str(r) + '.results.txt' if os.path.exists(datafile): variant_pos = VariantMeltingProfile.proc_temp_data(dir, str(r)) chart = open(dir + '/html/chart-' + str(r) + '.html', 'w') chart.write(VariantMeltingProfile.make_chart(variant_pos, r)) chart.write(cls.primer3_results_table(dir, r)) chart.write('</body></html>') chart.close() cls.primer3_results(dir, r) cls.primer3_results_table(dir, r, core, url) print '<a href="%s/chart-%d.html">Results/graph num %d</a><br>' % ( url, r, r + 1) else: cls.primer3_results(dir, r) cls.primer3_results_table(dir, r, core, None) break core.tableFooter() if choices.run == 'Single' and choices.batch != '__batch__': print str(core) print '<pre>' xcore = HtmlCore() xcore.begin() xcore.append(str(core)) xcore.end() open(dir + '/results.html', 'w').write(str(xcore))
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. ''' if choices[2]=='Transfac TF ids': mappingFn = 'pwm2TFids.shelf' mapping = safeshelve.open(Tool1.MAPPING_SHELVES_PATH + os.sep + mappingFn ) elif choices[2]== 'Transfac TF readable names': mappingFn = 'pwm2TFnamesNew.shelf' mapping = safeshelve.open(Tool1.MAPPING_SHELVES_PATH + os.sep + mappingFn ) elif choices[2]== 'HGNC gene symbols': mappingFn = 'PWM_to_HGNC.txt' mapping = dict([line.strip().split() for line in open(Tool1.MAPPING_SHELVES_PATH + os.sep + mappingFn).readlines()]) else: raise Exception(choices[2]) if galaxyFn==None: for key in sorted(mapping.keys()): print key + ':' + ','.join(mapping[key]) + os.linesep, else: mappingStaticFile = GalaxyRunSpecificFile(['mapping.txt'], galaxyFn) f = mappingStaticFile.getFile() for key in sorted(mapping.keys()): if type(mapping[key]) in (list,tuple): mapping[key] = ','.join(mapping[key]) f.write( key + ':' + mapping[key] + os.linesep ) f.close() print mappingStaticFile.getLink('View/download mapping')
def findGeneTargets(genome, regionsTn, upFlankSize, downFlankSize, galaxyFn): assert genome in ['hg18','hg19','mm9'] #tfTrackNameMappings = TfInfo.getTfTrackNameMappings(genome) #tfTrackName = tfTrackNameMappings[tfSource] + [selectedTF] geneIntersection = GeneIntersection(genome, 'Ensembl', regionsTn, galaxyFn) geneIntersection.expandReferenceTrack(upFlankSize, downFlankSize) expansionStr = ' flanked' if not (upFlankSize == downFlankSize == 0) else '' #print '<p>There are %i Ensemble genes being targets of your selected TF (%s), based on intersecting TF target positions with%s %sgene regions.</p>' % (geneIntersection.getNumberOfIntersectedBins(), selectedTF, expansionStr, 'Ensembl') print '<p>There are %i Ensemble genes being targets of your selected regions, based on intersecting your supplied regions with%s %sgene regions.</p>' % (geneIntersection.getNumberOfIntersectedBins(), expansionStr, 'Ensembl') idFileNamer = geneIntersection.getGeneIdStaticFileWithContent() print '<p>', idFileNamer.getLink('Download list'), ' of all Ensemble IDs with 1 or more hits.</p>' regFileNamer = geneIntersection.getIntersectedRegionsStaticFileWithContent() print '<p>', regFileNamer.getLink('Download bed-file'), ' of all Ensembl gene regions with 1 or more hits.</p>' targetBins = geneIntersection.getIntersectedReferenceBins() res = geneIntersection.getIntersectionResult() resDictKey = geneIntersection.getUniqueResDictKey() setOfNumOccurrences = set([res[bin][resDictKey] for bin in targetBins]) byNumOccurrencesStaticFile = GalaxyRunSpecificFile(['genes_by_num_occurrences.html'], galaxyFn) f = byNumOccurrencesStaticFile.getFile() for numOccurrences in reversed(sorted(setOfNumOccurrences)): f.write('Gene regions having %i occurrences:<br>' % numOccurrences + '<br>' + os.linesep) f.write(', '.join([ '<a href=http://www.ensembl.org/Homo_sapiens/Gene/Summary?g='+str(bin.val).split('|')[0]+'>'+str(bin.val).split('|')[0]+'</a>' for bin in targetBins if res[bin][resDictKey]==numOccurrences]) + '<br><br>' + os.linesep) f.close() print '</p>Inspect list of all intersected genes (by ID), ', byNumOccurrencesStaticFile.getLink('ordered by number of occurrences') + ' inside, and with links to gene descriptions.<br>'
def getGeneIdStaticFileWithContent(self): targetBins = self.getIntersectedReferenceBins() idFileNamer = GalaxyRunSpecificFile(self._getFileId('allGeneIds.txt'), self._galaxyFn) idFileNamer.writeTextToFile( os.linesep.join([str(bin.val).split('|')[0] for bin in targetBins]) + os.linesep) return idFileNamer
def makeHtmlStr(self): htmlPage = GalaxyRunSpecificFile( ['html', '_'.join(self.track), 'page.html'], self.galaxyFn) htmlStr = 'TF: ' + self.tf + '<br/>\nChip-seq peaks: ' + self.chipSeqPeaks + '<br/>\nPWM: ' + self.pwm + '<br/>\nNumber of SNV-intersected binding regions: ' + self.intersectingPoints + '<br/>\nHighest binding difference: ' + self.maxPwmDiff + '<br/>\nAvg binding difference: ' + self.avgPwmDiff + '<br/>\n' + self.regularFasta.getLink( 'Original Fasta') + '<br/>\n' + self.mutatedFasta.getLink( 'Mutated Fasta') + '<br/>\n' + self.pwmDiffScore.getLink( 'PWM score for each region' ) + '<br/>\n' + self.gtrackDiffScore.getLink( 'Gtrack of PWM score for each region') htmlPage.writeTextToFile(htmlStr) return htmlPage.getLink(self.tf + ': ' + self.track[-1])
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 time import time startTime = time() from quick.application.ExternalTrackManager import ExternalTrackManager from proto.hyperbrowser.StaticFile import GalaxyRunSpecificFile motifFn = ExternalTrackManager.extractFnFromGalaxyTN( choices[0].split(':')) observedFasta = ExternalTrackManager.extractFnFromGalaxyTN( choices[1].split(':')) randomGalaxyTN = choices[2].split(':') randomName = ExternalTrackManager.extractNameFromHistoryTN( randomGalaxyTN) randomGalaxyFn = ExternalTrackManager.extractFnFromGalaxyTN( randomGalaxyTN) randomStatic = GalaxyRunSpecificFile( ['random'], randomGalaxyFn ) #finds path to static file created for a previous history element (randomFn), and directs to a folder containing several files.. #print os.listdir(randomStatic.getDiskPath()) randomFastaPath = randomStatic.getDiskPath() #motifFn, observedFasta, randomFastaPath = '/Users/sandve/egne_dokumenter/_faglig/NullModels/DnaSeqExample/liver.pwm', 'liver.fa', 'randomFastas' testStatistic = choices[3] if testStatistic == 'Average of max score per sequence': scoreFunc = scoreMotifOnFastaAsAvgOfBestScores elif testStatistic == 'Sum of scores across all positions of all sequences': scoreFunc = scoreMotifOnFastaAsSumOfAllScores elif testStatistic == 'Score of Frith et al. (2004)': scoreFunc = lr4 elif testStatistic == 'Product of max per sequence': scoreFunc = scoreMotifOnFastaAsProductOfBestScores else: raise pvals = mcPvalFromMotifAndFastas(motifFn, observedFasta, randomFastaPath, scoreFunc) print 'Pvals for motifs (%s) against observed (%s) vs random (%s - %s) sequences.' % ( motifFn, observedFasta, randomName, randomFastaPath) for motif, pval in sorted(pvals.items()): print motif + '\t' + ('%.4f' % pval) from proto.hyperbrowser.StaticFile import GalaxyRunSpecificFile from proto.RSetup import robjects histStaticFile = GalaxyRunSpecificFile(['pvalHist.png'], galaxyFn) #histStaticFile.openRFigure() histStaticFile.plotRHist(pvals.values(), [x / 40.0 for x in range(41)], 'Histogram of p-values', xlim=robjects.FloatVector([0.0, 1.0])) #r.hist(robjects.FloatVector(pvals.values()), breaks=robjects.FloatVector([x/40.0 for x in range(41)]), xlim=robjects.FloatVector([0.0, 1.0]), main='Histogram of p-values' ) #histStaticFile.closeRFigure() print histStaticFile.getLink('Histogram') print 'Time (s):', time() - startTime
def collectParamsIntoFile(self): parameters = GalaxyRunSpecificFile(['run_parameters.html'],self.jobFile) #just collect the parametes used into a file p_path = parameters.getDiskPath(True) p_output = open(p_path,'w') print>>p_output, '<html><body>' print>>p_output, '<ol>' for key in self.params.keys(): print>>p_output, '<li>%s:%s </li>'%(key,self.params[key]) print>>p_output, '</body></html>' p_output.close() print parameters.getLink('Parameters of this run')
def execute(self, imageFn, html, dpi=None): #galaxyId = extractIdFromGalaxyFn(html) #outDir = getUniqueWebPath(galaxyId) staticDir = GalaxyRunSpecificFile([], html) outDir = staticDir.getDiskPath() try: os.makedirs(outDir + '/tiles') except OSError, e: if e.errno == errno.EEXIST: print e else: raise e
def getLinkToSingleLocalHtmlResultsTable(self, linkText, disease, resDictKey, galaxyFn): core = HtmlCore() core.begin() core.paragraph( self.getHtmlLocalResultsTable(resDictKey, fillInNoneValues=True)) core.end() staticFile = GalaxyRunSpecificFile( ['LocalResultTables', resDictKey, disease + '.html'], galaxyFn) staticFile.writeTextToFile(str(core)) return staticFile.getLink(linkText)
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...' genome = choices[0] galaxyTN = choices[1].split(':') #print 'galaxyTN: ',galaxyTN , type(galaxyTN) fn = ExternalTrackManager.extractFnFromGalaxyTN(galaxyTN) print 'Disk path for selected history element: <br>%s<br><br>' % fn from proto.hyperbrowser.StaticFile import GalaxyRunSpecificFile staticFile = GalaxyRunSpecificFile([],fn) print 'HyperBrowser data path (static file path) corresponding to selected history element: <br>%s<br><br>' % staticFile.getDiskPath() from config.Config import EXT_PROCESSED_DATA_PATH try: tn = ExternalTrackManager.getStdTrackNameFromGalaxyTN(galaxyTN)[:-1] preProcPath = '/'.join([EXT_PROCESSED_DATA_PATH,'100000','noOverlaps',genome] + tn) import os lastTnPart = os.listdir(preProcPath) assert len(lastTnPart)==1, lastTnPart #preProcPath += '/'+lastTnPart[0] tn += lastTnPart preProcPath = '/'.join([EXT_PROCESSED_DATA_PATH,'100000','noOverlaps',genome] + tn) print 'HyperBrowser pre-processed track name (if applicable): <br>%s<br><br>' % tn print 'HyperBrowser pre-processed track path (if applicable): <br>%s<br><br>' % preProcPath except: print '(Not printing track name, as history element does not appear to be a (valid) track.)<br>' print 'HyperBrowser URL path (static file URL) corresponding to selected history element: <br>%s<br><br>' % staticFile.getURL() # Does not work correctly, as the id needs to be the history id, and not the dataset id, # which may be different. Dataset id may perhaps be found from history id in the following manner (untested): # # data = trans.sa_session.query( trans.app.model.HistoryDatasetAssociation ).get( trans.security.decode_id( history_id ) ) # dataset_id = extractIdFromGalaxyFn(data.file_name) # # Not sure how to go the other way. # #from quick.util.CommonFunctions import extractIdFromGalaxyFn #from galaxy.web.security import SecurityHelper #from config.Config import GALAXY_ID_SECRET #secHelper = SecurityHelper(id_secret=GALAXY_ID_SECRET) #id = extractIdFromGalaxyFn(galaxyFn) #encodedId = secHelper.encode_id(id[1]) #print 'Galaxy URL id: <br>%s<br><br>' % encodedId import os.path, time print "Time of creation for Galaxy history file: %s" % time.ctime(os.path.getctime(fn)) print "Last modification for Galaxy history file: %s" % time.ctime(os.path.getmtime(fn))
def storePickledResults(self): try: from cPickle import dump pickleStaticFile = GalaxyRunSpecificFile(['results.pickle'], self._galaxyFn) from copy import copy pickleList = [copy(res) for res in self._resultsList] #for res in pickleList: # res._analysis=None dump(pickleList, pickleStaticFile.getFile()) #dump(self._resultsList, pickleStaticFile.getFile()) except Exception, e: logException(e, message='Not able to pickle results object')
def MakeHeatmapFromTracks(cls, tr1, tr2=None, tr3=None): tableRowEntryTemplate = """<tr><td>%s</td><td><a href="%s"><img src="%s" /></a></td></tr>""" htmlPageTemplate = """<html><body><table border="1">%s</table></body></html>""" #fileDict = dict() tr1, tr2, tr3 = [ExternalTrackManager.extractFnFromGalaxyTN(x.split(':')) if x != '----- select -----' else None for x in choices[1:] ] ResultDicts = [] maxVals = [] for tr,color in [(tr1, (1,0,0)),(tr2, (0,1,0)),(tr3, (0,0,1))]: if tr: res, maxVal = getValuesFromBedFile(tr,color) ResultDicts += [res] maxVals.append(maxVal) else: maxVals.append(None) #ResultDicts += [getValuesFromBedFile(tr2,colorPattern=(0,1,0))] if tr2 else [] htmlTableContent = [] resultDict = syncResultDict(ResultDicts) for chrom, valList in resultDict.items(): areaList = [] #For doing recursive pattern picture posMatrix = cls.getResult(len(valList), 2,2) javaScriptList = [[0 for v in xrange(len(posMatrix[0])) ] for t in xrange(len(posMatrix))] rowLen = len(posMatrix[0]) im = Image.new("RGB", (rowLen, len(posMatrix)), "white") for yIndex, row in enumerate(posMatrix): for xIndex, elem in enumerate(row): im.putpixel((xIndex, yIndex), valList[elem]) region = yIndex*rowLen + xIndex javaScriptList[yIndex][xIndex] = chrom+':'+str(elem*10)+'-'+str((elem+1)*10)+': '+repr([ round((255-v)/255.0 ,2 ) for v in valList[elem]]) #areaList.append(areaTemplate % (xIndex*10, yIndex*10, xIndex*11, yIndex*11, repr(valList[elem]))) im2 = im.resize((len(posMatrix[0])*10, len(posMatrix)*10)) fileElements = [GalaxyRunSpecificFile(['Recursive', chrom+'.png' ], galaxyFn), GalaxyRunSpecificFile(['Recursive', chrom+'Big.png' ], galaxyFn), GalaxyRunSpecificFile(['Recursive', chrom+'Zooming.html' ], galaxyFn)] #fileDict['Recursive/'+chrom] = fileElements im.save(fileElements[0].getDiskPath(ensurePath=True)) im2.save(fileElements[1].getDiskPath(ensurePath=True)) open(fileElements[2].getDiskPath(ensurePath=True),'w').write(htmlTemplate % (str(javaScriptList), fileElements[1].getURL(), fileElements[0].getURL())) htmlTableContent.append(tableRowEntryTemplate % (chrom, fileElements[2].getURL(), fileElements[0].getURL()))
def getHiCFileFromTargetBins(targetBins, galaxyFn): from proto.hyperbrowser.StaticFile import GalaxyRunSpecificFile staticFile = GalaxyRunSpecificFile(['PEI_regions.bed'], galaxyFn) fn = staticFile.getDiskPath() from quick.util.CommonFunctions import ensurePathExists ensurePathExists(fn) f = open(fn, 'w') import os for region in targetBins: chrom = region[0] start = region[1] end = region[2] f.write('\t'.join([chrom, str(start), str(end)]) + os.linesep) f.close() return staticFile
def _getResultsLists(histChoices): if len([x for x in histChoices.values() if x is not None]) == 0: return [], [] galaxyTNs = [ x.split(':') for x in histChoices.values() if x is not None ] galaxyFns = [ ExternalTrackManager.extractFnFromGalaxyTN(tn) for tn in galaxyTNs ] historyNames = [ ExternalTrackManager.extractNameFromHistoryTN(tn) for tn in galaxyTNs ] staticFiles = [ GalaxyRunSpecificFile(['results.pickle'], gfn) for gfn in galaxyFns ] #fileSpecificFile = [GalaxyRunSpecificFile([], gfn) for gfn in galaxyFns] #paths = [x.getDiskPath()+'/0' for x in fileSpecificFile] #pngList = [[v for v in x[2] if v.find('.png')>0] for x in os.walk(paths[0])] try: resultsLists = [load(sf.getFile('r')) for sf in staticFiles] except: resultsLists = [] return resultsLists, historyNames
def createShelvesBehindRankedGeneLists(galaxyId, mapId, countType): 'galaxyId mapId countType' batchid='0' resultsBaseDirStatic = '/work/hyperbrowser/results/developer/static' homeDirOnInsilico = '/xanadu/home/sveinugu' colldir = ('%.3f' % (int(galaxyId)/1000 *1.0 / 1000))[2:] #hent txt from quick.util.CommonFunctions import getGalaxyFnFromDatasetId from proto.hyperbrowser.StaticFile import GalaxyRunSpecificFile galaxyFn = getGalaxyFnFromDatasetId(id) resultsStaticDir = GalaxyRunSpecificFile([batchid], galaxyFn).getDiskPath() #legg shelf googleMapsCommonDir = '/'.join([STATIC_PATH, 'maps', 'common',str(mapId)]) disease2geneShelfFn = googleMapsCommonDir+os.sep + 'col2GeneList.shelf' geneAndTf2TfbsCountShelfFn = googleMapsCommonDir+os.sep + 'rowAndGene2count.shelf' rankedGeneListShelfFn = googleMapsCommonDir+os.sep + 'rowAndCol2rankedGeneList.shelf' resultTableTxtFn = resultsStaticDir+'/Result_table.txt' assert os.path.exists(resultTableTxtFn), 'Did not find Galaxy results file: ' + resultTableTxtFn assert os.path.exists(disease2geneShelfFn), 'Did not find col2GeneList shelf: ' + disease2geneShelfFn parseMatrixTextFileToShelf(resultTableTxtFn, geneAndTf2TfbsCountShelfFn, countType=countType) #geneAndTf2tfbsCount = safeshelve.open(geneAndTf2TfbsCountShelfFn,'r') _createTfAndDisease2RankedGeneListMapping(disease2geneShelfFn, geneAndTf2TfbsCountShelfFn, rankedGeneListShelfFn)
def getReference(self, resDictKey): globalRes = self._results.getGlobalResult() htmlObj = GalaxyRunSpecificFile(['test.html'], self._baseDir) fileObj = open(htmlObj.getDiskPath(ensurePath=True), 'w') #fileObj.write( 'globalRes ' + str(globalRes)) htmlText = CreateBpsVennDIagram.getHtmlString( globalRes['result']['catInfo'], globalRes['result']['stateBPCounter'], globalRes['result']['genome']) fileObj.write(htmlText) fileObj.close() return htmlObj.getLink('link to results') return str(globalRes) return strWithStdFormatting( globalRes[resDictKey]) if globalRes not in [None, {}] else 'None'
def addTableWithTabularAndGsuiteImportButtons(core, choices, galaxyFn, shortQuestion, tableDict, columnNames, gsuite=None, results=None, gsuiteAppendAttrs=None, **kwArgsForTable): def _produceTable(core, tableDict=None, columnNames=None, tableId=None, **kwArgs): return core.tableFromDictionary(tableDict, columnNames=columnNames, tableId=tableId, addInstruction=True, **kwArgs) tableId = 'resultsTable' tableFile = GalaxyRunSpecificFile([tableId, 'table.tsv'], galaxyFn) tabularHistElementName = 'Raw results: ' + shortQuestion if gsuite: gsuiteFile = GalaxyRunSpecificFile( [tableId, 'input_with_results.gsuite'], galaxyFn) GSuiteStatUtils.addResultsToInputGSuite(gsuite, results, gsuiteAppendAttrs, gsuiteFile.getDiskPath()) gsuiteHistElementName = \ getGSuiteHistoryOutputName('result', ', ' + shortQuestion, choices.gsuite) core.tableWithImportButtons( tabularFile=True, tabularFn=tableFile.getDiskPath(), tabularHistElementName=tabularHistElementName, gsuiteFile=True, gsuiteFn=gsuiteFile.getDiskPath(), gsuiteHistElementName=gsuiteHistElementName, produceTableCallbackFunc=_produceTable, tableDict=tableDict, columnNames=columnNames, tableId=tableId, **kwArgsForTable) else: core.tableWithImportButtons( tabularFile=True, tabularFn=tableFile.getDiskPath(), tabularHistElementName=tabularHistElementName, produceTableCallbackFunc=_produceTable, tableDict=tableDict, columnNames=columnNames, tableId=tableId, **kwArgsForTable)
def getFileFromTargetBins(targetBins, galaxyFn, subDirId=None): staticFile = GalaxyRunSpecificFile( ([subDirId] if subDirId else []) + ['intersected_regions.bed'], galaxyFn) fn = staticFile.getDiskPath() from quick.util.CommonFunctions import ensurePathExists ensurePathExists(fn) f = open(fn, 'w') for region in targetBins: tmp = region[0].split(':') chrom = tmp[0] tmp2 = tmp[1].split('-') start = tmp2[0] end = tmp2[1] tfs = region[1] f.write('\t'.join([chrom, str(start), str(end), tfs]) + os.linesep) f.close() return staticFile
def __init__(self, resultsList, galaxyFn): self._viewers = [] self._resultsList = resultsList self._galaxyFn = galaxyFn baseDir = GalaxyRunSpecificFile([], galaxyFn).getDiskPath() if len(resultsList) > 1: self._viewers.append(MultiBatchResultsViewer(resultsList, baseDir)) for i, results in enumerate(resultsList): self._viewers.append( ResultsViewer(results, os.sep.join([baseDir, str(i)])))
def expandReferenceTrack(self, upFlankSize, downFlankSize): if not (upFlankSize == downFlankSize == 0): self._intersectedReferenceBins = None flankedGeneRegsTempFn = GalaxyRunSpecificFile( self._getFileId('flankedGeneRegs.category.bed'), self._galaxyFn).getDiskPath() GalaxyInterface.expandBedSegments(self._referenceTrackFn, flankedGeneRegsTempFn, self._genome, upFlankSize, downFlankSize) self._referenceTrackFn = flankedGeneRegsTempFn
def execute(cls, choices, galaxyFn=None, username=''): histItem = choices[0].split(':') filSuffix = ExternalTrackManager.extractFileSuffixFromGalaxyTN( histItem) histFile = ExternalTrackManager.extractFnFromGalaxyTN(histItem) galaxyOutputFile = GalaxyRunSpecificFile(['circos.png'], galaxyFn) outputFn = galaxyOutputFile.getDiskPath(True) type = 'line' if filSuffix == 'bedgraph' else 'highlight' paramDict = {histFile: {'type': type, 'r0': '0.90r', 'r1': '1.0r'}} if type == 'line': try: vals = [ float(line.strip().split()[-1]) for line in open(histFile, 'r') if line.strip()[0] == 'c' ] except Exception, e: print e paramDict[histFile]['max'] = max(vals) paramDict[histFile]['min'] = min(vals)
def addVioplot(self): taskScoreData = self._examResults.getTaskListSortedByPercentageScore() plotOutput = GalaxyRunSpecificFile( ['TaskScoreOverview', 'vioplot.png'], self._galaxyFN) plotOutput.openRFigure() rawData = [x.getPercentScoresList() for x in taskScoreData] xlabels = [x.getName() for x in taskScoreData] mainTitle = 'Vioplot of task scores overview' xTitle = 'Task' yTitle = 'Percentage score (from max task score)' vioplotColor = 'magenta' xAxisAt = [x + 1 for x in range(len(xlabels))] xLimMin = 1 xLimMax = len(xlabels) + 1 xLas = 2 yAxisAt = range(0, 100, 20) yLimMin = 0 yLimMax = 100 yLas = 1 #plot is used to setup the chart for vioplot so we can control the x and y labels RPlotUtil.drawVioplot(rawData, xlabels, mainTitle, xTitle, yTitle, vioplotColor, xAxisAt, xLimMin, xLimMax, xLas, yAxisAt, yLimMin, yLimMax, yLas) RPlotUtil.rDevOff() self._plotUrls.append(plotOutput.getURL()) self._plotPaths.append(plotOutput.getDiskPath())
def run(self): students = self._examResults.getStudentList() examTotalScores = [] examTotalPercentageScores = [] for student in students: examTotalScores.append( self._examResults.getExamScoreForStudent( student.getStudentNr())) examTotalPercentageScores.append( self._examResults.getExamScorePercentageForStudent( student.getStudentNr())) plotOutput = GalaxyRunSpecificFile( ['ExamScoresOverview', 'histogram1.png'], self._galaxyFN) plotOutput.openRFigure(h=600, w=720) examMaxScore = self._examResults.getExamMaxScore() mainTitle = 'Exam total scores histogram' xTitle = 'Total exam score = %r points' % examMaxScore yTitle = 'Students exam score' RPlotUtil.drawHistogram(examTotalScores, mainTitle, xTitle, yTitle, [0, examMaxScore]) RPlotUtil.rDevOff() self._plotUrls.append(plotOutput.getURL()) self._plotPaths.append(plotOutput.getDiskPath())
def saveMap(self, args): if args['name'].isdigit(): galaxyFn = getGalaxyFnFromDatasetId( int(args['name']) ) outDir = GalaxyRunSpecificFile([], galaxyFn).getDiskPath() else: outDir = '/'.join([GoogleMapsInterface.BASE_DIR, args['name']]) try: os.makedirs(outDir + '/cookies') except OSError, e: if e.errno == errno.EEXIST: pass else: raise e
def __init__(self, name, id, mapId, batchid='0', genome=None): self._name = name self._mapId = mapId self._id = id colldir = createFullGalaxyIdFromNumber(id)[0] galaxyFn = getGalaxyFnFromDatasetId(id) self._genome = genome self._resultsFilesDir = '/'.join([RESULTS_FILES_PATH, colldir]) self._resultsStaticDir = GalaxyRunSpecificFile([batchid], galaxyFn).getDiskPath() self._googleMapsDir = '/'.join([STATIC_PATH, 'maps', name]) self._googleMapsCommonDir = '/'.join([STATIC_PATH, 'maps', 'common']) self._googleMapsCommonMapIdDir = '/'.join( [self._googleMapsCommonDir, mapId])
def getOccupancySummaryFile(summaryTable, galaxyFn, subDirId=None): staticFile = GalaxyRunSpecificFile( ([subDirId] if subDirId else []) + ['intersected_regions.bed'], galaxyFn) fn = staticFile.getDiskPath() from quick.util.CommonFunctions import ensurePathExists ensurePathExists(fn) f = open(fn, 'w') line = [ '#TF Motif', 'Motif count in region', 'Percentage(motif in full region)', 'Percentage(motif in co-bound regions)' ] f.write('\t'.join(line) + os.linesep) for region in summaryTable: line = [ str(region[0]), str(region[1]), str(region[2]), str(region[3]) ] f.write('\t'.join(line) + os.linesep) f.close() return staticFile
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. ''' contents = cls._getContentsOfHistoryFile(choices.history) averages = [] for row in contents: row = [float(x) for x in row] averages.append(sum(row) / len(row)) from proto.hyperbrowser.StaticFile import GalaxyRunSpecificFile plot = GalaxyRunSpecificFile(['average.png'], galaxyFn) plot.openRFigure() from proto.RSetup import r r.plot(range(1, len(averages) + 1), averages, xlab='Rows', ylab='Average value') plot.closeRFigure() #print plot.getURL() + '<br>' #print plot.getDiskPath() from proto.hyperbrowser.HtmlCore import HtmlCore core = HtmlCore() core.begin() core.bigHeader('Plot of row averages') core.paragraph('This is a plot of the average values of each row:') core.image(plot.getURL()) core.paragraph(plot.getURL()) core.paragraph(plot.getDiskPath()) #core.paragraph(str(averages)) core.end() print str(core)