예제 #1
0
    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
예제 #2
0
    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(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
예제 #4
0
 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)
예제 #5
0
    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
예제 #6
0
    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)
예제 #7
0
 def _buildContent(self):
     #iterate through dictionary and for each key create a section (one of [GSuite, Track...])
     # each value in the dictionary is a list of GiudeData objects that go into the section defined by the key
     htmlCore = HtmlCore()
     htmlCore.divBegin('toolGuideInfo')
     htmlCore.divBegin(divClass='toolGuideInfoText')
     htmlCore.divBegin(divClass='toolGuideInfoTextHeader')
     htmlCore.line(TOOL_GUIDE_HELP_HEADER_TEXT)
     htmlCore.divEnd()
     htmlCore.divBegin(divClass='toolGuideInfoText')
     htmlCore.line(TOOL_GUIDE_HELP_HEADER_TEXT_TEXT)
     htmlCore.divEnd()
     htmlCore.divEnd()
     for guideDataKey, guideDataValues in self._guideDataDict.iteritems():
         htmlCore.divBegin('toolGuide')
         if guideDataKey in TOOL_INPUT_TYPE_TO_TOOL_GUIDE_HELP_HEADER_DICT:
             htmlCore.header(TOOL_INPUT_TYPE_TO_TOOL_GUIDE_HELP_HEADER_DICT[
                 guideDataKey])
         for guideDataValue in guideDataValues:
             htmlCore.divBegin(divClass='toolGuideData')
             htmlCore.divBegin(divClass='toolGuideImgTitle')
             if guideDataValue.imgUrl:
                 htmlCore.image(guideDataValue.imgUrl)
             htmlCore.link(text=guideDataValue.toolDisplayName,
                           url=str(guideDataValue.toolUrl),
                           args=(' onclick="%s"' % guideDataValue.onclick)
                           if guideDataValue.onclick else '')
             htmlCore.divEnd()
             htmlCore.divBegin(divClass='toolGuideDesc')
             htmlCore.append(guideDataValue.description)
             if guideDataValue.helpPageUrl:
                 htmlCore.link(text='...read more',
                               url=str(guideDataValue.helpPageUrl))
             htmlCore.divEnd()
             htmlCore.divEnd()
         htmlCore.divEnd()
     htmlCore.divEnd()
     #raise Exception(str(htmlCore))#to debug
     self._guideContent = str(htmlCore)
