def _createPreprocessedGsuiteTrack(self,
                                       gSuiteTrack,
                                       baseFileName,
                                       doEncodeId,
                                       urlPrefix=None):
        from quick.application.ExternalTrackManager import ExternalTrackManager as ETM
        from gold.description.TrackInfo import TrackInfo

        self.genericVisit(gSuiteTrack)

        galaxyTN = ETM.constructGalaxyTnFromSuitedFn(
            gSuiteTrack.path, fileEnding=gSuiteTrack.suffix, name=baseFileName)
        trackName = ETM.getPreProcessedTrackFromGalaxyTN(
            gSuiteTrack.genome,
            galaxyTN,
            printErrors=False,
            printProgress=False,
            renameExistingTracksIfNeeded=False,
            doEncodeId=doEncodeId,
            urlPrefix=urlPrefix)

        trackType = TrackInfo(gSuiteTrack.genome,
                              trackName).trackFormatName.lower()
        hbUri = HbGSuiteTrack.generateURI(trackName=trackName)

        return GSuiteTrack(hbUri,
                           title=gSuiteTrack.title,
                           trackType=trackType,
                           genome=gSuiteTrack.genome,
                           attributes=gSuiteTrack.attributes,
                           comment=gSuiteTrack.comment)
Пример #2
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.
        '''
        from quick.application.ExternalTrackManager import ExternalTrackManager
        from quick.application.GalaxyInterface import GalaxyInterface

        from gold.application.LogSetup import setupDebugModeAndLogging
        #setupDebugModeAndLogging()

        genome = choices[0]
        tn1, tn2 = choices[1:]
        fnTn1 = ExternalTrackManager.extractFnFromGalaxyTN(tn1)

        track1 = [
            'Sequence', 'DNA'
        ]  #ExternalTrackManager.getPreProcessedTrackFromGalaxyTN(genome, tn1.split(':'))
        track2 = ExternalTrackManager.getPreProcessedTrackFromGalaxyTN(
            genome, tn2.split(':'))
        analysisDef = 'dummy -> GetMutatedSequenceStat'

        res = GalaxyInterface.runManual([track1, track2], analysisDef, 'bed',
                                        fnTn1, genome)
        with open(galaxyFn, 'w') as utfil:
            for region, sequence in res.items():
                print >> utfil, '>' + region.chr + ' ' + str(region.start +
                                                             1) + '-' + str(
                                                                 region.end)
                print >> utfil, sequence['Result']
Пример #3
0
 def _collectTracks(self):
     tracks = [self._track, self._track2]
     if 'trackNameIntensity' in self._kwArgs:
         assert not 'extraTracks' in self._kwArgs
         self._kwArgs['extraTracks'] = self._kwArgs['trackNameIntensity']
         
     if 'extraTracks' in self._kwArgs:
         from gold.track.Track import PlainTrack
         import re
         from config.Config import MULTIPLE_EXTRA_TRACKS_SEPARATOR
         extraTracks = self._kwArgs['extraTracks']
         if type(extraTracks) == str:
             extraTracks = extraTracks.split(MULTIPLE_EXTRA_TRACKS_SEPARATOR)
         for extraT in extraTracks:
             if type(extraT) == str:
                 #extraT = extraT.split('|')
                 #extraT = re.split('\^|\|',extraT)                    
                 extraT = convertTNstrToTNListFormat(extraT)
             if type(extraT) == list:
                 #print 'TEMP1: ', extraT
                 from urllib import unquote
                 extraT = [unquote(part) for part in extraT]
                 from quick.application.ExternalTrackManager import ExternalTrackManager
                 if ExternalTrackManager.isGalaxyTrack(extraT):
                     extraT = ExternalTrackManager.getPreProcessedTrackFromGalaxyTN(self.getGenome(), extraT)
                 extraT = PlainTrack(extraT)
                 tracks.append(extraT)
             
     return tracks
Пример #4
0
    def execute(cls, choices, galaxyFn=None, username=''):
        from gold.origdata.TrackGenomeElementSource import TrackViewListGenomeElementSource
        from gold.origdata.GtrackComposer import StdGtrackComposer

        genome = choices[0]
        if choices[1] == 'track':
            trackName = choices[2].split(':')
        else:
            trackName = ExternalTrackManager.getPreProcessedTrackFromGalaxyTN(
                genome, choices[2].split(':'))

        outFn = galaxyFn
        if choices[4] == 'Write to Standardised file':
            outFn = createOrigPath(genome, choices[-1].split(':'),
                                   'collapsed_result.bedgraph')
            ensurePathExists(outFn[:outFn.rfind('/') + 1])

        threshold = choices[3]
        analysisDef = 'dummy [threshold=%s] -> ForEachSegmentDistToNearestInSameTrackStat' % threshold  #'Python'
        res = GalaxyInterface.runManual([trackName], analysisDef, '*', '*', genome, username=username, \
                                        printResults=False, printHtmlWarningMsgs=False)

        tvGeSource = TrackViewListGenomeElementSource(
            genome, [x['Result'] for x in res.values()], trackName)
        StdGtrackComposer(tvGeSource).composeToFile(outFn)
Пример #5
0
    def execute(cls, choices, galaxyFn=None, username=''):
        from quick.application.ExternalTrackManager import ExternalTrackManager

        genome = choices[0]
        preProcTN1 = ExternalTrackManager.getPreProcessedTrackFromGalaxyTN(
            genome, choices[2].split(
                ':')) if choices[1] == 'history' else choices[2].split(':')
        chrSizeDict = dict([(chrom, GenomeInfo.getChrLen(genome, chrom))
                            for chrom in GenomeInfo.getChrList(genome)])

        trackType = choices[3].split(':')[1]
        fnSource = ExternalTrackManager.extractFnFromGalaxyTN(
            choices[3].split(':'))

        if trackType in ['valued.bed', 'category.bed', 'bed']:
            geSource = GenomeElementSorter(
                BedGenomeElementSource(fnSource, genome=genome)).__iter__()

        elif trackType == 'gtrack':
            geSource = GenomeElementSorter(
                GtrackGenomeElementSource(fnSource, genome=genome)).__iter__()
            #headLinesStr = geSource.getHeaderLines().replace('##','\n##')
        else:
            raise InvalidFormatError(
                'The Binning must be of the following formats: gtrack, valued.bed, category.bed ,bed ...'
            )

        cls.PrintResultToHistItem(galaxyFn, geSource, preProcTN1, genome,
                                  username)
Пример #6
0
    def visitGalaxyGSuiteTrack(self, gSuiteTrack):
        self.genericVisit(gSuiteTrack)

        from quick.application.ExternalTrackManager import ExternalTrackManager
        from gold.description.TrackInfo import TrackInfo

        if gSuiteTrack.hasExtraFileName():
            baseFileName = os.path.basename(gSuiteTrack.uriWithoutSuffix)
        else:
            baseFileName = gSuiteTrack.title

        galaxyTN = ExternalTrackManager.constructGalaxyTnFromSuitedFn(
            gSuiteTrack.path, fileEnding=gSuiteTrack.suffix, name=baseFileName)
        trackName = ExternalTrackManager.getPreProcessedTrackFromGalaxyTN(
            gSuiteTrack.genome,
            galaxyTN,
            printErrors=False,
            printProgress=False,
            renameExistingTracksIfNeeded=False)

        trackType = TrackInfo(gSuiteTrack.genome,
                              trackName).trackFormatName.lower()
        hbUri = HbGSuiteTrack.generateURI(trackName=trackName)

        return GSuiteTrack(hbUri,
                           title=gSuiteTrack.title,
                           trackType=trackType,
                           genome=gSuiteTrack.genome,
                           attributes=gSuiteTrack.attributes,
                           comment=gSuiteTrack.comment)
Пример #7
0
 def getOptionsBoxTfTracks(cls, prevChoices):
     if prevChoices.sourceTfsDetails != cls.SELECT:
         genome = prevChoices.genome
         sourceTfs = prevChoices.sourceTfs
         sourceTfsDetails = prevChoices.sourceTfsDetails
         if sourceTfs == cls.SELECT:
             return
         elif sourceTfs == 'Hyperbrowser repository':
             tfSourceTN = TfTrackNameMappings.getTfTrackNameMappings(
                 prevChoices.genome)[sourceTfsDetails]
             subtypes = ProcTrackOptions.getSubtypes(
                 prevChoices.genome, tfSourceTN, True)
             falses = ['False'] * len(subtypes)
             return OrderedDict(zip(subtypes, falses))
         elif sourceTfs == cls.REGIONS_FROM_HISTORY:
             if isinstance(sourceTfsDetails, basestring):
                 galaxyTN = sourceTfsDetails.split(':')
                 if galaxyTN[
                         1] == "gsuite":  #ExternalTrackManager.extractFileSuffixFromGalaxyTN(prevChoices.sourceTfsDetails, allowUnsupportedSuffixes=True) == "gsuite"
                     errorString = GeneralGuiTool._checkGSuiteFile(
                         sourceTfsDetails)
                     if not errorString:
                         gSuite = getGSuiteFromGalaxyTN(sourceTfsDetails)
                         sizeErrorString = GeneralGuiTool._checkGSuiteTrackListSize(
                             gSuite, 1, 1000)
                         if not sizeErrorString:
                             reqErrorString = GeneralGuiTool._checkGSuiteRequirements \
                                 (gSuite,
                                  AllTfsOfRegions.GSUITE_ALLOWED_FILE_FORMATS,
                                  AllTfsOfRegions.GSUITE_ALLOWED_LOCATIONS,
                                  AllTfsOfRegions.GSUITE_ALLOWED_TRACK_TYPES,
                                  AllTfsOfRegions.GSUITE_DISALLOWED_GENOMES)
                             if not reqErrorString:
                                 validity = 'Valid'
                             else:
                                 return
                         else:
                             return
                     else:
                         return
                     if validity == 'Valid':
                         selectedTrackNames = []
                         gSuite = getGSuiteFromGalaxyTN(sourceTfsDetails)
                         for track in gSuite.allTracks():
                             selectedTrackNames.append(':'.join(
                                 track.trackName))
                         falses = ['False'] * len(selectedTrackNames)
                         return OrderedDict(zip(selectedTrackNames, falses))
                 else:
                     tfTrackName = ExternalTrackManager.getPreProcessedTrackFromGalaxyTN(
                         genome, galaxyTN)
                     return [':'.join(tfTrackName)]
             else:
                 return
         else:
             return
     else:
         return
Пример #8
0
    def execute(cls, choices, galaxyFn=None, username=''):
        genome = choices.genome
        sourceHic = choices.sourceHic
        hicdic = choices.hicdic
        annotation = choices.annotation

        # Get Genomic Regions track names:
        selectedTrackNames = []
        if isinstance(hicdic, dict):
            selectedHiCRegions = [
                key for key, val in hicdic.iteritems() if val == 'True'
            ]
        else:
            selectedHiCRegions = hicdic

        if sourceHic == 'Hyperbrowser repository':
            selectedTrackNames = []
            for i in selectedHiCRegions:
                hicTrackName = HiCNameMappings.getHiCNameMappings(genome)[i]
                selectedTrackNames.append(hicTrackName)

                print '<p>', i, '</p>'
                print getTrackRelevantInfo.getNumberElements(
                    genome, hicTrackName)
                print getTrackRelevantInfo.getSegmentSizes(
                    genome, hicTrackName)
                #print getTrackRelevantInfo.getAnchor(genome, hicTrackName)
                targetBins = getTrackRelevantInfo.getGenomicElements(
                    genome, hicTrackName)
                print targetBins
                print '<p>==============================================</p>'

                analysis = AntoniosTool.getHiCFileFromTargetBins(
                    targetBins, galaxyFn)
                print '<p>', analysis.getLoadToHistoryLink(
                    'Send file to History'), '</p>'
                print '<p>==============================================</p>'
        elif sourceHic == cls.REGIONS_FROM_HISTORY:
            galaxyTN = selectedHiCRegions.split(':')
            hicTrackName = ExternalTrackManager.getPreProcessedTrackFromGalaxyTN(
                genome, galaxyTN)

            print '<p>', selectedHiCRegions, '</p>'
            print '<p>', hicTrackName, '</p>'
            numElements = getTrackRelevantInfo.getNumberElements(
                genome, hicTrackName)
            print 'numElements=', sum(numElements), numElements
            print getTrackRelevantInfo.getSegmentSizes(genome, hicTrackName)
            trackElements = getTrackRelevantInfo.getGenomicElements(
                genome, hicTrackName)
            print len(trackElements), trackElements
            print '<p>==============================================</p>'

            analysis = AntoniosTool.getHiCFileFromTargetBins(
                trackElements, galaxyFn)
            print '<p>', analysis.getLoadToHistoryLink(
                'Send file to History'), '</p>'
            print '<p>==============================================</p>'
Пример #9
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.
     '''
     
     genome = choices[0]
     trackList =  choices[2].values()
     print trackList
     
     from quick.application.ExternalTrackManager import ExternalTrackManager
     for track in trackList:
         ExternalTrackManager.getPreProcessedTrackFromGalaxyTN(genome, track.split(':'))
     print 'Executing...'
