def getOptionsBoxPrev(prevChoices): #return repr(prevChoices),3,True from proto.hyperbrowser.HtmlCore import HtmlCore core = HtmlCore() core.link('Download', 'ftp://something.com/') from collections import OrderedDict return [['a','b','c'], [str(core),'2','3'],\ ['x','y','z']]
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)
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
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 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