예제 #8
0
    def execute(cls, choices, galaxyFn=None, username=''):
        genome = choices.genome
         

        from quick.multitrack.MultiTrackCommon import getGSuiteDataFromGalaxyTN
        trackTitles, refTrackNameList, genome = getGSuiteDataFromGalaxyTN(choices.gsuite)
        
        queryTrackName = ExternalTrackManager.extractFnFromGalaxyTN(choices.targetTrack)
        if choices.isBasic:
            suffix = ExternalTrackManager.extractFileSuffixFromGalaxyTN(choices.targetTrack, False)
            regSpec = suffix
            binSpec = queryTrackName
        else:
            regSpec, binSpec = UserBinMixin.getRegsAndBinsSpec(choices)
        
        #targetTrack = choices.targetTrack.split(':')
        #targetTrackTitle = targetTrack[-1]
        #print targetTrackTitle
        #
        #binSpec = targetTrackTitle
        #Phenotype and disease associations:Assorted experiments:Virus integration, HPV specific, Kraus and Schmitz, including 50kb flanks

        from gold.gsuite.GSuiteConstants import TITLE_COL
        from gold.gsuite.GSuite import GSuite
        from proto.hyperbrowser.StaticFile import GalaxyRunSpecificFile
        from gold.gsuite.GSuiteEditor import selectColumnsFromGSuite
        staticFile=[]
        
        results = []
        for refTrack in refTrackNameList:
            analysisDef = '-> ProportionCountStat' #ProportionCountStat #CountStat
            res = GalaxyInterface.runManual([refTrack], analysisDef, regSpec, binSpec, genome, username=username, galaxyFn=galaxyFn, printRunDescription=False, printResults=False, printProgress=False)
            segCoverageProp = [res[seg]['Result'] for seg in res.getAllRegionKeys()]
            results.append(segCoverageProp)
            
            regFileNamer = GalaxyRunSpecificFile(refTrack, galaxyFn)
            staticFile.append([regFileNamer.getLink('Download bed-file'), regFileNamer.getLoadToHistoryLink('Download bed-file to History')])

        refGSuite = getGSuiteFromGalaxyTN(choices.gsuite)

        if TITLE_COL == choices.selectColumns:
            selected = trackTitles
        else:
            selected = refGSuite.getAttributeValueList(choices.selectColumns)

        yAxisNameOverMouse=[]
        metadataAll =[]

        for x in range(0, len(selected)):
            if selected[x] == None:
                yAxisNameOverMouse.append(str(trackTitles[x]) + ' --- ' + 'None')
            else:
                if TITLE_COL == choices.selectColumns:
                    yAxisNameOverMouse.append(selected[x].replace('\'', '').replace('"', ''))
                else:
                    metadata = str(selected[x].replace('\'', '').replace('"', ''))
                    yAxisNameOverMouse.append(str(trackTitles[x]) + ' --- ' + metadata)
                    metadataAll.append(metadata)

        colorListForYAxisNameOverMouse = []
        if len(metadataAll) > 0:
            import quick.webtools.restricted.visualization.visualizationGraphs as vg
            cList = vg.colorList().fullColorList()
            uniqueCList = list(set(metadataAll))

            for m in metadataAll:
                colorListForYAxisNameOverMouse.append(cList[uniqueCList.index(m)])

        #startEnd - order in res
        startEndInterval = []
        startEnd = []
        i=0
        

        extraX=[]
        rowLabel = []
        for ch in res.getAllRegionKeys():
            rowLabel.append(str(ch.chr) + ":" + str(ch.start) + "-" + str(ch.end) + str(' (Pos)' if ch.strand else ' (Neg)'))
            if not i==0 and not i==len(res.getAllRegionKeys())-1:
                start = ch.start
                if start-end > 0:
                    startEnd.append(start-end)
                else:
                    startEnd.append('null')
                    extraX.append("""{ color: 'orange', width: 5, value: '""" + str(i-0.5) + """' }""")
                startEndInterval.append(ch.end - ch.start)
            else:
                startEndInterval.append(ch.end - ch.start)
            end = ch.end
            i+=1

        extraXAxis='plotLines: [ '
        extraXAxis = extraXAxis + ",".join(extraX)
        extraXAxis = extraXAxis + """ ],  """

        #rowLabel = res.getAllRegionKeys()
        #rowLabel = [str(x) for x in rowLabel]
        

        import quick.webtools.restricted.visualization.visualizationPlots as vp

        htmlCore = HtmlCore()
        htmlCore.begin()
        htmlCore.divBegin(divId='results-page')
        htmlCore.divBegin(divClass='results-section')
        htmlCore.divBegin('plotDiv')
        htmlCore.line(vp.addJSlibs())
        htmlCore.line(vp.useThemePlot())
        htmlCore.line(vp.addJSlibsExport())
        htmlCore.line(vp.axaddJSlibsOverMouseAxisisPopup())
        #vp.addGuideline(htmlCore)
        htmlCore.line(vp._addGuidelineV1())

        htmlCore.line(vp.addJSlibsHeatmap())

        from config.Config import DATA_FILES_PATH

        from proto.StaticFile import StaticFile, GalaxyRunSpecificFile

        #sf = GalaxyRunSpecificFile(['result.txt'], galaxyFn)
        #outFile = sf.getDiskPath(ensurePath=True)

        htmlCore.divBegin()
        writeFile = open(
            cls.makeHistElement(galaxyExt='tabular',
                                title='result'), 'w')
        # htmlCore.link('Get all results', sf.getURL())
        htmlCore.divEnd()

        i = 0

        writeFile.write('Track' + '\t' + '\t'.join(rowLabel)+ '\n')
        for rList in results:
            writeFile.write(str(yAxisNameOverMouse[i]) + '\t' + '\t'.join([str(r) for r in rList]) + '\n')
            i+=1




        fileOutput = GalaxyRunSpecificFile(['heatmap.png'],
                                           galaxyFn)
        ensurePathExists(fileOutput.getDiskPath())

        fileOutputPdf = GalaxyRunSpecificFile(['heatmap.pdf'],
                                              galaxyFn)
        ensurePathExists(fileOutputPdf.getDiskPath())

        cls.generateStaticRPlot(results, colorListForYAxisNameOverMouse, rowLabel, yAxisNameOverMouse,
                                colorMaps[choices.colorMapSelectList],
                                fileOutput.getDiskPath(), fileOutputPdf.getDiskPath())


        htmlCore.divBegin(divId='heatmap', style="padding: 10px 0 px 10 px 0px;margin: 10px 0 px 10 px 0px")
        htmlCore.link('Download heatmap image', fileOutputPdf.getURL())
        htmlCore.divEnd()

        if len(results) * len(results[1]) >= 10000:
            htmlCore.image(fileOutput.getURL())


        else:

            min = 1000000000
            max = -1000000000
            for rList in results:
                for r in rList:
                    if min > r:
                        min = r
                    if max < r:
                        max = r




            if max-min != 0:
                resultNormalised = []
                for rList in results:
                    resultNormalisedPart = []
                    for r in rList:
                        resultNormalisedPart.append((r-min)/(max-min))
                    resultNormalised.append(resultNormalisedPart)

                addText = '(normalised to [0, 1])'
            else:
                resultNormalised = results
                addText = ''


            hm, heatmapPlotNumber, heatmapPlot = vp.drawHeatMap(
                                                    resultNormalised,
                                                    colorMaps[choices.colorMapSelectList],
                                                    label='this.series.xAxis.categories[this.point.x] + ' + "'<br >'" + ' + yAxisNameOverMouse[this.point.y] + ' + "'<br>Overlap proportion" + str(addText) + ": <b>'" + ' + this.point.value + ' + "'</b>'",
                                                    yAxisTitle= 'Reference tracks',
                                                    categories=rowLabel,
                                                    tickInterval=1,
                                                    plotNumber=3,
                                                    interaction=True,
                                                    otherPlotNumber=1,
                                                    titleText='Overlap with reference tracks for each local region',
                                                    otherPlotData=[startEnd, startEndInterval],
                                                    overMouseAxisX=True,
                                                    overMouseAxisY=True,
                                                    yAxisNameOverMouse=yAxisNameOverMouse,
                                                    overMouseLabelY=" + 'Track: '" + ' + this.value + ' + "' '" + ' + yAxisNameOverMouse[this.value] + ',
                                                    overMouseLabelX = ' + this.value.substring(0, 20) +',
                                                    extrOp = staticFile
                                                    )
            htmlCore.line(hm)
            htmlCore.line(vp.drawChartInteractionWithHeatmap(
                [startEndInterval, startEnd],
                tickInterval=1,
                type='line',
                categories=[rowLabel, rowLabel],
                seriesType=['line', 'column'],
                minWidth=300,
                height=500,
                lineWidth=3,
                titleText=['Lengths of segments (local regions)','Gaps between consecutive segments'],
                label=['<b>Length: </b>{point.y}<br/>', '<b>Gap length: </b>{point.y}<br/>'],
                subtitleText=['',''],
                yAxisTitle=['Lengths','Gap lengths'],
                seriesName=['Lengths','Gap lengths'],
                xAxisRotation=90,
                legend=False,
                extraXAxis=extraXAxis,
                heatmapPlot=heatmapPlot,
                heatmapPlotNumber=heatmapPlotNumber,
                overMouseAxisX=True,
                overMouseLabelX = ' + this.value.substring(0, 20) +'
                ))


        htmlCore.divEnd()
        htmlCore.divEnd()
        htmlCore.divEnd()
        htmlCore.end()

        htmlCore.hideToggle(styleClass='debug')

        print htmlCore