Пример #10
0
    def _collectTracks(self):
        tracks = [self._track, self._track2]
        #Map trackNameIntensity over to extraTrack, if extraTrack does not exist in itself (to allow selection of third track in GUI and through some existing code interfaces)
        if 'trackNameIntensity' in self._kwArgs:
            if not 'extraTracks' in self._kwArgs:
                self._kwArgs['extraTracks'] = self._kwArgs[
                    'trackNameIntensity']

        if 'extraTracks' in self._kwArgs:
            from gold.util.CommonConstants import MULTIPLE_EXTRA_TRACKS_SEPARATOR
            extraTracks = self._kwArgs['extraTracks']
            if isinstance(extraTracks, basestring):
                extraTracks = extraTracks.split(
                    MULTIPLE_EXTRA_TRACKS_SEPARATOR)
            for extraT in extraTracks:

                #HACK for tests
                if isinstance(
                        extraT,
                    (Track, SampleTrack)):  #SampleTrack is used by tests
                    if str(extraT) not in self._trackDict:
                        self._trackDict[str(extraT)] = extraT
                        tracks.append(extraT)
                    else:
                        tracks.append(self._trackDict[str(extraT)])
                #####################################
                else:
                    if isinstance(extraT, basestring):
                        #extraT = extraT.split('|')
                        #extraT = re.split('\^|\|',extraT)
                        extraT = convertTNstrToTNListFormat(extraT,
                                                            doUnquoting=False)
                    if type(extraT) == list:
                        from urllib import unquote
                        extraT = [unquote(part) for part in extraT]
                        from quick.application.ExternalTrackManager import ExternalTrackManager
                        if ExternalTrackManager.isGalaxyTrack(extraT):
                            extraT = ExternalTrackManager.getPreProcessedTrackFromGalaxyTN(
                                self.getGenome(), extraT)
                        #extraT = PlainTrack(extraT)
                        #extraT = Track(extraT)
                        #tracks.append(extraT)
                        if str(extraT) not in self._trackDict:
                            extraTrack = Track(extraT)
                            self._trackDict[str(extraT)] = extraTrack
                            tracks.append(extraTrack)
                        else:
                            tracks.append(self._trackDict[str(extraT)])

        return tracks
    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)

        # Print tool information
        cls.htmlClusterTitle(cls.getToolName(), htmlCore)
        cls.htmlClusterSubtext(choices.distanceMeasure, cls.CLUSTER_LIST, choices.linkageCriterion, htmlCore)
        htmlCore.line('Threshold of r<sup>2</sup>: ' + choices.rSquare)

        # Analysis environment
        gSuite = getGSuiteFromGalaxyTN(choices.gSuite)
        analysisBins = GlobalBinSource(gSuite.genome)
        analysisSpec = AnalysisSpec(ExpandTrackAndMatchStat)

        splitName = choices.ldTrack.split(":")
        trackName = ExternalTrackManager.getPreProcessedTrackFromGalaxyTN(gSuite.genome, splitName)
        linkedPointTrack = Track(trackName)

        # Find distance/correlation matrix
        labels = []
        distDict = cls.createDistDict(cls.CLUSTER_LIST)
        size = gSuite.numTracks()
        for i in range(0, size):
            gSuiteTrack1 = gSuite.getTrackFromIndex(i)
            labels.append(gSuiteTrack1.title)
            for j in range(i + 1, size):
                gSuiteTrack2 = gSuite.getTrackFromIndex(j)
                track1 = Track(gSuiteTrack1.trackName)
                track2 = Track(gSuiteTrack2.trackName)
                count = doAnalysis(analysisSpec, analysisBins, [track1, track2, linkedPointTrack]).getGlobalResult()
                cls.updateDistDict(distDict, count)

        # Cluster and print plots
        cls.printDistPlots(distDict, labels, choices.distanceMeasure, choices.linkageCriterion, galaxyFn, htmlCore)

        cls.htmlClusterTime(str(time.clock() - start), htmlCore)
        htmlCore.divEnd()
        print htmlCore
 def execute(cls, choices, galaxyFn=None, username=''):
     from gold.origdata.TrackGenomeElementSource import TrackViewListGenomeElementSource
     from gold.origdata.GtrackComposer import StdGtrackComposer
     genome = choices[0]
     if choices[1] == 'Track':
         trackName = choices[2].split(':')
     else:
         trackName = ExternalTrackManager.getPreProcessedTrackFromGalaxyTN(genome, choices[2].split(':'))
         
     outFn = galaxyFn
     if choices[4] == 'Write to Standardised file':
         outFn = createOrigPath(genome, choices[-1].split(':'), 'collapsed_result.bedgraph')
         ensurePathExists(outFn[:outFn.rfind('/')+1])
            
     threshold = choices[3]
     analysisDef = 'dummy [threshold=%s] -> ForEachSegmentDistToNearestInSameTrackStat' % threshold #'Python'
     res = GalaxyInterface.runManual([trackName], analysisDef, '*', '*', genome, username=username, \
                                     printResults=False, printHtmlWarningMsgs=False)
             
     tvGeSource = TrackViewListGenomeElementSource(genome, [x['Result'] for x in res.values()], trackName)    
     StdGtrackComposer(tvGeSource).composeToFile(outFn)
 def execute(cls, choices, galaxyFn=None, username=''):
     from quick.application.ExternalTrackManager import ExternalTrackManager
     
     genome = choices[0]
     preProcTN1 = ExternalTrackManager.getPreProcessedTrackFromGalaxyTN(genome, choices[2].split(':')) if choices[1] == 'History' else choices[2].split(':')
     chrSizeDict =  dict([ ( chrom, GenomeInfo.getChrLen(genome, chrom)) for chrom in GenomeInfo.getChrList(genome)])
     
     
     trackType = choices[3].split(':')[1]
     fnSource = ExternalTrackManager.extractFnFromGalaxyTN(choices[3].split(':'))
     
     if trackType in ['marked.bed', 'category.bed', 'bed']:
         geSource = GenomeElementSorter(BedGenomeElementSource(fnSource, genome=genome)).__iter__()
         
     elif trackType == 'gtrack':
         geSource = GenomeElementSorter(GtrackGenomeElementSource(fnSource, genome=genome)).__iter__()
         #headLinesStr = geSource.getHeaderLines().replace('##','\n##')
     else:
         raise InvalidFormatError('The Binning must be of the following formats: gtrack, marked.bed, category.bed ,bed ...')
         
         
     cls.PrintResultToHistItem( galaxyFn, geSource, preProcTN1, genome, username)
