def execute(cls, choices, galaxyFn=None, username=''): import time start = time.clock() # HTML settings from gold.result.HtmlCore import HtmlCore htmlCore = HtmlCore() htmlCore.divBegin(style=cls.HTML_STYLE) # Set debug environment cls._setDebugModeIfSelected(choices) # Analysis environment gSuite = getGSuiteFromGalaxyTN(choices.gSuite) analysisBins = GlobalBinSource(gSuite.genome) analysisSpec = AnalysisSpec(GeneticLociOverlapStat) analysisSpec.addParameter('filterThreshold', int(choices.geneticLocus)) # Print tool information: cls.htmlClusterTitle(cls.getToolName(), htmlCore) cls.htmlClusterSubtext(choices.corrStat, [cls.CORR_PEARSON, cls.CORR_SPEARMAN], choices.linkageCriterion, htmlCore) cls.htmlVectorHandling(htmlCore) # Get correlations overlapMatrix, labels = cls.getOverlapMatrix(analysisBins, analysisSpec, gSuite) corrDict = cls.getTriangularCorrMatrix(overlapMatrix) cls.printCorrPlots(corrDict, labels, choices.corrStat, choices.linkageCriterion, galaxyFn, htmlCore) cls.htmlClusterTime(str(time.clock() - start), htmlCore) htmlCore.divEnd() print htmlCore
def getGSuiteRipleysKData(self, bpWindow=1000, analysisBins=None): resDict = OrderedDict() ripleysK = AnalysisSpec(RipleysKStat) ripleysK.addParameter('bpWindow', str(bpWindow)) for track in self._gSuite.allTracks(): ripleysKResults = doAnalysis(ripleysK, analysisBins, [Track(track.trackName)]) resDict[track.title] = ripleysKResults.getGlobalResult()['Result'] return resDict
def _runMultipleSingleValStatsCommon(trackStructure, stats, analysisBins, stat): assert stats is not None, 'stats argument not defined' assert type(stats) in [str, list], '''stats argument must be a list of statistics or ^-separated string of statistic names''' additionalAnalysisSpec = AnalysisSpec(stat) statsParam = stats if isinstance(stats, basestring) else "^".join([x.__name__ for x in stats]) additionalAnalysisSpec.addParameter('rawStatistics', statsParam) # use ^ separator to add additional stat classes. return doAnalysis(additionalAnalysisSpec, analysisBins, trackStructure).getGlobalResult()["Result"]
def prepareQ1(cls, reverse, similarityStatClassName, trackTitles): analysisSpec = AnalysisSpec(GSuiteSimilarityToQueryTrackRankingsWrapperStat) analysisSpec.addParameter('pairwiseStatistic', GSuiteStatUtils.PAIRWISE_STAT_LABEL_TO_CLASS_MAPPING[similarityStatClassName]) analysisSpec.addParameter('reverse', reverse) analysisSpec.addParameter('trackTitles', trackTitles) analysisSpec.addParameter('queryTracksNum', str(1)) return analysisSpec
def runMultipleSingleValStatsOnTracks(gsuite, stats, analysisBins, queryTrack=None): ''' gsuite: The gsuite of tracks stats: List of statistics analysisBins: BinSource object queryTrack: should be defined if there are stats that need to run on two tracks (e.g. overlap) Returns an OrderedDict: Track title -> OrderedDict: Stat name -> single value''' assert stats is not None, 'stats argument not defined' assert type(stats) in [str, list ], '''stats argument must be a list of statistics or ^-separated string of statistic names''' resultsDict = OrderedDict() from quick.statistic.GenericResultsCombinerStat import GenericResultsCombinerStat additionalAnalysisSpec = AnalysisSpec(GenericResultsCombinerStat) statsParam = stats if isinstance(stats, basestring) else "^".join( [x.__name__ for x in stats]) additionalAnalysisSpec.addParameter( 'rawStatistics', statsParam) #use ^ separator to add additional stat classes. for refTrack in gsuite.allTracks(): if refTrack.title not in resultsDict: resultsDict[refTrack.title] = OrderedDict() tracks = [Track(refTrack.trackName), queryTrack ] if queryTrack else [Track(refTrack.trackName)] additionalResult = doAnalysis(additionalAnalysisSpec, analysisBins, tracks).getGlobalResult() for statClassName, res in additionalResult.iteritems(): statPrettyName = CommonConstants.STATISTIC_CLASS_NAME_TO_NATURAL_NAME_DICT[ statClassName] if statClassName in CommonConstants.STATISTIC_CLASS_NAME_TO_NATURAL_NAME_DICT else statClassName resultsDict[refTrack.title][statPrettyName] = res return resultsDict
def run(self): tracks = [t.trackName for t in self._gsuite.allTracks()] trackTitles = self._gsuite.allTrackTitles() results = OrderedDict() analysisSpec = AnalysisSpec(SummarizedInteractionWithOtherTracksStat) analysisSpec.addParameter('rawStatistic', self._rawStatistic) analysisSpec.addParameter('summaryFunc', self._summaryFunction) analysisSpec.addParameter('reverse', self._reversed) for t1Title, t1 in zip(trackTitles, tracks): for t2Title, t2 in zip(trackTitles, tracks): if t1Title != t2Title: result = doAnalysis(analysisSpec, self._analysisBins, [Track(t1), Track(t2)]) resultDict = result.getGlobalResult() # if 'Result' in resultDict: results[(t1Title, t2Title)] = resultDict['Result']
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. ''' cls._setDebugModeIfSelected(choices) # First compute pvalue by running the statistic through a wrapper stat that computes the max per bin """ from quick.statistic.RandomizationManagerV3Stat import RandomizationManagerV3Stat from quick.statistic.CollectionBinnedHypothesisWrapperStat import CollectionBinnedHypothesisWrapperStat analysisSpec = AnalysisSpec(CollectionBinnedHypothesisWrapperStat) analysisSpec.addParameter("rawStatistic", "GenericMaxBinValueStat") analysisSpec.addParameter('perBinStatistic', 'SummarizedStat') analysisSpec.addParameter('mcSamplerClass', 'NaiveMCSamplingV2Stat') analysisSpec.addParameter('pairwiseStatistic', 'ProportionCountStat') analysisSpec.addParameter('summaryFunc', choices.summaryFunc) analysisSpec.addParameter('evaluatorFunc','evaluatePvalueAndNullDistribution') analysisSpec.addParameter('tail', 'right-tail') analysisSpec.addParameter('assumptions', 'RandomGenomeLocationTrack') analysisSpec.addParameter('maxSamples', 10) gsuite = getGSuiteFromGalaxyTN(choices.gsuite) tracks = [Track(x.trackName) for x in gsuite.allTracks()] regSpec, binSpec = cls.getRegsAndBinsSpec(choices) analysisBins = GalaxyInterface._getUserBinSource(regSpec, binSpec, choices.genome) results = doAnalysis(analysisSpec, analysisBins, tracks) print "<p>Max stat results:</p>" print results.getGlobalResult() """ # Stat question 4 summaryFunc = choices.summaryFunc if choices.summaryFunc else cls.SUMMARY_FUNC_DEFAULT statTxt = "Average" if (summaryFunc == "max"): statTxt = "Maximum" statDesc = 'number of <b>segments</b> per base' if choices.analysisName == cls.Q2: statDesc = 'number of <b>base pairs covered by segments</b>' core = HtmlCore() core.begin() core.header("Enrichment of GSuite tracks across regions") core.divBegin(divClass='resultsExplanation') core.paragraph( 'The following is a list of all regions (bins) and the <b>' + statTxt.lower() + '</b> ' + statDesc + ' across the tracks within each region.') core.divEnd() if choices.analysisName == cls.Q3: # Compute p-value per bin analysisSpec = AnalysisSpec(GSuiteBinEnrichmentPValWrapperStat) analysisSpec.addParameter('rawStatistic', 'BinSizeStat') #analysisSpec.addParameter('pairwiseStatistic', 'ProportionElementCountStat') #analysisSpec.addParameter('pairwiseStatistic', 'ProportionElementCountStat') #analysisSpec.addParameter('summaryFunc', summaryFunc) gsuite = getGSuiteFromGalaxyTN(choices.gsuite) tracks = [Track(x.trackName) for x in gsuite.allTracks()] regSpec, binSpec = cls.getRegsAndBinsSpec(choices) from quick.statistic.GenericRelativeToGlobalStat import GenericRelativeToGlobalStatUnsplittable #analysisSpec.addParameter("globalSource", GenericRelativeToGlobalStatUnsplittable.getGlobalSource('test', choices.genome, False)) analysisSpec.addParameter("globalSource", 'userbins') analysisBins = GalaxyInterface._getUserBinSource( regSpec, binSpec, choices.genome) results_pval = doAnalysis(analysisSpec, analysisBins, tracks) #print results_pval analysisSpec = AnalysisSpec(SummarizedWrapperStat) analysisSpec.addParameter('rawStatistic', 'SummarizedWrapperStat') countStat = 'ProportionElementCountStat' if choices.analysisName == cls.Q2: countStat = 'ProportionCountStat' # analysisSpec.addParameter('pairwiseStatistic', 'ProportionCountStat') analysisSpec.addParameter('pairwiseStatistic', countStat) analysisSpec.addParameter('summaryFunc', summaryFunc) gsuite = getGSuiteFromGalaxyTN(choices.gsuite) tracks = [Track(x.trackName) for x in gsuite.allTracks()] regSpec, binSpec = cls.getRegsAndBinsSpec(choices) analysisBins = GalaxyInterface._getUserBinSource( regSpec, binSpec, choices.genome) results = doAnalysis(analysisSpec, analysisBins, tracks) prettyResults = {} #print results for key, val in results.iteritems(): if "Result" in val.keys(): if choices.analysisName == cls.Q3: prettyResults[key] = (val["Result"], results_pval[key]["Result"]) else: prettyResults[key] = (val["Result"]) else: prettyResults[key] = "No result" topTrackTitle = results.keys()[0] """ core.paragraph(''' Suite data is coinciding the most in bin %s ''' % ('test')) """ columnNames = ['Bin', 'Representation within the bin'] if choices.analysisName == cls.Q3: columnNames.append('p-value') core.divBegin() if choices.analysisName == cls.Q1: shortQuestion = cls.Q1_SHORT elif choices.analysisName == cls.Q2: shortQuestion = cls.Q2_SHORT else: # Q3 shortQuestion = cls.Q3_SHORT visibleRows = 20 makeTableExpandable = len(prettyResults) > visibleRows addTableWithTabularAndGsuiteImportButtons( core, choices, galaxyFn, shortQuestion, tableDict=prettyResults, columnNames=columnNames, sortable=True, presorted=0, expandable=makeTableExpandable) core.divEnd() core.end() print str(core)
def execute(cls, choices, galaxyFn=None, username=''): #cls._setDebugModeIfSelected(choices) # from config.DebugConfig import DebugConfig # from config.DebugConfig import DebugModes # DebugConfig.changeMode(DebugModes.RAISE_HIDDEN_EXCEPTIONS_NO_VERBOSE) # DebugUtil.insertBreakPoint(5678, suspend=False) choices_gsuite = choices.gsuite selected_metadata = choices.cat choices_queryTrack = choices.query #genome = 'hg19' genome = choices.genome queryTS = factory.getSingleTrackTS(genome, choices_queryTrack) refTS = factory.getFlatTracksTS(genome, choices_gsuite) categoricalTS = refTS.getSplittedByCategoryTS(selected_metadata) fullTS = TrackStructureV2() fullTS['query'] = queryTS fullTS['reference'] = categoricalTS spec = AnalysisSpec(SummarizedInteractionPerTsCatV2Stat) parameter = 'minLqMedUqMax' spec.addParameter('pairwiseStatistic', ObservedVsExpectedStat.__name__) spec.addParameter('summaryFunc', parameter) bins = UserBinSource('chr1', '*', genome=genome) res = doAnalysis(spec, bins, fullTS) tsRes = res.getGlobalResult()['Result'] htmlCore = HtmlCore() htmlCore.begin() if parameter == 'minAndMax': htmlCore.tableHeader(['Track', 'min-max'], sortable=False, tableId='tab1') for k, it in tsRes.iteritems(): htmlCore.tableLine([ k, str("%.2f" % it.getResult()[0]) + '-' + str("%.2f" % it.getResult()[1]) ]) htmlCore.tableFooter() if parameter == 'minLqMedUqMax': dataList = [] categories = [] for keyE, itE in tsRes.iteritems(): categories.append(keyE) dataList.append(list(itE.getResult())) from quick.webtools.restricted.visualization.visualizationGraphs import \ visualizationGraphs vg = visualizationGraphs() res = vg.drawBoxPlotChart(dataList, categories=categories, seriesName=selected_metadata) htmlCore.line(res) htmlCore.end() print htmlCore
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. ''' import numpy numpy.seterr(all='raise') cls._setDebugModeIfSelected(choices) # DebugUtil.insertBreakPoint(username=username, currentUser='******') genome = choices.genome analysisQuestion = choices.analysisName similaryStatClassName = choices.similarityFunc if choices.similarityFunc else GSuiteStatUtils.T5_RATIO_OF_OBSERVED_TO_EXPECTED_OVERLAP summaryFunc = choices.summaryFunc if choices.summaryFunc else 'average' reverse = 'Yes' if choices.reversed else 'No' gsuite = getGSuiteFromGalaxyTN(choices.gsuite) regSpec, binSpec = UserBinMixin.getRegsAndBinsSpec(choices) analysisBins = GalaxyInterface._getUserBinSource(regSpec, binSpec, genome=genome) tracks = [ Track(x.trackName, trackTitle=x.title) for x in gsuite.allTracks() ] trackTitles = CommonConstants.TRACK_TITLES_SEPARATOR.join( [quote(x.title, safe='') for x in gsuite.allTracks()]) additionalResultsDict = OrderedDict() additionalAttributesDict = OrderedDict() if analysisQuestion in [cls.Q1, cls.Q2, cls.Q3]: additionalAttributesDict = cls.getSelectedAttributesForEachTrackDict( choices.additionalAttributes, gsuite) #additional analysis stats = [CountStat, CountElementStat] additionalResultsDict = runMultipleSingleValStatsOnTracks( gsuite, stats, analysisBins, queryTrack=None) if analysisQuestion == cls.Q1: analysisSpec = AnalysisSpec( GSuiteRepresentativenessOfTracksRankingsWrapperStat) analysisSpec.addParameter( 'pairwiseStatistic', GSuiteStatUtils. PAIRWISE_STAT_LABEL_TO_CLASS_MAPPING[similaryStatClassName]) analysisSpec.addParameter( 'summaryFunc', GSuiteStatUtils.SUMMARY_FUNCTIONS_MAPPER[summaryFunc]) analysisSpec.addParameter('reverse', reverse) analysisSpec.addParameter('ascending', 'No') analysisSpec.addParameter('trackTitles', trackTitles) analysisSpec.addParameter('queryTracksNum', len(tracks)) results = doAnalysis(analysisSpec, analysisBins, tracks).getGlobalResult() gsPerTrackResultsModel = GSuitePerTrackResultModel( results, ['Similarity to rest of tracks in suite (%s)' % summaryFunc], additionalResultsDict=additionalResultsDict, additionalAttributesDict=additionalAttributesDict) if choices.leadAttribute and choices.leadAttribute != GSuiteConstants.TITLE_COL: columnTitles, decoratedResultsDict = \ gsPerTrackResultsModel.generateColumnTitlesAndResultsDict(choices.leadAttribute) else: columnTitles, decoratedResultsDict = \ 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" is the most representative track of the GSuite with %s %s similarity to the rest of the tracks as measured by "%s" track similarity measure. ''' % (topTrackTitle, results[topTrackTitle], summaryFunc, similaryStatClassName)) addTableWithTabularAndGsuiteImportButtons( core, choices, galaxyFn, cls.Q1_SHORT, decoratedResultsDict, columnTitles, gsuite=gsuite, results=results, gsuiteAppendAttrs=['similarity_score'], sortable=True) # plot columnInd = 0 if choices.leadAttribute and choices.leadAttribute != GSuiteConstants.TITLE_COL: columnInd = 1 res = GSuiteTracksCoincidingWithQueryTrackTool.drawPlot( results, additionalResultsDict, 'Similarity to rest of tracks in suite (%s)' % summaryFunc, columnInd=columnInd) core.line(res) core.divEnd() core.divEnd() core.end() # elif analysisQuestion == cls.Q2: # analysisSpec = AnalysisSpec(GSuiteRepresentativenessOfTracksRankingsWrapperStat) # analysisSpec.addParameter('pairwiseStatistic', GSuiteStatUtils.PAIRWISE_STAT_LABEL_TO_CLASS_MAPPING[similaryStatClassName]) # analysisSpec.addParameter('summaryFunc', GSuiteStatUtils.SUMMARY_FUNCTIONS_MAPPER[summaryFunc]) # analysisSpec.addParameter('reverse', reverse) # analysisSpec.addParameter('ascending', 'Yes') # analysisSpec.addParameter('trackTitles', trackTitles) # results = doAnalysis(analysisSpec, analysisBins, tracks).getGlobalResult() # # gsPerTrackResultsModel = GSuitePerTrackResultModel( # results, ['Similarity to rest of tracks in suite (%s)' % summaryFunc], # additionalResultsDict=additionalResultsDict, # additionalAttributesDict=additionalAttributesDict) # if choices.leadAttribute and choices.leadAttribute != GSuiteConstants.TITLE_COL: # columnTitles, decoratedResultsDict = \ # gsPerTrackResultsModel.generateColumnTitlesAndResultsDict(choices.leadAttribute) # else: # columnTitles, decoratedResultsDict = \ # 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" is the most atypical track of the GSuite with %s %s similarity to the rest of the tracks # as measured by the "%s" track similarity measure. # ''' % (topTrackTitle, strWithNatLangFormatting(results[topTrackTitle]), summaryFunc, similaryStatClassName)) # # core.tableFromDictionary(results, columnNames=['Track title', 'Similarity to rest of tracks in suite (' + summaryFunc+')'], sortable=False) # # from quick.util import CommonFunctions # rawDataURIList = CommonFunctions.getHyperlinksForRawTableData( # dataDict=decoratedResultsDict, colNames=columnTitles, # tableId="resultsTable", galaxyFn=galaxyFn) # core.tableFromDictionary(decoratedResultsDict, columnNames=columnTitles, sortable=True, # tableId='resultsTable', addInstruction=True, # addRawDataSelectBox=True, rawDataURIList=rawDataURIList) # # core.tableFromDictionary(decoratedResultsDict, columnNames=columnTitles, sortable=True, tableId='resultsTable') # # columnInd = 0 # if choices.leadAttribute and choices.leadAttribute != GSuiteConstants.TITLE_COL: # columnInd = 1 # res = GSuiteTracksCoincidingWithQueryTrackTool.drawPlot( # results, additionalResultsDict, # 'Similarity to rest of tracks in suite (%s)' % summaryFunc, # columnInd=columnInd) # core.line(res) # core.divEnd() # core.divEnd() # core.end() # # if choices.addResults == 'Yes': # GSuiteStatUtils.addResultsToInputGSuite( # gsuite, results, ['Similarity_score'], # cls.extraGalaxyFn[GSUITE_EXPANDED_WITH_RESULT_COLUMNS_FILENAME]) elif analysisQuestion == cls.Q3: mcfdrDepth = choices.mcfdrDepth if choices.mcfdrDepth else \ AnalysisDefHandler(REPLACE_TEMPLATES['$MCFDR$']).getOptionsAsText().values()[0][0] analysisDefString = REPLACE_TEMPLATES[ '$MCFDRv3$'] + ' -> GSuiteRepresentativenessOfTracksRankingsAndPValuesWrapperStat' analysisSpec = AnalysisDefHandler(analysisDefString) analysisSpec.setChoice('MCFDR sampling depth', mcfdrDepth) analysisSpec.addParameter('assumptions', 'PermutedSegsAndIntersegsTrack') analysisSpec.addParameter( 'rawStatistic', SummarizedInteractionWithOtherTracksV2Stat.__name__) analysisSpec.addParameter( 'pairwiseStatistic', GSuiteStatUtils. PAIRWISE_STAT_LABEL_TO_CLASS_MAPPING[similaryStatClassName]) analysisSpec.addParameter( 'summaryFunc', GSuiteStatUtils.SUMMARY_FUNCTIONS_MAPPER[summaryFunc]) analysisSpec.addParameter('tail', 'right-tail') analysisSpec.addParameter('trackTitles', trackTitles) results = doAnalysis(analysisSpec, analysisBins, tracks).getGlobalResult() core = HtmlCore() gsPerTrackResultsModel = GSuitePerTrackResultModel( results, [ 'Similarity to rest of tracks in suite (%s)' % summaryFunc, 'P-value' ], additionalResultsDict=additionalResultsDict, additionalAttributesDict=additionalAttributesDict) if choices.leadAttribute and choices.leadAttribute != GSuiteConstants.TITLE_COL: columnTitles, decoratedResultsDict = \ gsPerTrackResultsModel.generateColumnTitlesAndResultsDict(choices.leadAttribute) else: columnTitles, decoratedResultsDict = \ gsPerTrackResultsModel.generateColumnTitlesAndResultsDict() 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 %s similarity to the rest of the tracks as measured by "%s" track similarity measure. ''' % (topTrackTitle, strWithNatLangFormatting(results[topTrackTitle][1]), strWithNatLangFormatting(results[topTrackTitle][0]), summaryFunc, similaryStatClassName)) # core.tableFromDictionary(results, columnNames=['Track title', 'Similarity to rest of tracks in suite (' + summaryFunc+')', 'P-value'], sortable=False) addTableWithTabularAndGsuiteImportButtons( core, choices, galaxyFn, cls.Q3_SHORT, decoratedResultsDict, columnTitles, gsuite=gsuite, results=results, gsuiteAppendAttrs=['similarity_score', 'p_value'], sortable=True) core.divEnd() core.divEnd() core.end() else: # Q4 mcfdrDepth = choices.mcfdrDepth if choices.mcfdrDepth else \ AnalysisDefHandler(REPLACE_TEMPLATES['$MCFDR$']).getOptionsAsText().values()[0][0] analysisDefString = REPLACE_TEMPLATES[ '$MCFDRv3$'] + ' -> CollectionSimilarityHypothesisWrapperStat' analysisSpec = AnalysisDefHandler(analysisDefString) analysisSpec.setChoice('MCFDR sampling depth', mcfdrDepth) analysisSpec.addParameter('assumptions', 'PermutedSegsAndIntersegsTrack') analysisSpec.addParameter('rawStatistic', 'MultitrackSummarizedInteractionV2Stat') analysisSpec.addParameter( 'pairwiseStatistic', GSuiteStatUtils. PAIRWISE_STAT_LABEL_TO_CLASS_MAPPING[similaryStatClassName]) analysisSpec.addParameter( 'summaryFunc', GSuiteStatUtils.SUMMARY_FUNCTIONS_MAPPER[summaryFunc]) analysisSpec.addParameter('multitrackSummaryFunc', 'avg') # should it be a choice? analysisSpec.addParameter('tail', 'right-tail') results = doAnalysis(analysisSpec, analysisBins, tracks).getGlobalResult() pval = results['P-value'] observed = results['TSMC_MultitrackSummarizedInteractionV2Stat'] 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 tracks in the suite show %s significance in their collective similarity (average similarity of a track to the rest) of %s and corresponding p-value of %s, as measured by "%s" track similarity measure. ''' % (significanceLevel, strWithNatLangFormatting(observed), strWithNatLangFormatting(pval), similaryStatClassName)) core.divEnd() core.divEnd() core.end() print 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. ''' cls._setDebugModeIfSelected(choices) genome = choices.genome queryGSuite = getGSuiteFromGalaxyTN(choices.queryGSuite) refGSuite = getGSuiteFromGalaxyTN(choices.refGSuite) if choices.similarityFunc: similarityStatClassNameKey = choices.similarityFunc else: similarityStatClassNameKey = GSuiteStatUtils.T5_RATIO_OF_OBSERVED_TO_EXPECTED_OVERLAP isPointsVsSegments, pointsGSuite, segGSuite = cls.isPointsVsSegmentsAnalysis(queryGSuite, refGSuite) regSpec, binSpec = UserBinMixin.getRegsAndBinsSpec(choices) analysisBins = GalaxyInterface._getUserBinSource(regSpec, binSpec, genome=genome) queryTrackList = [Track(x.trackName, x.title) for x in queryGSuite.allTracks()] refTrackList = [Track(x.trackName, x.title) for x in refGSuite.allTracks()] queryTrackTitles = CommonConstants.TRACK_TITLES_SEPARATOR.join( [quote(x.title, safe='') for x in queryGSuite.allTracks()]) refTrackTitles = CommonConstants.TRACK_TITLES_SEPARATOR.join( [quote(x.title, safe='') for x in refGSuite.allTracks()]) analysisSpec = AnalysisSpec(GSuiteVsGSuiteWrapperStat) analysisSpec.addParameter('queryTracksNum', str(len(queryTrackList))) analysisSpec.addParameter('refTracksNum', str(len(refTrackList))) analysisSpec.addParameter('queryTrackTitleList', queryTrackTitles) analysisSpec.addParameter('refTrackTitleList', refTrackTitles) analysisSpec.addParameter('similarityStatClassName', GSuiteStatUtils.PAIRWISE_STAT_LABEL_TO_CLASS_MAPPING[similarityStatClassNameKey]) if choices.removeZeroRow: analysisSpec.addParameter('removeZeroRow', choices.removeZeroRow) if choices.removeZeroCol: analysisSpec.addParameter('removeZeroColumn', choices.removeZeroCol) resultsObj = doAnalysis(analysisSpec, analysisBins, queryTrackList + refTrackList) results = resultsObj.getGlobalResult() # baseDir = GalaxyRunSpecificFile([RAW_OVERLAP_TABLE_RESULT_KEY], galaxyFn).getDiskPath() # rawOverlapHeatmapPresenter = HeatmapFromDictOfDictsPresenter(resultsObj, baseDir, # 'Overlapping base-pair of tracks from the two suites', # printDimensions=False) rawOverlapTableData = results[RAW_OVERLAP_TABLE_RESULT_KEY] maxRawOverlap, maxROt1, maxROt2 = rawOverlapTableData.getMaxElement() similarityScoreTableData = results[SIMILARITY_SCORE_TABLE_RESULT_KEY] maxSimScore, maxSSt1, maxSSt2 = similarityScoreTableData.getMaxElement() baseDir = GalaxyRunSpecificFile([], galaxyFn=galaxyFn).getDiskPath() heatmapPresenter = HeatmapFromTableDataPresenter(resultsObj, baseDir=baseDir, header='Overlapping base-pairs between the tracks of the two suites', printDimensions=False) tablePresenter = MatrixGlobalValueFromTableDataPresenter(resultsObj, baseDir=baseDir, header='Table of overlapping base-pairs between the tracks of the two suites') core = HtmlCore() core.begin() core.divBegin(divId='results-page') core.divBegin(divId='svs-res-main-div', divClass='svs-res-main') core.divBegin(divId='raw-overlap-div', divClass='results-section') core.divBegin(divId='raw-overlap-table', divClass='svs-table-div') core.header('Base-pair overlaps between the tracks of the two GSuites') core.paragraph("""From the tracks in the two GSuites the highest base-pair overlap <b>(%s bps)</b> is observed for the pair of <b>'%s'</b> and <b>'%s'</b>.""" % (maxRawOverlap, maxROt1, maxROt2)) core.divBegin(divId='raw-table-result', divClass='result-div') core.divBegin(divId='raw-table-result', divClass='result-div-left') core.line('''Follow the links to view the results in an HTML table or raw tabular form:''') core.divEnd() core.divBegin(divId='raw-table-result', divClass='result-div-right') core.line(tablePresenter.getReference(RAW_OVERLAP_TABLE_RESULT_KEY)) core.divEnd()#rawoverlap table core.divEnd() core.divEnd() core.divBegin(divId='raw-overlap-heatmap', divClass='svs-heatmap-div') try: core.header('Heatmap of base-pair overlaps') core.divBegin(divId='raw-table-result', divClass='result-div-heatmap') core.divBegin(divId='raw-table-result', divClass='result-div-left') core.line('''Follow the links to view the heatmap in the desired format:''') core.divEnd() core.divBegin(divId='raw-table-result', divClass='result-div-right') core.line(heatmapPresenter.getReference(RAW_OVERLAP_TABLE_RESULT_KEY)) core.divEnd() core.divEnd() except: core.line('Heatmap for the base-pair overlaps could not be created.') core.divEnd() core.divEnd() core.divEnd()#rawoverlap heatmap core.divEnd()#rawoverlap core.divBegin(divId='sim-score-div', divClass='results-section') core.divBegin(divId='sim-score-table', divClass='svs-table-div') core.header('Similarity score between the tracks of the two GSuites measured by %s' % choices.similarityFunc) core.paragraph("""From the tracks in the two GSuites the highest similarity score <b>(%s)</b> is observed for the pair of <b>'%s'</b> and <b>'%s'</b>.""" % (maxSimScore, maxSSt1, maxSSt2)) core.divBegin(divId='raw-table-result', divClass='result-div') core.divBegin(divId='raw-table-result', divClass='result-div-left') core.line("""Follow the links to view the results in an HTML table or raw tabular form:""") core.divEnd() core.divBegin(divId='raw-table-result', divClass='result-div-right') core.line(tablePresenter.getReference(SIMILARITY_SCORE_TABLE_RESULT_KEY)) core.divEnd() core.divEnd() core.divEnd()#simscore table core.divBegin(divId='sim-score-heatmap', divClass='svs-heatmap-div') try: core.header('Heatmap of similarity scores') core.divBegin(divId='raw-table-result', divClass='result-div-heatmap') core.divBegin(divId='raw-table-result', divClass='result-div-left') core.line('''Follow the links to view the heatmap in the desired format:''') core.divEnd() core.divBegin(divId='raw-table-result', divClass='result-div-right') core.line(heatmapPresenter.getReference(SIMILARITY_SCORE_TABLE_RESULT_KEY)) core.divEnd() core.divEnd() except: core.line('Heatmap for the similarity score could not be created.') core.divEnd() core.divEnd() core.divEnd()#simscore heatmap core.divEnd()#simscore core.divEnd()#results # core.paragraph( # '''Table displaying the number of base-pairs overlapping between the tracks in the two suites:''') # core.tableFromDictOfDicts(rawOverlapTableData, firstColName='Track title') # # core.paragraph(rawOverlapHeatmapPresenter.getReference(resDictKey=RAW_OVERLAP_TABLE_RESULT_KEY)) # core.paragraph( # '''Table displaying the similarity score for the tracks in the two suites as measured by %s:''' % similarityStatClassNameKey) # core.tableFromDictOfDicts(similarityScoreTableData, firstColName='Track title') # core.divEnd() core.end() print str(core)