def getHtmlResultsTable(self): headerTab = [ 'TF', 'Chip-seq peaks: ', 'PWM', 'Number of SNV-intersected binding regions', 'Highest binding difference', 'Avg binding difference', 'Number of regions with binding difference', 'Original Fasta', 'Mutated Fasta', 'PWM score for each region', 'Gtrack of PWM score for each region', 'BED of PWM score for each region' ] core = HtmlCore() core.begin() core.tableHeader(headerTab, sortable=True) for tfObj in self.values(): if True: #hasattr(tfObj,'maxPwmDiff'): core.tableLine([ tfObj.tf, tfObj.chipSeqPeaks, tfObj.pwm, tfObj.intersectingPoints, tfObj.maxPwmDiff, tfObj.avgPwmDiff, tfObj.numPwmDiff, tfObj.regularFasta.getLink('Original Fasta'), tfObj.mutatedFasta.getLink('Mutated Fasta'), tfObj.pwmDiffScore.getLink('PWM score for each region'), tfObj.gtrackDiffScore.getLink( 'Gtrack of PWM score for each region'), tfObj.bedPwmDiffScore.getLink( 'BED of PWM score for each region') ]) core.tableFooter() core.end() return str(core)
def execute(cls, choices, galaxyFn=None, username=''): cls._setDebugModeIfSelected(choices) gSuite = getGSuiteFromGalaxyTN(choices.gsuite) if gSuite.genome != choices.genome: gSuite.setGenomeOfAllTracks(choices.genome) regSpec, binSpec = UserBinMixin.getRegsAndBinsSpec(choices) paragraphs = [] paragraphs += generatePilotPageTwoParagraphs(gSuite, galaxyFn, regSpec=regSpec, binSpec=binSpec) paragraphs += generatePilotPageThreeParagraphs(gSuite, galaxyFn, regSpec=regSpec, binSpec=binSpec) core = HtmlCore() core.begin() core.divBegin(divId='results-page') core.divBegin(divClass='results-section') core.header('Similarity and uniqueness of tracks') for prg in paragraphs: core.paragraph(prg) core.divEnd() core.divEnd() core.end() print core
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. ''' resultsFN = ExternalTrackManager.extractFnFromGalaxyTN( choices.resultsFile) selectedTasks = [key for key, val in choices.tasks.iteritems() if val] examAnalysis = TaskCorrelationAnalysis(resultsFN, galaxyFn) examAnalysis.run(selectedTasks) core = HtmlCore() core.begin() for plotUrl in examAnalysis.getPlotUrls(): core.divBegin(divId='plot') core.image(plotUrl) core.divEnd() core.end() print core
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. ''' resultsFN = ExternalTrackManager.extractFnFromGalaxyTN( choices.resultsFile) examResults = TaskScoreOverview(resultsFN, galaxyFn) examResults.run() core = HtmlCore() core.begin() core.header('Overview of exam scores') for table in examResults.getTables(): core.divBegin(divClass='resultsTable') core.tableHeader([]) for key, val in table.iteritems(): core.tableLine([key, val]) core.tableFooter() core.divEnd() for plotUrl in examResults.getPlotUrls(): core.divBegin(divClass='plot') core.image(plotUrl) core.divEnd() core.end() print core
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(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. ''' gSuite = getGSuiteFromGalaxyTN(choices.gSuite) regSpec, binSpec = UserBinMixin.getRegsAndBinsSpec(choices) analysisBins = GalaxyInterface._getUserBinSource(regSpec, binSpec, genome=gSuite.genome) gSuiteOverview = GSuiteOverview(gSuite) coreHtml = HtmlCore() coreHtml.begin() coreHtml.append( str( getGSuiteOverviewHtmlCore( gSuiteOverview.getGSuiteOverviewData( analysisBins=analysisBins)))) coreHtml.end() print coreHtml
def printHtml(cols,rows,colListString,outFile): colListString = colListString.replace('_','').upper() colListString = colListString.replace('"','') from proto.hyperbrowser.HtmlCore import HtmlCore core = HtmlCore() core.begin() core.tableHeader(colListString.split(','),sortable = True) if len(TrackFileImport3.SELECTED_FILES_INDEXES)>0: arr = TrackFileImport3.SELECTED_FILES_INDEXES else: arr = range(len(rows)) for i in arr: row = rows[i] if row == None or len(row)<len(cols): continue url = str(row[0]) filename = url.split('/')[-1] link = HtmlCore().link(filename,url) row = list(row) row[0] = link core.tableLine([str(x) for x in row]) core.tableFooter() core.end() outFile.write(str(core)) outFile.close()
def generateQ1output(cls, additionalResultsDict, analysisQuestion, choices, galaxyFn, gsPerTrackResults, queryTrackTitle, gsuite, results, similarityStatClassName): core = HtmlCore() core.begin() core.divBegin(divId='results-page') core.divBegin(divClass='results-section') core.header(analysisQuestion) topTrackTitle = results.keys()[0] core.paragraph(''' The track "%s" in the GSuite is the one most similar to the query track %s, with a similarity score of %s as measured by the "%s" track similarity measure. ''' % ( topTrackTitle, queryTrackTitle, strWithNatLangFormatting(results[topTrackTitle]), similarityStatClassName)) core.divBegin() addTableWithTabularAndGsuiteImportButtons( core, choices, galaxyFn, cls.Q1_SHORT, tableDict=gsPerTrackResults[1], columnNames=gsPerTrackResults[0], gsuite=gsuite, results=results, gsuiteAppendAttrs=['similarity_score'], sortable=True) core.divEnd() columnInd = 0 if choices.leadAttribute and choices.leadAttribute != GSuiteConstants.TITLE_COL: columnInd = 1 res = GSuiteTracksCoincidingWithQueryTrackTool.drawPlot( results, additionalResultsDict, 'Similarity to query track', columnInd=columnInd) core.line(res) core.divEnd() core.divEnd() core.end() return core
def execute(choices, galaxyFn=None, username=''): gsuite = getGSuiteFromGalaxyTN(choices.gsuite) bedRegions = choices.bedRegions rp = RP(gsuite) bedData = rp.openBedFile(bedRegions) chrOrder, chrLength = rp.sortChrDict() dataDict, dataDictLine, elementOrder, listResCopy, newDictRegions = rp.countMutations( chrLength, bedData) vg = visualizationGraphs() tName = gsuite.allTrackTitles() uniformDictList = OrderedDict() # expected values observedDictList = OrderedDict() # observed values seriesNameRegionUDL = OrderedDict() seriesNameRegionODL = OrderedDict() seriesNameRegion = OrderedDict() GenerateDistributionOfPointsOfInterestTool.countRegionsForDistribution( newDictRegions, observedDictList, rp, seriesNameRegion, seriesNameRegionODL, seriesNameRegionUDL, tName, uniformDictList) res = '' for elK in uniformDictList.keys(): res += GenerateDistributionOfPointsOfInterestTool.drawDistribution( elK, observedDictList, seriesNameRegion, seriesNameRegionODL, seriesNameRegionUDL, uniformDictList, vg) htmlCore = HtmlCore() htmlCore.begin() htmlCore.line(res) htmlCore.end() htmlCore.hideToggle(styleClass='debug') print htmlCore
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 _createNextHistoryElement(cls, toolId, **kwArgs): from quick.util.CommonFunctions import createToolURL redirectUrl = createToolURL(toolId=toolId, **kwArgs) from proto.hyperbrowser.HtmlCore import HtmlCore core = HtmlCore() core.begin(redirectUrl=redirectUrl) core.paragraph('Redirecting to next tool') core.end() with open(cls.extraGalaxyFn[cls.NEXT_TOOL_TITLE], 'w') as nextToolFile: nextToolFile.write(str(core))
def generateQ2Output(cls, additionalAttributesDict, additionalResultsDict, analysisQuestion, choices, galaxyFn, queryTrackTitle, gsuite, results, similarityStatClassName): gsPerTrackResultsModel = GSuitePerTrackResultModel(results, ['Similarity to query track', 'P-value'], additionalResultsDict=additionalResultsDict, additionalAttributesDict=additionalAttributesDict) if choices.leadAttribute and choices.leadAttribute != GSuiteConstants.TITLE_COL: gsPerTrackResults = gsPerTrackResultsModel.generateColumnTitlesAndResultsDict(choices.leadAttribute) else: gsPerTrackResults = gsPerTrackResultsModel.generateColumnTitlesAndResultsDict() core = HtmlCore() core.begin() core.divBegin(divId='results-page') core.divBegin(divClass='results-section') core.header(analysisQuestion) topTrackTitle = results.keys()[0] core.paragraph(''' The track "%s" has the lowest P-value of %s corresponding to %s similarity to the query track "%s" as measured by "%s" track similarity measure. ''' % (topTrackTitle, strWithNatLangFormatting(results[topTrackTitle][1]), strWithNatLangFormatting(results[topTrackTitle][0]), queryTrackTitle, similarityStatClassName)) addTableWithTabularAndGsuiteImportButtons( core, choices, galaxyFn, cls.Q2_SHORT, tableDict=gsPerTrackResults[1], columnNames=gsPerTrackResults[0], gsuite=gsuite, results=results, gsuiteAppendAttrs=['similarity_score', 'p_value'], sortable=True) columnInd = 0 if choices.leadAttribute and choices.leadAttribute != GSuiteConstants.TITLE_COL: columnInd = 1 resultsSeparateListPart = OrderedDict() additionalResultsDictIncludePartFromResults = OrderedDict() for k, v in results.iteritems(): if k not in resultsSeparateListPart.keys(): resultsSeparateListPart[k] = v[0] if k not in additionalResultsDictIncludePartFromResults.keys(): additionalResultsDictIncludePartFromResults[k] = OrderedDict() additionalResultsDictIncludePartFromResults[k]['P-Value'] = v[1] for k1, v1 in additionalResultsDict[k].iteritems(): additionalResultsDictIncludePartFromResults[k][k1] = v1 res = GSuiteTracksCoincidingWithQueryTrackTool.drawPlot( resultsSeparateListPart, additionalResultsDictIncludePartFromResults, 'Similarity to query track', columnInd=columnInd) core.line(res) core.divEnd() core.divEnd() core.end() return core
def execute(cls, choices, galaxyFn=None, username=''): file = choices.file import quick.extra.stefania.Functions_defineDistance_CreateDistanceMatrix_ClusterAnalysis as cdm if choices.mothers == "": numMothers = None else: numMothers = int(choices.mothers) # inputFile = open(ExternalTrackManager.extractFnFromGalaxyTN(file.split(':')), 'r') # with inputFile as f: # data = [x.strip('\n') for x in f.readlines()] # f.closed from proto.hyperbrowser.StaticFile import GalaxyRunSpecificFile sf = GalaxyRunSpecificFile(["matrix.pickle"],galaxyFn) sfPng = GalaxyRunSpecificFile(["matrix.png"], galaxyFn) sfPng1 = GalaxyRunSpecificFile(["Flat1.csv"], galaxyFn) sfPng2 = GalaxyRunSpecificFile(["Flat2.csv"], galaxyFn) filename = ExternalTrackManager.extractFnFromGalaxyTN(file.split(':')) outFn = sf.getDiskPath(ensurePath=True) outDendrogram = sfPng.getDiskPath(ensurePath=True) clustersFileOutput1 = sfPng1.getDiskPath(ensurePath=True) clustersFileOutput2 = sfPng2.getDiskPath(ensurePath=True) cdm.createDistanceMatrix(filename, outFn, outFileType='pkl', womanIDcolPosition = 0, numRows=numMothers) cdm.clusteringFunction(outFn, outDendrogram, clustersFileOutput1, clustersFileOutput2, type='hierarchical', method1= 'centroid', method2='complete') print "Result: ", sf.getLink("pickle-file") htmlCore = HtmlCore() htmlCore.begin() htmlCore.divBegin('plot1') htmlCore.link('Download plot', sfPng.getURL()) htmlCore.image(sfPng.getURL()) htmlCore.divEnd() htmlCore.divBegin('plot1') htmlCore.link('Download file1', sfPng1.getURL()) htmlCore.divEnd() htmlCore.divBegin('plot1') htmlCore.link('Download file2', sfPng2.getURL()) htmlCore.divEnd() htmlCore.end() print htmlCore
def execute(choices, galaxyFn=None, username=''): from proto.hyperbrowser.StaticFile import GalaxyRunSpecificFile from proto.RSetup import r from quick.application.ExternalTrackManager import ExternalTrackManager from proto.hyperbrowser.HtmlCore import HtmlCore dataFn = ExternalTrackManager.extractFnFromGalaxyTN(choices[0]) sf = GalaxyRunSpecificFile(['fig1.png'], galaxyFn) sf.openRFigure() r(PlotFigure1Tool.rCode)(dataFn) sf.closeRFigure() core = HtmlCore() core.begin() core.image(sf.getURL()) core.end() print str(core)
def execute(cls, choices, galaxyFn=None, username=''): #gsuite gsuite = getGSuiteFromGalaxyTN(choices.gsuite) #all boxes multiPlot = choices.multiPlot #scale = choices.scale #overlap = choices.overlap overlap = 'no' bps = int(choices.bps) rp = RP(gsuite) #get length of chromosomes and ordering chrItems = GenomeInfo.getStdChrLengthDict(gsuite.genome) chrOrder, chrLength = GenerateRainfallPlotTool.sortChrDict(chrItems) dataDict, dataDictLine, elementOrder, listResCopy, listDataCountPerBin, newResBinSizeListSum, chrList = GenerateRainfallPlotTool.countMutations( gsuite, chrLength, bps) seriesType, newSeriesNameRes, newSeriesNameResOE, yAxisMultiVal = rp.getOptionsForPlot( elementOrder, gsuite.allTrackTitles()) newResList, newResBinSizeList, newResBinSizeListSortedList = rp.generateBinSizeList( elementOrder, listResCopy, listDataCountPerBin, newResBinSizeListSum) vg = visualizationGraphs() res = '' if multiPlot == 'Single': res += GenerateRainfallPlotTool.drawSinglePlot( vg, newResBinSizeListSortedList, chrLength, newResList, newSeriesNameRes, newResBinSizeList, overlap, seriesType, yAxisMultiVal) else: res += GenerateRainfallPlotTool.drawMultiPlot( newResList, newSeriesNameRes, newResBinSizeList, vg, seriesType, yAxisMultiVal) htmlCore = HtmlCore() htmlCore.begin() htmlCore.line('Bin size: ' + str(bps)) htmlCore.line(res) htmlCore.end() htmlCore.hideToggle(styleClass='debug') print htmlCore
def getHtmlPwmTable(self, lineTab): headerTab = [ 'chrom', 'start', 'end', 'max PWM difference', 'best reference seq_PWM score -> corresponding mut seq score', 'best mut seq PWM score -> corresponding_ref seq score', 'ref region', 'ref seq', 'corresponding mut seq', 'mut region', 'mut seq', 'corresponding ref seq' ] core = HtmlCore() core.begin() core.tableHeader(headerTab, sortable=True) for row in lineTab: if True: #hasattr(tfObj,'maxPwmDiff'): core.tableLine(row) core.tableFooter() core.end() return str(core)
def execute(choices, galaxyFn=None, username=''): gSuite = getGSuiteFromGalaxyTN(choices.gsuite) if gSuite.genome != choices.genome: gSuite.setGenomeOfAllTracks(choices.genome) regSpec, binSpec = UserBinMixin.getRegsAndBinsSpec(choices) paragraphs = generatePilotPageTwoParagraphs(gSuite, galaxyFn, regSpec=regSpec, binSpec=binSpec) core = HtmlCore() core.begin() core.header('Overlap between tracks') for prg in paragraphs: core.paragraph(prg) core.end() print core
def getResultTableLink(self, refSubType, linkText): assert self._galaxyFn is not None and self._gwasId is not None res = self.getResult(refSubType) basedir = GalaxyRunSpecificFile( ['ResultTableDetails', self._gwasId, refSubType], self._galaxyFn).getDiskPath(ensurePath=True) staticFile = GalaxyRunSpecificFile( ['ResultTables', self._gwasId, refSubType + '.html'], self._galaxyFn) core = HtmlCore() core.begin() if hasattr(res, 'batchText'): core.paragraph('<pre> Corresponding batch command line:\n ' + res.batchText + '</pre>') core.paragraph(str(ResultsViewer(res, basedir))) core.end() staticFile.writeTextToFile(str(core)) #staticFile.writeTextToFile( str(ResultsViewer(res, basedir) ) ) return staticFile.getLink(linkText)
def execute(choices, galaxyFn=None, username=''): gSuite = getGSuiteFromGalaxyTN(choices.gsuite) if gSuite.genome != choices.genome: gSuite.setGenomeOfAllTracks(choices.genome) # regSpec, binSpec = UserBinSelector.getRegsAndBinsSpec(choices) paragraphs = generatePilotPageFiveParagraphs(gSuite, galaxyFn) core = HtmlCore() core.begin() core.divBegin(divId='results-page') core.divBegin(divClass='results-section') core.header('Clustering of track elements') for prg in paragraphs: core.paragraph(prg) core.divEnd() core.divEnd() core.end() print core
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. ''' resultsFN = ExternalTrackManager.extractFnFromGalaxyTN( choices.resultsFile) selectedTasks = [key for key, val in choices.tasks.iteritems() if val] bins = int(choices.bins) if choices.bins else 20 displayPoints = bool(choices.displayPoints['display'] ) if choices.displayPoints else False spar = float(choices.spar) if choices.spar else 1.0 verticalLines = None if choices.verticalLines and \ choices.analysis in [IndividualTaskAnalysis.ANALYSIS_BIN_AVG_SMOOTHED_PLOT, IndividualTaskAnalysis.ANALYSIS_MOVING_AVG_SMOOTHED_PLOT]: verticalLines = [ float(x.strip()) for x in choices.verticalLines.split(',') ] examAnalysis = IndividualTaskAnalysis(resultsFN, galaxyFn) examAnalysis.run(analysis=choices.analysis, selectedTasks=selectedTasks, bins=bins, displayPoints=displayPoints, spar=spar, verticalLines=verticalLines) core = HtmlCore() core.begin() for plotUrl in examAnalysis.getPlotUrls(): core.divBegin(divId='plot') core.image(plotUrl) core.divEnd() core.end() print core
def generateQ3output(cls, analysisQuestion, queryTrackTitle, results, similarityStatClassName): pval = results['P-value'] observed = results['TSMC_SummarizedInteractionWithOtherTracksV2Stat'] significanceLevel = 'strong' if pval < 0.01 else ('weak' if pval < 0.05 else 'no') core = HtmlCore() core.begin() core.divBegin(divId='results-page') core.divBegin(divClass='results-section') core.header(analysisQuestion) core.paragraph(''' The query track %s shows %s significance in similarity to the suite of %s and corresponding p-value of %s, as measured by "%s" track similarity measure. ''' % ( queryTrackTitle, significanceLevel, strWithNatLangFormatting(observed), strWithNatLangFormatting(pval), similarityStatClassName)) core.divEnd() core.divEnd() core.end() return 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. ''' 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)
def execute(cls, choices, galaxyFn=None, username=''): cls._setDebugModeIfSelected(choices, galaxyFn) with stdout_redirector(open(galaxyFn, "w", 0)): core = HtmlCore() core.append(GalaxyInterface.getHtmlBeginForRuns(galaxyFn)) core.append( GalaxyInterface.getHtmlForToggles(withRunDescription=False)) core.styleInfoBegin(styleClass='debug') core.paragraph( 'GalaxyInterface.startPreProcessing({}, {}, {})'.format( choices.genome, choices.track, username)) print core if choices.parsingError == cls.MOVE_TO_PARSING_ERROR_CHOICE: finished = False while not finished: DebugConfig.PASS_ON_PREPROCESS_EXCEPTIONS = True try: GalaxyInterface.startPreProcessing( choices.genome, choices.track, username) finished = True except (PreprocessWarning, PreprocessError) as e: print e match = re.search("trackName=\"([^\"]+)\"", str(e)) if match: trackName = match.group(1).split(':') PlainMover().parseFiles(choices.genome, trackName, direction='std_to_error') else: # cls.DO_NOTHING_CHOICE GalaxyInterface.startPreProcessing(choices.genome, choices.track, username) core = HtmlCore() core.styleInfoEnd() core.script('done = true;') core.end() print core
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(choices, galaxyFn=None, username=''): gSuite = getGSuiteFromGalaxyTN(choices.gsuite) if gSuite.genome != choices.genome: gSuite.setGenomeOfAllTracks(choices.genome) regSpec, binSpec = UserBinMixin.getRegsAndBinsSpec(choices) paragraphs = OrderedDict() paragraphs[ 'Basic overview of tracks in collection'] = generatePilotPageOneParagraphs( gSuite, galaxyFn, regSpec=regSpec, binSpec=binSpec, username=username) paragraphs['Overlap between tracks'] = generatePilotPageTwoParagraphs( gSuite, galaxyFn, regSpec=regSpec, binSpec=binSpec) paragraphs[ 'Similarity and uniqueness of tracks'] = generatePilotPageThreeParagraphs( gSuite, galaxyFn, regSpec=regSpec, binSpec=binSpec) paragraphs['Clustering of tracks'] = generatePilotPageFiveParagraphs( gSuite, galaxyFn) core = HtmlCore() core.begin() core.divBegin(divId='results-page', divClass='trackbook_main') for hdr, prgList in paragraphs.iteritems(): core.divBegin(divClass='trackbook_section') core.divBegin(divClass='results-section') core.header(hdr) for prg in prgList: core.paragraph(prg) core.divEnd() core.divEnd() core.divEnd() core.end() print core
def execute(cls, choices, galaxyFn=None, username=''): gSuite = getGSuiteFromGalaxyTN(choices.gsuite) if gSuite.genome != choices.genome: gSuite.setGenomeOfAllTracks(choices.genome) regSpec, binSpec = UserBinMixin.getRegsAndBinsSpec(choices) paragraphs = generatePilotPageOneParagraphs(gSuite, galaxyFn, regSpec=regSpec, binSpec=binSpec, username=username) core = HtmlCore() core.begin() core.divBegin(divId='results-page') core.divBegin(divClass='results-section') core.header('Basic overview of tracks in collection') for prg in paragraphs: core.paragraph(prg) core.divEnd() core.divEnd() core.end() print core
class GtrackSpecParser(object): def __init__(self, filPath, outFilePath): self.core = HtmlCore() self.specStr = open(filPath, 'r').read() self.outFilePath = outFilePath self.htmlMal = '<html><body>%s</body></html>' self.htmlStr = '' self.divCounter = 0 self.fullContentTab = [] def getContentList(self): return self.specStr.split('\n----------------')[2].strip().split('\n') def getContentlineSearcStr(self, line): anchorIndex = 0 if line.strip().startswith('*'): anchorIndex = 2 searchStr = line[2:].strip() + '\n----' elif len(line.strip()) and line.strip().startswith('-'): anchorIndex = line.find('-') + 4 searchStr = line.strip()[2:].strip() + '\n ----' elif line.strip() != '': anchorIndex = 8 searchStr = line.strip().replace(' ', ' ') + '\n ----' else: searchStr = None return searchStr, anchorIndex #x. Comments def findAll(self, substring, string): starts = [ match.start() for match in re.finditer(re.escape(substring), string) ] return [ x for i, x in enumerate(starts) if i == 0 or i > 0 and x - starts[i - 1] != len(substring) ] def checkHeader(self, header, contentStr, devNotes=True): headerIndex = contentStr.find(header) falseHeaderIndex = contentStr.find('"' + header) if headerIndex != -1 and not (falseHeaderIndex != -1 and headerIndex == falseHeaderIndex + 1): devChunckList = contentStr.split(header) resultStr = devChunckList[0] for value in devChunckList[1:]: resultStr += '''<a onclick ="javascript:ShowHide('HiddenDiv%s')" href="javascript:;" >%s</a>''' % ( str(self.divCounter), header) dashLine = '-' * len(header) if devNotes: dotList = value.split(dashLine) resultStr += '<div class="mid" id="HiddenDiv%s" style="DISPLAY: none" >%s%s%s%s</div>' % ( str(self.divCounter), dotList[0], dashLine, dotList[1], dashLine) + dashLine.join(dotList[2:]) else: lastDashLine = self.findAll('----', value)[-1] if value[lastDashLine - 2:lastDashLine] == ' ': lastDashLine -= 2 mainContent = ''.join(value[1:lastDashLine]) newHeader = ''.join(value[lastDashLine:]) resultStr += '<div class="mid" id="HiddenDiv%s" style="DISPLAY: none" >%s</div>\n ' % ( str(self.divCounter), mainContent) + dashLine + '\n\n' + newHeader self.divCounter += 1 return resultStr else: return contentStr def checkRestrictions(self, contentStr): if contentStr.find('- Restrictions') > 0: devChunckList = contentStr.split('- Restrictions') resultStr = devChunckList[0] for value in devChunckList[1:]: resultStr += '''- <a onclick ="javascript:ShowHide('HiddenDiv%s')" href="javascript:;" >Restrictions</a>\n''' % str( self.divCounter) restrictTab, extraTab = [], [] valueTab = value.split('\n') for index, resVal in enumerate(valueTab): if resVal.strip() == '' or (len(resVal) > 2 and resVal[2].isspace()): restrictTab.append(resVal) else: extraTab = valueTab[index:] break for val in restrictTab: if val.strip() == '': restrictTab = restrictTab[1:] else: break for val in reversed(restrictTab): if val.strip() == '': restrictTab = restrictTab[:-1] else: break resultStr += '<div class="mid" id="HiddenDiv%s" style="DISPLAY: none" >\n%s</div>' % ( str(self.divCounter), '\n'.join(restrictTab)) + '\n\n' + '\n'.join(extraTab) self.divCounter += 1 return resultStr else: return contentStr def parseSpecFile(self): contentList = self.getContentList() self.core.begin() self.core.script( "function ShowHide(divId)\n{\nif(document.getElementById(divId).style.display == 'none')\n{\ndocument.getElementById(divId).style.display='block';\n}\nelse\n{\ndocument.getElementById(divId).style.display = 'none';\n}\n}\n" ) self.core.append('<pre class="largefont">' + self.specStr.split(contentList[0])[0]) for i in contentList: searchStr, entry = self.getContentlineSearcStr(i) self.core.append(i[:entry]) self.core.link(i[entry:], '#' + searchStr.split('\n')[0]) self.core.append('\n') self.core.append('\n\n\n') for index, value in enumerate(contentList): print value startPoint, entry = self.getContentlineSearcStr(value) endPoint, entry = self.getContentlineSearcStr( contentList[index + 1]) if index + 1 < len(contentList) else (None, 0) self.core.anchor('', startPoint.split('\n')[0]) content = self.specStr[self.specStr.find( startPoint):] if not endPoint else self.specStr[ self.specStr.find(startPoint):self.specStr.find(endPoint)] # content = self.checkHeader('Parser notes:', content, True) content = self.checkRestrictions(content) self.core.append(content) self.core.append('</pre>') self.core.end() utfil = open(self.outFilePath, 'w') utfil.write(str(self.core))
def _buildHtml(self, done): htmlCore = HtmlCore() htmlCore.begin(reloadTime=RELOAD_TIME) htmlCore.divBegin(divId='progress') runningTimeStr = self._getRunningTimeStr() htmlCore.header(runningTimeStr) remainingTime, unknown = self._estimateRemainingTime() timeRemainingStr = self._getEstimatedTimeRemainingStr( remainingTime, unknown) if unknown: if remainingTime > 0: timeRemainingStr += '+' htmlCore.header(timeRemainingStr) nameCellColSpan = 4 #colspan for the first cell that displays the process name for progressObj in self._progressObjList: htmlCore.tableHeader([], tableClass='progress') htmlCore.tableRowBegin(rowClass='progressRow') htmlCore.tableCell(progressObj.name, colSpan=nameCellColSpan) # for i in range(progressObj.status): # content = '' # if i == int(progressObj.elementCount / 2): # content = "%0.2f" % float(progressObj.status) / progressObj.elementCount * 100 # if i == int(progressObj.elementCount / 2 + 1): # content = '%' # htmlCore.tableCell(content, cellClass='progressCellDone') # # for i in range(progressObj.status, progressObj.elementCount): # content = '' # if i == int(progressObj.elementCount / 2): # content = "%0.2f" % float(progressObj.status) / progressObj.elementCount * 100 # if i == int(progressObj.elementCount / 2 + 1): # content = '%' # htmlCore.tableCell(content, cellClass='progressCell') for i in range(progressObj.elementCount): content = '' if i == int(progressObj.elementCount / 2): content = "%0.2f" % (float(progressObj.status) / progressObj.elementCount * 100) if i == int(progressObj.elementCount / 2 + 1): content = '%' cellCls = 'progressCellDone' if i < progressObj.status else 'progressCell' htmlCore.tableCell(content, cellClass=cellCls) htmlCore.tableRowEnd() htmlCore.tableFooter() estimatedRemainingTime = progressObj.estimateRemainingTime() unknown = estimatedRemainingTime == UNKNOWN_TIME_REMAINING progressObjInfo = self._getEstimatedTimeRemainingStr( estimatedRemainingTime, unknown) htmlCore.paragraph(progressObjInfo) htmlCore.divEnd() htmlCore.end(stopReload=done) return htmlCore
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=''): cls._setDebugModeIfSelected(choices) genome = choices.genome genomicRegions = choices.genomicRegions genomicRegionsTracks = choices.genomicRegionsTracks sourceTfs = choices.sourceTfs sourceTfsDetails = choices.sourceTfsDetails tfTracks = choices.tfTracks # Get Genomic Region track name: if genomicRegions == cls.REGIONS_FROM_HISTORY: galaxyTN = genomicRegionsTracks.split(':') genElementTrackName = ExternalTrackManager.getPreProcessedTrackFromGalaxyTN( genome, galaxyTN) #queryGSuite = getGSuiteFromGalaxyTN(genomicRegionsTracks) #queryTrackList = [Track(x.trackName, x.title) for x in queryGSuite.allTracks()] elif genomicRegions == 'Hyperbrowser repository': selectedGenRegTrack = TfbsTrackNameMappings.getTfbsTrackNameMappings( genome)[genomicRegionsTracks] if isinstance(selectedGenRegTrack, dict): genElementTrackName = selectedGenRegTrack.values() else: genElementTrackName = selectedGenRegTrack elif genomicRegions == 'Hyperbrowser repository (cell-type-specific)': genElementTrackName = ['Private', 'Antonio' ] + genomicRegionsTracks.split(':') else: return # Get TF track names: if isinstance(tfTracks, dict): selectedTfTracks = [ key for key, val in tfTracks.iteritems() if val == 'True' ] else: selectedTfTracks = [tfTracks] queryTrackTitle = '--'.join(genElementTrackName) trackTitles = [queryTrackTitle] tracks = [Track(genElementTrackName, trackTitle=queryTrackTitle)] for i in selectedTfTracks: if sourceTfs == 'Hyperbrowser repository': tfTrackName = TfTrackNameMappings.getTfTrackNameMappings( genome)[sourceTfsDetails] + [i] tracks.append( Track(tfTrackName, trackTitle=tfTrackName[len(tfTrackName) - 1])) trackTitles.append(tfTrackName[len(tfTrackName) - 1]) else: tfTrackName = i.split(':') queryGSuite = getGSuiteFromGalaxyTN(sourceTfsDetails) for x in queryGSuite.allTracks(): selectedTrackNames = (':'.join(x.trackName)) if i == selectedTrackNames: tracks.append(Track(x.trackName, x.title)) trackTitles.append(x.trackName[-1]) # queryGSuite = getGSuiteFromGalaxyTN(sourceTfsDetails) # tfTrackName = [x.trackName for x in queryGSuite.allTracks()] + [i] # tracks += [Track(x.trackName, x.title) for x in queryGSuite.allTracks()] # trackTitles += tfTrackName # print tfTrackName # print tracks # print trackTitles trackTitlesForStat = trackTitles trackTitles = CommonConstants.TRACK_TITLES_SEPARATOR.join(trackTitles) ##first statistic for Q2 resultsForStatistics = OrderedDict() similarityFunc = [ #GSuiteStatUtils.T7_RATIO_OF_OBSERVED_TO_EXPECTED_OVERLAP, GSuiteStatUtils.T5_RATIO_OF_OBSERVED_TO_EXPECTED_OVERLAP ] for similarityStatClassName in similarityFunc: regSpec, binSpec = UserBinMixin.getRegsAndBinsSpec(choices) analysisBins = GalaxyInterface._getUserBinSource(regSpec, binSpec, genome=genome) mcfdrDepth = AnalysisDefHandler( REPLACE_TEMPLATES['$MCFDR$']).getOptionsAsText().values()[0][0] analysisDefString = REPLACE_TEMPLATES[ '$MCFDR$'] + ' -> GSuiteSimilarityToQueryTrackRankingsAndPValuesWrapperStat' analysisSpec = AnalysisDefHandler(analysisDefString) analysisSpec.setChoice('MCFDR sampling depth', mcfdrDepth) analysisSpec.addParameter('assumptions', 'PermutedSegsAndIntersegsTrack_') analysisSpec.addParameter( 'rawStatistic', GSuiteStatUtils. PAIRWISE_STAT_LABEL_TO_CLASS_MAPPING[similarityStatClassName]) analysisSpec.addParameter( 'pairwiseStatistic', GSuiteStatUtils. PAIRWISE_STAT_LABEL_TO_CLASS_MAPPING[similarityStatClassName] ) #needed for call of non randomized stat for assertion analysisSpec.addParameter('tail', 'more') analysisSpec.addParameter('trackTitles', trackTitles) #that need to be string analysisSpec.addParameter('queryTracksNum', str(len(tracks))) results = doAnalysis(analysisSpec, analysisBins, tracks).getGlobalResult() if not similarityStatClassName in resultsForStatistics: resultsForStatistics[similarityStatClassName] = {} resultsForStatistics[similarityStatClassName] = results keyTitle = [ #'Normalized ratio of observed to expected overlap (normalized Forbes similarity measure)', 'Ratio of observed to expected overlap (Forbes similarity measure)' ] # 'Normalized Forbes coefficient: ratio of observed to expected overlap normalized in relation to the reference GSuite', # 'Forbes coefficient: ratio of observed to expected overlap' keyTitle = [ #GSuiteStatUtils.T7_RATIO_OF_OBSERVED_TO_EXPECTED_OVERLAP, GSuiteStatUtils.T5_RATIO_OF_OBSERVED_TO_EXPECTED_OVERLAP ] resultDict = AllTfsOfRegions.countStatistics(similarityFunc, choices, genome, tracks, trackTitlesForStat) resultDictShow = AllTfsOfRegions.countStatisticResults( resultDict, keyTitle, trackTitlesForStat) # print resultsForStatistics '''selectedTrackNames = [] if sourceTfs == 'History (user-defined)': if selectedTfTracks.split(":")[1] == "gsuite": gSuite = getGSuiteFromGalaxyTN(selectedTfTracks) for track in gSuite.allTracks(): selectedTrackNames.append(track.trackName) else: galaxyTN = selectedTfTracks.split(':') gRegTrackName = ExternalTrackManager.getPreProcessedTrackFromGalaxyTN(genome, galaxyTN) selectedTrackNames.append(gRegTrackName) else:''' tfNameList = [] #Intersection between TF Tracks and selected region (Table 1): n = 0 allTargetBins = [] alltfNames = [] table1 = [] for i in selectedTfTracks: n = n + 1 #newGalaxyFn = galaxyFn.split(".")[0] + str(n) + "." + "dat" if sourceTfs == 'Hyperbrowser repository': tfTrackName = TfTrackNameMappings.getTfTrackNameMappings( genome)[sourceTfsDetails] + [i] else: tfTrackName = i.split(':') tfTrackName.pop(0) #tfIntersection.expandReferenceTrack(upFlankSize, downFlankSize) tfIntersection = TrackIntersection(genome, genElementTrackName, tfTrackName, galaxyFn, str(n)) regFileNamer = tfIntersection.getIntersectedRegionsStaticFileWithContent( ) targetBins = tfIntersection.getIntersectedReferenceBins() #regSpec, targetBins = UserBinSelector.getRegsAndBinsSpec(choices) tfHits = [i] * len(targetBins) fixedTargetBins = [str(a).split(" ")[0] for a in targetBins] extendedTargetBins = [ list(a) for a in zip(fixedTargetBins, tfHits) ] allTargetBins = allTargetBins + extendedTargetBins tfName = i alltfNames = alltfNames + [tfName] # Save output table: tfNameList.append(tfName) line = [tfName] + [len(targetBins)] + [ regFileNamer.getLink('Download bed-file') ] + [ regFileNamer.getLoadToHistoryLink('Send bed-file to History') ] table1 = table1 + [line] # Computing totals: fullCase = ','.join(alltfNames) firstColumn = [item[0] for item in allTargetBins] uniqueAllTargetBins = list(set(firstColumn)) # Group TFs by bound region: d1 = defaultdict(list) for k, v in allTargetBins: d1[k].append(v) allTFTargetBins = dict((k, ','.join(v)) for k, v in d1.iteritems()) allTFTargetList = [] fullCaseTFTargetList = [] for key, value in allTFTargetBins.iteritems(): allTFTargetList = allTFTargetList + [[key, value]] if value == fullCase: fullCaseTFTargetList = fullCaseTFTargetList + [[key, value]] analysis3 = TrackIntersection.getFileFromTargetBins( allTFTargetList, galaxyFn, str(3)) analysis4 = TrackIntersection.getFileFromTargetBins( fullCaseTFTargetList, galaxyFn, str(4)) # Print output to table: title = 'TF targets and co-occupancy of ' + genElementTrackName[ -1] + ' genomic regions' htmlCore = HtmlCore() pf = plotFunction(tableId='resultsTable') htmlCore.begin() htmlCore.header(title) htmlCore.divBegin('resultsDiv') htmlCore.line(pf.createButton(bText='Show/Hide more results')) # htmlCore.tableHeader(['Transcription Factor', 'Normalized ratio of observed to expected overlap (normalized Forbes similarity measure) -- Similarity to genomic regions track', 'Normalized ratio of observed to expected overlap (normalized Forbes similarity measure) -- p-value','Ratio of observed to expected overlap (Forbes similarity measure) -- Similarity to genomic regions track', 'Ratio of observed to expected overlap (Forbes similarity measure) -- p-value', 'Number of TF-Target Track Regions', 'File of TF Target Regions', 'File of TF Target Regions', 'Number of TF-co-occupied Regions', 'File of TF co-occupied Regions', 'File of TF co-occupied Regions', 'Rank of TF co-occupancy motifs', 'Rank of TF co-occupancy motifs'], sortable=True, tableId='resultsTable') #previous ordering # htmlCore.tableHeader(['Transcription Factor', 'Normalized Forbes index --overlap score', # 'Normalized Forbes index --p-value', # 'Forbes index --overlap score', 'Forbes index --p-value', # 'Number of TF-Target Track Regions', 'File of TF Target Regions', # 'File of TF Target Regions', 'Number of target track regions occupied by this TF', # 'File of TF co-occupied Regions', 'File of TF co-occupied Regions', # 'Rank of TF co-occupancy motifs', 'Rank of TF co-occupancy motifs'], # sortable=True, tableId='resultsTable') htmlCore.tableHeader( [ 'Transcription Factor', 'Number of TF-Target Track Regions', 'File of TF Track Regions', 'Number of target track regions occupied by this TF', 'File of TF Target Regions', 'Forbes index --overlap score', 'Forbes index --p-value', #'Normalized Forbes index --overlap score', 'Normalized Forbes index --p-value', 'File of TF co-occupied Regions', 'Rank of TF co-occupancy motifs' ], sortable=True, tableId='resultsTable') # Adding co-occupancy results to table: n = 1000 genRegionNumElements = [ int(x) for x in getTrackRelevantInfo.getNumberElements( genome, genElementTrackName) ] for key0, it0 in resultsForStatistics.iteritems(): for el in tfNameList: if el not in it0: resultsForStatistics[key0][el] = [None, None] resultsPlotDict = {} resultPlotCat = [] resultsPlot = [] resultsForStatisticsProper = {} for key0, it0 in resultsForStatistics.iteritems(): if not key0 in resultsPlotDict: resultsPlotDict[key0] = {} resultsPlotPart = [] for key1, it1 in it0.iteritems(): resultsPlotPart.append(it1[0]) if not key1 in resultsForStatisticsProper: resultsForStatisticsProper[key1] = [] if not key1 in resultsPlotDict[key0]: resultsPlotDict[key0][key1] = None for el in it1: resultsForStatisticsProper[key1].append(el) resultsPlotDict[key0][key1] = it1[0] resultPlotCat.append(tfNameList) resultPlotCat.append(tfNameList) #resultPlotCatPart = tfNameList # print resultPlotCatPart for key0, it0 in resultsPlotDict.iteritems(): resultsPlotPart = [] for el in tfNameList: if el in it0: resultsPlotPart.append(it0[el]) else: resultsPlotPart.append(None) resultsPlot.append(resultsPlotPart) for i in table1: thisCaseTFTargetList = [] for key, value in allTFTargetList: if i[0] in value and ',' in value: thisCaseTFTargetList = thisCaseTFTargetList + [[ key, value ]] n = n + 1 thisAnalysis = TrackIntersection.getFileFromTargetBins( thisCaseTFTargetList, galaxyFn, str(n)) thisCaseCoCountsList = [] thing = [x[1] for x in thisCaseTFTargetList] for k in list(set(thing)): thisCount = thing.count(k) thisCaseCoCountsList = thisCaseCoCountsList + \ [[k, thisCount, 100*float(thisCount)/float(sum(genRegionNumElements)), 100*float(thisCount)/float(len(thisCaseTFTargetList))]] thisCaseCoCountsList.sort(key=lambda x: x[2], reverse=True) n = n + 1 thisCoCountsAnalysis = TrackIntersection.getOccupancySummaryFile( thisCaseCoCountsList, galaxyFn, str(n)) thisLine = [len(thisCaseTFTargetList)] + \ [thisAnalysis.getLink('Download file')] + [thisAnalysis.getLoadToHistoryLink('Send file to History')] + \ [thisCoCountsAnalysis.getLink('Download file')] + [thisCoCountsAnalysis.getLoadToHistoryLink('Send file to History')] newLineI = [] tfName = i[0] newLineI.append(tfName) for el in resultsForStatisticsProper[tfName]: newLineI.append(el) for elN in range(1, len(i)): newLineI.append(i[elN]) # htmlCore.tableLine(i + thisLine) # htmlCore.tableHeader(['Transcription Factor', 'Normalized Forbes index --overlap score', # 'Normalized Forbes index --p-value', # 'Forbes index --overlap score', 'Forbes index --p-value', # 'Number of TF-Target Track Regions', 'File of TF Target Regions', # 'File of TF Target Regions', 'Number of target track regions occupied by this TF', # 'File of TF co-occupied Regions', 'File of TF co-occupied Regions', # 'Rank of TF co-occupancy motifs', 'Rank of TF co-occupancy motifs'], # sortable=True, tableId='resultsTable') # htmlCore.tableHeader(['Transcription Factor', 'Number of TF-Target Track Regions', 'File of TF Track Regions', # 'Number of target track regions occupied by this TF', 'File of TF Target Regions', # 'Forbes index --overlap score', 'Forbes index --p-value', # 'Normalized Forbes index --overlap score', 'Normalized Forbes index --p-value', # 'File of TF co-occupied Regions', 'Rank of TF co-occupancy motifs'], # sortable=True, tableId='resultsTable') tl = newLineI + thisLine # previous ordering tl - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 # actual ordering - 0, 5, 7, 8, 7, 3, 4, 1, 2, 9, 11 #ordering = [0, 5, 7, 8, 10, 3, 4, 1, 2, 10, 12] ordering = [0, 3, 5, 6, 8, 1, 2, 8, 10] #1, 2, => delete eoList = [] for eo in ordering: eoList.append(tl[eo]) htmlCore.tableLine(eoList) totalCoOccupancyTargetList = [] n = 2000 for key, value in allTFTargetList: n = n + 1 if ',' in value: totalCoOccupancyTargetList = totalCoOccupancyTargetList + [[ key, value ]] #newGalaxyFn = galaxyFn.split(".")[0] + str(n) + "." + "dat" totalCoOccupancyAnalysis = TrackIntersection.getFileFromTargetBins( totalCoOccupancyTargetList, galaxyFn, str(n)) #line = ['Total reported regions'] + [len(allTargetBins)] + [''] + [''] + [''] + [''] + [''] #line = ['Full co-occupancy of ' + fullCase] + ['-'] + ['-'] + ['-'] + ['-'] + ['-'] + ['-'] + ['-'] + [len(fullCaseTFTargetList)] + [analysis4.getLink('Download file')] + [analysis4.getLoadToHistoryLink('Send file to History')] + ['-'] + ['-'] line = ['Full co-occupancy of ' + fullCase] + \ ['-'] + \ ['-'] + \ [len(fullCaseTFTargetList)] + \ ['-'] + \ ['-'] + \ ['-'] + \ [analysis4.getLoadToHistoryLink('Send file to History')] + \ ['-'] htmlCore.tableLine(line) #line = ['Total unique regions'] + ['-'] + ['-'] + ['-'] + ['-'] + [len(allTFTargetList)] + [analysis3.getLink('Download bed-file')] + [analysis3.getLoadToHistoryLink('Send bed-file to History')] + [len(totalCoOccupancyTargetList)] + [totalCoOccupancyAnalysis.getLink('Download file')] + [totalCoOccupancyAnalysis.getLoadToHistoryLink('Send file to History')] + ['-'] + ['-'] line = ['Total unique regions'] + \ [len(allTFTargetList)] + \ ['-'] + \ [len(totalCoOccupancyTargetList)] + \ [analysis3.getLoadToHistoryLink('Send bed-file to History')] + \ ['-'] +\ ['-'] + \ [totalCoOccupancyAnalysis.getLoadToHistoryLink('Send file to History')] + \ ['-'] htmlCore.tableLine(line) htmlCore.tableFooter() htmlCore.divEnd() # htmlCore.line(pf.hideColumns(indexList=[2, 4])) # sumRes = 0 for r in resultsPlot[0]: if r != None: sumRes += r if sumRes != 0: vg = visualizationGraphs() result = vg.drawColumnCharts( [resultsPlot[0]], height=300, categories=resultPlotCat, legend=False, addOptions='width: 90%; float:left; margin: 0 4%;', #titleText=['Overlap between TFs and genomic region using normalized Forbes', 'Overlap between TFs and genomic region using Forbes'], titleText=[ 'Overlap between TFs and genomic region using Forbes' ], xAxisRotation=90, xAxisTitle='TF', yAxisTitle='value') htmlCore.line(result) for key0, it0 in resultDictShow.iteritems(): htmlCore.divBegin('resultsDiv' + str(key0)) htmlCore.header(key0) htmlCore.tableHeader(it0[0], sortable=True, tableId='resultsTable' + str(key0)) for elN in range(1, len(it0)): htmlCore.tableLine(it0[elN]) htmlCore.tableFooter() htmlCore.divEnd() htmlCore.hideToggle(styleClass='debug') htmlCore.end() print htmlCore