Пример #14
0
    def preprocessTrack(genome, dataset):
        suffixForFile = extractFileSuffixFromDatasetInfo(dataset)

        if (suffixForFile == 'bed'):
            trackName = ExternalTrackManager.getPreProcessedTrackFromGalaxyTN(
                genome, dataset, printErrors=False, printProgress=False)
            return trackName

        elif (suffixForFile == 'gsuite'):
            trackName = []
            trackTitle = []
            # l = []
            gSuite = getGSuiteFromGalaxyTN(dataset)
            for i, iTrack in enumerate(gSuite.allTracks()):
                # l = dir(iTrack)
                # if 'trackName' in l:
                #     print(iTrack.trackName)
                # else:
                #     print('not found')

                #print iTrack, iTrack.trackName, iTrack.title, '<br>'
                trackName.append(iTrack.trackName)
                trackTitle.append(iTrack.title)
            return trackName, trackTitle
    def execute(cls, choices, galaxyFn=None, username=""):

        from quick.application.GalaxyInterface import GalaxyInterface

        fileformat = choices[6]
        outputFile = open(galaxyFn, "w")

        if fileformat == "html":
            print GalaxyInterface.getHtmlBeginForRuns(galaxyFn)
            print GalaxyInterface.getHtmlForToggles(withRunDescription=False)
            t = calendar.timegm(time.gmtime())
            htmlfile = GalaxyRunSpecificFile(["fet", str(t)], galaxyFn)

        genome = choices[0]
        track1 = choices[1].split(":")
        track2 = choices[2].split(":")
        tn1 = ExternalTrackManager.getPreProcessedTrackFromGalaxyTN(genome, track1)
        tn2 = ExternalTrackManager.getPreProcessedTrackFromGalaxyTN(genome, track2)

        windowSize = int(choices[3])
        windowStep = int(choices[4])
        percentile = float(choices[5])

        # results = {}

        # TODO: why this?
        # tr = Track(tn1)
        # tr.addFormatReq(TrackFormatReq(dense=False, allowOverlaps=True))

        outputFile.write("#seqid\tstart\tscore\tstddev\n")

        if fileformat == "html":
            text = "#seqid\tstart\tscore\tstddev\n"
        print "chrs:", str(GenomeInfo.getChrList(genome))
        reg = "*"
        bins = "*"
        analysisDef = "Dummy: dummy name ([wStep=%g] [wSize=%g] [percentile=%g])-> FisherExactScoreStat" % (
            windowStep,
            windowSize,
            percentile,
        )
        userBinSource = GalaxyInterface._getUserBinSource(reg, bins, genome)
        result = GalaxyInterface.runManual([tn1, tn2], analysisDef, reg, bins, genome, galaxyFn=galaxyFn)
        for key in result.getAllRegionKeys():
            chrom = str(key).split(":")[0]
            r = result[key]
            if "Result" not in r.keys():
                print "skipping chr:", chrom, r
                continue
            r = r["Result"]
            scores = r[0]
            stddev = r[1]
            for i in range(len(scores)):
                if scores[i] != 0:
                    pos = i * windowStep
                    # if choices[5] == "html":
                    # print "%s\t%s\t%s\t%s\n" % (str(chrom), pos, str(scores[i]), str(stddev[i]))
                    if fileformat == "tabular":
                        outputFile.write("%s\t%s\t%s\t%s\n" % (str(chrom), pos, str(scores[i]), str(stddev[i])))
                    else:
                        text += "%s\t%s\t%s\t%s\n" % (str(chrom), pos, str(scores[i]), str(stddev[i]))

        if fileformat == "html":
            htmlfile.writeTextToFile(text)
            print htmlfile.getLink("Result file")
            print GalaxyInterface.getHtmlEndForRuns()

        outputFile.close()
Пример #16
0
    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
    def execute(cls, choices, galaxyFn=None, username=''):
        cls._setDebugModeIfSelected(choices)

        genome = choices.genome
        genomicRegionsSource = choices.genomicRegionsSource
        genomicRegions = choices.genomicRegions
        #upFlankSize = int(choices.upFlankSize)
        #downFlankSize = int(choices.downFlankSize)
        sourceTfs = choices.sourceTfs
        tfTracks = choices.tfTracks

        # Get TF track name:
        if sourceTfs == cls.REGIONS_FROM_HISTORY:
            galaxyTN = tfTracks.split(':')
            tfTrackName = ExternalTrackManager.getPreProcessedTrackFromGalaxyTN(
                genome, galaxyTN)
        else:
            tfTrackName = TfTrackNameMappings.getTfTrackNameMappings(
                genome)[sourceTfs] + [tfTracks]

        # Get Genomic Regions track names:
        selectedTrackNames = []

        if isinstance(genomicRegions, dict):
            selectedGenRegions = [
                key for key, val in genomicRegions.iteritems() if val == 'True'
            ]
        else:
            selectedGenRegions = genomicRegions

        if genomicRegionsSource == 'Hyperbrowser repository (single tracks)':
            for i in selectedGenRegions:
                selectedTrackNames.append(
                    TfbsTrackNameMappings.getTfbsTrackNameMappings(genome)[i])
        elif genomicRegionsSource == 'Hyperbrowser repository (cell-specific multi-tracks)':
            for i in selectedGenRegions:
                genElementGSuiteName = TfbsGSuiteNameMappings.getTfbsGSuiteNameMappings(
                    genome)[i]
                gSuite = getGSuiteFromGSuiteFile(genElementGSuiteName)
                for track in gSuite.allTracks():
                    selectedTrackNames.append(track.trackName)
        elif genomicRegionsSource == 'History (user-defined)':
            if genomicRegions.split(":")[1] == "gsuite":
                gSuite = getGSuiteFromGalaxyTN(selectedGenRegions)
                for track in gSuite.allTracks():
                    selectedTrackNames.append(track.trackName)
            else:
                galaxyTN = selectedGenRegions.split(':')
                gRegTrackName = ExternalTrackManager.getPreProcessedTrackFromGalaxyTN(
                    genome, galaxyTN)
                selectedTrackNames.append(gRegTrackName)
        else:
            return

        #Intersection:
        title = 'Targets of ' + tfTrackName[-1] + ' TF track'
        htmlCore = HtmlCore()
        htmlCore.begin()
        htmlCore.header(title)
        htmlCore.divBegin('resultsDiv')
        htmlCore.tableHeader([
            'Genomic Region', 'Number of Target Regions',
            'Download bed file of Target Regions', 'Send bed file to history'
        ],
                             sortable=True,
                             tableId='resultsTable')

        n = 0
        allTargetBins = []
        dataY = []
        allRefSetNames = []
        #print 'all:', selectedTrackNames, '<p>'
        #print 'tf:', tfTrackName, '<p>'
        for i in selectedTrackNames:
            n = n + 1
            #newGalaxyFn = galaxyFn.split(".")[0] + str(n) + "." + "dat"

            tfIntersection = TrackIntersection(genome, i, tfTrackName,
                                               galaxyFn, str(n))
            #tfIntersection.expandReferenceTrack(upFlankSize, downFlankSize)
            regFileNamer = tfIntersection.getIntersectedRegionsStaticFileWithContent(
            )
            targetBins = tfIntersection.getIntersectedReferenceBins()
            '''print 'Target Bins = ', targetBins, '<p>'
            if genomicRegionsSource=='Hyperbrowser repository (single tracks)':
                print '\"', tfTracks, '\" in \"', ":".join((i[len(i)-2],i[len(i)-1])), '":<p>'
            elif genomicRegionsSource=='History (user-defined)':
                print '\"', tfTracks, '\" in \"', i[len(i)-1], '":<p>'
            else:
                listGenRegion = i[0].split(":")
                maxIndex = len(listGenRegion)-1
                print '\"', tfTracks, '\" in \"', ":".join((listGenRegion[maxIndex-1],listGenRegion[maxIndex])), '":<p>'
            print '<p>Number of Targets = ', len(targetBins), 'regions.</p>'
            print '<p>', regFileNamer.getLink('Download bed-file'), ' of all regions with 1 or more hits.</p>'
            print '<p>', regFileNamer.getLoadToHistoryLink('Download bed-file to History'), ' of all regions with 1 or more hits.</p>'
            print '<p>==============================================</p>'
            #with open(galaxyFn, 'w') as outFile:
                #print>>outFile, 'TargetBins=', targetBins, '<p>'
                #print >>outFile, selectedGenRegions, '<p>' '''
            # Collect all target bins and data to plot:
            allTargetBins = allTargetBins + targetBins
            dataY = dataY + [
                TrackIntersection.prepareDataForPlot(genome, targetBins)
            ]
            refSetName = i[len(i) - 1]
            allRefSetNames = allRefSetNames + [refSetName]

            # Print output to table:
            line = [refSetName] + [len(targetBins)] + [
                regFileNamer.getLink('Download bed-file')
            ] + [
                regFileNamer.getLoadToHistoryLink(
                    'Download bed-file to History')
            ]
            #print line, '<p>'
            htmlCore.tableLine(line)

        line = ['Total'] + [len(allTargetBins)] + [''] + ['']
        dataY = dataY + [
            TrackIntersection.prepareDataForPlot(genome, allTargetBins)
        ]
        allRefSetNames = allRefSetNames + ['Total']

        htmlCore.tableLine(line)
        htmlCore.tableFooter()
        htmlCore.divEnd()
        htmlCore.hideToggle(styleClass='debug')
        htmlCore.end()
        print htmlCore
        #print 'ALL Target Bins = ', allTargetBins, '<p>'
        #print 'dataY = ', dataY, '<p>'

        # Plot:
        if genome == 'hg19':
            chrNames = [
                'chr1', 'chr2', 'chr3', 'chr4', 'chr5', 'chr6', 'chr7', 'chr8',
                'chr9', 'chr10', 'chr11', 'chr12', 'chr13', 'chr14', 'chr15',
                'chr16', 'chr17', 'chr18', 'chr19', 'chr20', 'chr21', 'chr22',
                'chrX', 'chrY'
            ]
        if genome == 'mm9':
            chrNames = [
                'chr1', 'chr2', 'chr3', 'chr4', 'chr5', 'chr6', 'chr7', 'chr8',
                'chr9', 'chr10', 'chr11', 'chr12', 'chr13', 'chr14', 'chr15',
                'chr16', 'chr17', 'chr18', 'chr19', 'chrX', 'chrY'
            ]

        titleText = 'Targets per Chromosome'
        dataX = [[dataY[i][j] for i in range(len(dataY))]
                 for j in range(len(dataY[0]))]
        seriesType = ['column'] * len(dataX)
        categories = allRefSetNames
        yAxisTitle = 'Number of Targets'
        seriesName = chrNames
        shared = False
        legend = True
        xAxisRotation = 0
        #print 'dataX = ', dataX, '<p>'

        htmlCore = HtmlCore()
        htmlCore.begin()
        title = 'Targets of ' + tfTrackName[-1] + ' TF track per chromosome'
        htmlCore.header(title)
        htmlCore.line('<a href="#" id="linkContainer1">Click to see plot</a>')
        htmlCore.divBegin(divId='plotDiv', style=' margin: 0 auto')
        htmlCore.line(vp.addJSlibs())
        htmlCore.line(vp.useThemePlot())
        htmlCore.line(vp.addJSlibsExport())
        plot = vp.drawChart(dataX,
                            type='column',
                            legend=legend,
                            height=600,
                            xAxisRotation=xAxisRotation,
                            seriesType=seriesType,
                            seriesName=seriesName,
                            shared=shared,
                            titleText=titleText,
                            overMouseAxisX=True,
                            categories=categories,
                            showChartClickOnLink=True)
        htmlCore.line(plot)
        htmlCore.divEnd()
        htmlCore.end()
        print htmlCore
Пример #18
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.
        :param choices:  Dict holding all current selections
        :param galaxyFn:
        :param username:
        """

        cls._setDebugModeIfSelected(choices)
        genome = choices.genome
        queryTrackNameAsList = ExternalTrackManager.getPreProcessedTrackFromGalaxyTN(genome, choices.queryTrack,
                                                                                     printErrors=False,
                                                                                     printProgress=False)
        if choices.intensityTrack:
            intensityTrackNameAsList = ExternalTrackManager.getPreProcessedTrackFromGalaxyTN(genome, choices.intensityTrack,
                                                                                     printErrors=False,
                                                                                     printProgress=False)
        else:
            intensityTrackNameAsList = None
        analysisQuestion = choices.analysisQName
        similarityStatClassName = 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'
        if analysisQuestion in [cls.Q2, cls.Q3]:
            randStrat = 'PermutedSegsAndIntersegsTrack_' if choices.isBasic else GSuiteStatUtils.PAIRWISE_RAND_CLS_MAPPING[choices.randStrat]

        gsuite = getGSuiteFromGalaxyTN(choices.gsuite)
        regSpec, binSpec = UserBinMixin.getRegsAndBinsSpec(choices)
        analysisBins = GalaxyInterface._getUserBinSource(regSpec, binSpec, genome=genome)
        queryTrack = Track(queryTrackNameAsList)
        tracks = [queryTrack] + [Track(x.trackName, trackTitle=x.title) for x in gsuite.allTracks()]
        queryTrackTitle = prettyPrintTrackName(queryTrack.trackName).replace('/', '_')
        trackTitles = CommonConstants.TRACK_TITLES_SEPARATOR.join(
            [quote(queryTrackTitle)] + [quote(x.title, safe='') for x in gsuite.allTracks()])
        additionalResultsDict = OrderedDict()
        additionalAttributesDict = OrderedDict()
        if analysisQuestion in [cls.Q1, cls.Q2]:
            additionalAttributesDict = cls.getSelectedAttributesForEachTrackDict(choices.additionalAttributes, gsuite)
            # additional analysis
            stats = [SingleValueOverlapStat, CountStat,
                     CountElementStat]  # + [CountSegmentsOverlappingWithT2Stat] #takes long time
            additionalResultsDict = runMultipleSingleValStatsOnTracks(gsuite, stats, analysisBins,
                                                                      queryTrack=queryTrack)

        core = HtmlCore()
        if analysisQuestion == cls.Q1:
            analysisSpec = cls.prepareQ1(reverse, similarityStatClassName, trackTitles)

            results = doAnalysis(analysisSpec, analysisBins, tracks).getGlobalResult()

            gsPerTrackResultsModel = GSuitePerTrackResultModel(results, ['Similarity to query track'],
                                                               additionalResultsDict=additionalResultsDict,
                                                               additionalAttributesDict=additionalAttributesDict)
            if choices.leadAttribute and choices.leadAttribute != GSuiteConstants.TITLE_COL:
                gsPerTrackResults = gsPerTrackResultsModel.generateColumnTitlesAndResultsDict(choices.leadAttribute)
            else:
                gsPerTrackResults = gsPerTrackResultsModel.generateColumnTitlesAndResultsDict()

            core = cls.generateQ1output(additionalResultsDict, analysisQuestion, choices, galaxyFn, gsPerTrackResults,
                                        queryTrackTitle, gsuite, results, similarityStatClassName)
        elif analysisQuestion == cls.Q2:
            analysisSpec = cls.prepareQ2(choices, similarityStatClassName, trackTitles, randStrat,
                                         intensityTrackNameAsList)

            results = doAnalysis(analysisSpec, analysisBins, tracks).getGlobalResult()

            core = cls.generateQ2Output(additionalAttributesDict, additionalResultsDict,
                                        analysisQuestion, choices, galaxyFn, queryTrackTitle,
                                        gsuite, results, similarityStatClassName)
        else:  # Q3
            analysisSpec = cls.prepareQ3(choices, similarityStatClassName, summaryFunc, randStrat)
            results = doAnalysis(analysisSpec, analysisBins, tracks).getGlobalResult()
            core = cls.generateQ3output(analysisQuestion, queryTrackTitle, results, similarityStatClassName)

        print str(core)
Пример #19
0
def getSingleTrackTS(genome, guiSelectedTrack, title='Dummy'):
    trackName = ExternalTrackManager.getPreProcessedTrackFromGalaxyTN(genome, guiSelectedTrack)
    return SingleTrackTS(PlainTrack(trackName), {'title': title})
    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 gold.gsuite.GSuiteComposer as GSuiteComposer
        from gold.gsuite.GSuite import GSuite
        from gold.gsuite.GSuiteTrack import GSuiteTrack, HbGSuiteTrack
        from gold.origdata.TrackGenomeElementSource import TrackViewListGenomeElementSource
        from gold.origdata.FileFormatComposer import getComposerClsFromFileSuffix
        from quick.multitrack.MultiTrackCommon import getGSuiteFromGalaxyTN
        from quick.application.ExternalTrackManager import ExternalTrackManager
        from quick.application.GalaxyInterface import GalaxyInterface
        from quick.application.UserBinSource import UserBinSource
        from quick.extra.TrackExtractor import TrackExtractor

        genome = choices.genome
        gSuite = getGSuiteFromGalaxyTN(choices.gSuite)

        if choices.withOverlaps == cls.NO_OVERLAPS:
            if choices.trackSource == cls.FROM_HISTORY_TEXT:
                filterTrackName = ExternalTrackManager.getPreProcessedTrackFromGalaxyTN(genome, choices.trackHistory)
            else:
                filterTrackName = choices.track.split(':')
        else:
            if choices.trackSource == cls.FROM_HISTORY_TEXT:
                regSpec = ExternalTrackManager.extractFileSuffixFromGalaxyTN(choices.trackHistory)
                binSpec = ExternalTrackManager.extractFnFromGalaxyTN(choices.trackHistory)
            else:
                regSpec = 'track'
                binSpec = choices.track

            userBinSource = UserBinSource(regSpec, binSpec, genome)

        desc = cls.OUTPUT_GSUITE_DESCRIPTION
        emptyFn = cls.extraGalaxyFn \
            [getGSuiteHistoryOutputName('nointersect', description=desc, datasetInfo=choices.gSuite)]
        primaryFn = cls.extraGalaxyFn \
            [getGSuiteHistoryOutputName('primary', description=desc, datasetInfo=choices.gSuite)]
        errorFn = cls.extraGalaxyFn \
            [getGSuiteHistoryOutputName('nopreprocessed', description=desc, datasetInfo=choices.gSuite)]
        preprocessedFn = cls.extraGalaxyFn \
            [getGSuiteHistoryOutputName('preprocessed', description=desc, datasetInfo=choices.gSuite)]
        hiddenStorageFn = cls.extraGalaxyFn \
            [getGSuiteHistoryOutputName('storage', description=desc, datasetInfo=choices.gSuite)]

        analysisDef = '-> TrackIntersectionStat'
#         analysisDef = '-> TrackIntersectionWithValStat'

        numTracks = gSuite.numTracks()
        progressViewer = ProgressViewer([(cls.PROGRESS_INTERSECT_MSG, numTracks),
                                         (cls.PROGRESS_PREPROCESS_MSG, numTracks)], galaxyFn)
        emptyGSuite = GSuite()
        primaryGSuite = GSuite()

        for track in gSuite.allTracks():
            newSuffix = cls.OUTPUT_TRACKS_SUFFIX
            extraFileName = os.path.sep.join(track.trackName)
            extraFileName = changeSuffixIfPresent(extraFileName, newSuffix=newSuffix)
            title = getTitleWithSuffixReplaced(track.title, newSuffix)

            primaryTrackUri = GalaxyGSuiteTrack.generateURI(
                galaxyFn=hiddenStorageFn, extraFileName=extraFileName,
                suffix=newSuffix if not extraFileName.endswith(newSuffix) else '')
            primaryTrack = GSuiteTrack(primaryTrackUri, title=title,
                                       genome=track.genome, attributes=track.attributes)

            if choices.withOverlaps == cls.NO_OVERLAPS:
                res = GalaxyInterface.runManual([track.trackName, filterTrackName], analysisDef, '*', '*',
                                                 genome=genome, galaxyFn=galaxyFn, username=username)

                trackViewList = [res[key]['Result'] for key in sorted(res.keys())]

                tvGeSource = TrackViewListGenomeElementSource(genome, trackViewList)

                composerCls = getComposerClsFromFileSuffix(cls.OUTPUT_TRACKS_SUFFIX)
                composerCls(tvGeSource).composeToFile(primaryTrack.path)
            else:
                TrackExtractor.extractOneTrackManyRegsToOneFile( \
                    track.trackName, userBinSource, primaryTrack.path, fileFormatName=cls.OUTPUT_TRACKS_SUFFIX, \
                    globalCoords=True, asOriginal=False, allowOverlaps=True)

            # Temporary hack until better solution for empty result tracks have been implemented

            from gold.origdata.GenomeElementSource import GenomeElementSource
            geSource = GenomeElementSource(primaryTrack.path, genome=genome, suffix=cls.OUTPUT_TRACKS_SUFFIX)

            try:
                geSource.parseFirstDataLine()
                primaryGSuite.addTrack(primaryTrack)
            except Exception, e: # Most likely empty file
                primaryTrack.comment = e.message
                emptyGSuite.addTrack(primaryTrack)
                numTracks -= 1
                progressViewer.updateProgressObjectElementCount(
                    cls.PROGRESS_PREPROCESS_MSG, numTracks)
            #

            progressViewer.update()
Пример #21
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 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.
        '''

        choices = list(choices)
        if choices[1] == 'history':
            choices[2] = ':'.join(
                ExternalTrackManager.getPreProcessedTrackFromGalaxyTN(
                    choices[0], choices[2].split(':')))
        genome, inTrackName, tf = cls._getBasicTrackFormat(choices,
                                                           tnChoiceIndex=2)

        statistic = choices[3]
        winSize = int(choices[4])

        #print 'Format: ', tf

        if tf.split()[-1] == 'points':
            if statistic == 'Point density in window':
                func = lambda tv: len(tv.startsAsNumpyArray()) * 1.0 / len(tv)
            elif statistic == 'Number of points in window':
                func = lambda tv: len(tv.startsAsNumpyArray())

        elif tf.split()[-1] == 'segments':
            if statistic == 'Coverage proportion in window':
                func = lambda tv: sum(len(x) for x in tv) * 1.0 / len(tv)
            elif statistic == 'Density of segments in window (based on number of segments)':
                func = lambda tv: len(tv.startsAsNumpyArray()) * 1.0 / len(tv)
            elif statistic == 'Number of segments in window':
                func = lambda tv: len(tv.startsAsNumpyArray())

        elif tf == 'function':
            if statistic == 'Mean function value in window':
                func = lambda tv: tv.valsAsNumpyArray().sum(dtype='float64'
                                                            ) / len(tv)
            elif statistic == 'Maximum function value in window':
                func = lambda tv: tv.valsAsNumpyArray().max()
            elif statistic == 'Minimum function value in window':
                func = lambda tv: tv.valsAsNumpyArray().min()
        else:
            raise
        #if choices[4] == 'HyperBrowser track':
        #    outTrackName = choices[5]
        #else:
        outTrackName = 'galaxy:hbfunction:%s:Create smoothing or density track' % galaxyFn

        from quick.application.GalaxyInterface import GalaxyInterface
        print GalaxyInterface.getHbFunctionOutputBegin(galaxyFn,
                                                       withDebug=True)

        #print 'cleaning..'
        #print 'inTrackName: ', inTrackName
        #inTrackName = GalaxyInterface._cleanUpTracks([inTrackName], genome, True)[0]
        #print 'creating..'
        GalaxyInterface.createCustomTrack(genome, inTrackName, outTrackName,
                                          winSize, func, username)

        infoMsg = 'A custom track has been created by applying the function "%s" on elements of the track "%s" in a sliding window of size %i along the genome "%s".' % (
            statistic, ':'.join(inTrackName), winSize, genome)
        print GalaxyInterface.getHbFunctionOutputEnd(infoMsg, withDebug=True)
Пример #22
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.
        '''

        genome = choices[0]
        regSpec = '__chrs__'
        binSpec = '*'
        if choices[6] == 'Chromosome arms':
            regSpec = '__chrArms__'
        elif choices[6] == 'Track from history...':
            #put in history bins support here
            #print choices[4:]
            regSpec = ExternalTrackManager.extractFileSuffixFromGalaxyTN(choices[7].split(':'))
            binSpec = ExternalTrackManager.extractFnFromGalaxyTN(choices[7].split(':'))
            #print 'regSpec, binSpec,', regSpec, binSpec
            lineList, counter, tooManyBins = [], 0, False
            for line in open(binSpec):
                if line.strip() !='':
                    if counter == cls.MAX_NUM_ROWS:
                        tooManyBins = True
                        break
                    lineList.append(line)
                    counter+= 1 if line.strip()[0] !='#' else 0

            if tooManyBins:
                newHist = GalaxyRunSpecificFile(['newHistFile.%s' % regSpec], galaxyFn)
                binSpec = newHist.getDiskPath(ensurePath=True)
                open(binSpec, 'w').write(''.join(lineList))

        print GalaxyInterface.getHtmlBeginForRuns(galaxyFn)
        print GalaxyInterface.getHtmlForToggles(withRunDescription=False)

        core = HtmlCore()
        core.styleInfoBegin(styleClass='debug')

        figImage = GalaxyRunSpecificFile(['VizTrackOnGenome.png'], galaxyFn)
        #StaticImage(['VizTrackOnGenome.png'])
        analysisDef = ' [normalizeRows=%s] [centerRows=%s]  -> RawVisualizationDataStat' % \
            (choices[4] == 'Scale to same size', choices[5] == 'Center')

        if choices[1] == 'HyperBrowser repository':
            trackName = choices[2].split(':')
        else:
            trackName = ExternalTrackManager.getPreProcessedTrackFromGalaxyTN(genome, choices[3].split(':'))

        res = GalaxyInterface.runManual([trackName], analysisDef, regSpec, binSpec, genome, username=username, printResults=False, printHtmlWarningMsgs=False)

        core.styleInfoEnd()
        core.line('')

        core.tableHeader(None)
        #visPresenter = RawVisualizationPresenter(res, galaxyFn,'')#os.path.split()[0]
        #htmlStreng = visPresenter.getReference('Result', fullImage=True)
        rScript = cls.customRExecution(res, figImage.getDiskPath(ensurePath=True), '')

        figUrl = figImage.getURL()
        figLinkText ='<img src="%s" alt="Figure" height="%i" width="800"/>' % (figUrl, 20 *min(cls.MAX_NUM_ROWS, len(res)))
        core.tableLine([figImage.getLink(figLinkText)])

        rScriptGalaxyFile = GalaxyRunSpecificFile(['RScript.R'], galaxyFn)
        with open(rScriptGalaxyFile.getDiskPath(ensurePath=True), 'w') as rScriptFile:
            rScriptFile.write(rScript)

        core.tableLine([rScriptGalaxyFile.getLink('R script')])

        core.tableFooter()

        print core
        print GalaxyInterface.getHtmlEndForRuns()
    def execute(cls, choices, galaxyFn=None, username=''):
        from quick.application.GalaxyInterface import GalaxyInterface

        fileformat = choices[9];
        outputFile = open(galaxyFn, "w")
        
        if fileformat == "html":
            print GalaxyInterface.getHtmlBeginForRuns(galaxyFn)
            print GalaxyInterface.getHtmlForToggles(withRunDescription=False)
            t = calendar.timegm(time.gmtime())
            htmlfile = GalaxyRunSpecificFile(["css", str(t)], galaxyFn);


        genome = choices[0]
        track1 = choices[1].split(":")
        track2 = choices[2].split(":")
        tn1 = ExternalTrackManager.getPreProcessedTrackFromGalaxyTN(genome, track1)
        tn2 = ExternalTrackManager.getPreProcessedTrackFromGalaxyTN(genome, track2)

        compare = choices[3] != "Count individual SNP-differences in window"
        if choices[4] == "Classical MDS":
            mds = 0;
        elif choices[4] == "SMACOF":
            mds = 1;
        else:
            mds = 2;
        windowSize = int(choices[5])
        windowStep = int(choices[6])
        
        mcTreshold = int(choices[7])
        mcRuns = int(choices[8])

        outputFile.write("#seqid\tstart\tscore\tp\n")
        if fileformat == "html":
            text = "#seqid\tstart\tscore\tp\n";

	print "chrs:"+str(GenomeInfo.getChrList(genome))
        reg = "*"
        bins = "*"
        analysisDef = "Dummy: dummy name ([wStep=%g] [wSize=%s] [func=%s] [mds=%s] [mcT=%s] [mcR=%s])-> CategoryClusterSeparationStat" % (windowStep, windowSize, compare, mds, mcTreshold, mcRuns)
        userBinSource = GalaxyInterface._getUserBinSource(reg, bins, genome)
        result = GalaxyInterface.runManual([tn1, tn2], analysisDef, reg, bins, genome, galaxyFn=galaxyFn)
        for key in result.getAllRegionKeys():
            chrom = str(key).split(":")[0];
            r = result[key];
            if 'Result' not in r.keys():
                print "skipping chr:", chrom, r;
                continue;
            r = r['Result'];
            scores = r[0];
            stddev = r[1];
            for i in range(len(scores)):
                if scores[i] != 0:
                    pos = i*windowStep;
                    if fileformat == "tabular":
                        outputFile.write("%s\t%s\t%s\t%s\n" % (str(chrom), pos, str(scores[i]), str(stddev[i])))
                    else:
                        text += "%s\t%s\t%s\t%s\n" % (str(chrom), pos, str(scores[i]), str(stddev[i]));
        if fileformat == "html":
            htmlfile.writeTextToFile(text);
            print htmlfile.getLink("Result file");
            print GalaxyInterface.getHtmlEndForRuns()
        
        outputFile.close();
    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.
        '''
        genome = choices.genome
        targetTrack = ExternalTrackManager.getPreProcessedTrackFromGalaxyTN(
            genome,
            choices.targetTrack,
            printErrors=False,
            printProgress=False)

        refGSuite = getGSuiteFromGalaxyTN(choices.refTrackCollection)

        regSpec, binSpec = UserBinMixin.getRegsAndBinsSpec(choices)

        analysisBins = GalaxyInterface._getUserBinSource(regSpec,
                                                         binSpec,
                                                         genome=genome)

        results = TrackReportCommon.getOverlapResultsForTrackVsCollection(
            genome, targetTrack, refGSuite, analysisBins=analysisBins)
        processedResults = TrackReportCommon.processRawResults(results)

        targetTrackTitle = prettyPrintTrackName(targetTrack)
        title = 'Screening of track ' + targetTrackTitle
        sortedProcessedResultsTupleList = sorted(
            processedResults.iteritems(),
            key=lambda x: x[1][STAT_LIST_INDEX[STAT_FACTOR_OBSERVED_VS_EXPECTED
                                               ]],
            reverse=True)
        refTrackNames = [x[0] for x in sortedProcessedResultsTupleList]
        refTrackNames = [
            x.replace('\'', '').replace('"', '') for x in refTrackNames
        ]
        plotData = [x[1] for x in sortedProcessedResultsTupleList]
        #         plotData = zip(*plotData) #invert
        plotData = normalizeMatrixData(plotData)

        printVals = tuple([str(targetTrackTitle)]) + tuple(
            [str(x[0]) for x in sortedProcessedResultsTupleList[0:3]])

        htmlCore = HtmlCore()
        htmlCore.begin()
        htmlCore.header(title)

        if choices.bmQid and choices.bmQid not in ['None']:
            htmlCore.append(
                str(
                    quick.gsuite.GSuiteHbIntegration.
                    getAnalysisQuestionInfoHtml(choices.bmQid)))

        htmlCore.divBegin('resultsDiv')
        htmlCore.paragraph('''
            The query track <b>%s</b> overlaps most strongly (is most highly enriched) with the tracks <b>%s</b>, <b>%s</b> and <b>%s</b> 
            from the selected collection. See below for a full (ranked) table of overlap and enrichment.
        ''' % printVals)

        htmlCore.paragraph('''
        The coverage of the query track is %s bps.
        ''' % strWithNatLangFormatting(
            TrackReportCommon.getQueryTrackCoverageFromRawOverlapResults(
                results)))

        htmlCore.tableHeader(TrackReportCommon.HEADER_ROW,
                             sortable=True,
                             tableId='resultsTable')
        for refTrackName, refTrackResults in sortedProcessedResultsTupleList:
            line = [refTrackName
                    ] + [strWithNatLangFormatting(x) for x in refTrackResults]
            htmlCore.tableLine(line)
        htmlCore.tableFooter()
        htmlCore.divEnd()
        '''

        addColumnPlotToHtmlCore(htmlCore, 
                                refTrackNames,  
                                TrackReportCommon.HEADER_ROW[1:], 
                                'stat', 'Results plot (data is normalized for better visual comparison) ', 
                                plotData, xAxisRotation = 315)
        '''
        addPlotToHtmlCore(
            htmlCore,
            refTrackNames,
            TrackReportCommon.HEADER_ROW[1:],
            'stat',
            'Results plot (data is normalized for better visual comparison) ',
            plotData,
            xAxisRotation=315)

        htmlCore.hideToggle(styleClass='debug')
        htmlCore.end()

        print htmlCore