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
        seqTrackName = choices.seqTrack.split(':')
        outBaseTrackName = choices.outTrackStr.split(':')
        
        regSpec = '__brs__' if choices.regions == 'Bounding regions of the sequence track' else '*'

        for pwm, chosen in choices.pwms.iteritems():
            if chosen:
                pfmFileName = os.sep.join([CreatePwmScoreTracksTool.JASPAR_DIR, pwm + '.pfm'])
                outTrackName = outBaseTrackName + [pwm]
                analysisDef ='[dataStat=MaxPwmScoreInWindowArrayStat] [pfmFileName=%s] [outTrackName=%s] [valDataType=float32]-> CreateFunctionTrackStat' \
                    % (pfmFileName.replace('/','^'), '^'.join(outTrackName))
                
                from quick.application.GalaxyInterface import GalaxyInterface
                GalaxyInterface.runManual([seqTrackName], analysisDef, regSpec, '*', genome, username=username, printResults=False, printHtmlWarningMsgs=False)
Пример #2
0
 def execute(choices, galaxyFn=None, username=''):
     '''Is called when execute-button is pushed by web-user.
     Should print output as HTML to standard out, which will be directed to a results page in Galaxy history.
     If 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]
     nmer = choices[1].lower()
     regSpec = choices[2]
     binSpec = '*'
     trackName = GenomeInfo.getPropertyTrackName(genome, 'nmer') + [str(len(nmer))+'-mers',nmer]
     assert galaxyFn is not None
     GalaxyInterface.extractTrackManyBins(genome, trackName, regSpec, binSpec, True, 'point bed', False, False, galaxyFn)
 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.
     '''
     
     inFn = ExternalTrackManager.extractFnFromGalaxyTN(choices.history.split(':'))
     treatTrackAs = ExpandBedSegmentsTool._TRACK_TYPE_CONVERSION_OPTIONS[choices.conversion]
         
     GalaxyInterface.expandBedSegments(inFn, galaxyFn, choices.genome, \
                                       int(choices.upstream), int(choices.downstream), \
                                       treatTrackAs, removeChrBorderCrossing=(choices.chrBorderHandling=='Removing'))
 def _runSingleStatistic(self, regionTrackName, analysisDef, predictionTrackName, answerTrackName=None):
     splittedPredictionTrackName = predictionTrackName.split(':')
     regionFileName = regionTrackName.split(':')[2]
     
     if answerTrackName == None:
         resultObject = GalaxyInterface.runManual([splittedPredictionTrackName], 
                     analysisDef, 'gtrack', regionFileName, self._genome, username=self._username, 
                     printResults=False, printHtmlWarningMsgs=False)
     else:
         splittedAnswerTrackName = answerTrackName.split(':')
     
         resultObject = GalaxyInterface.runManual([splittedPredictionTrackName, splittedAnswerTrackName], 
                     analysisDef, 'gtrack', regionFileName, self._genome, username=self._username, 
                     printResults=False, printHtmlWarningMsgs=False)
     
     return resultObject.getGlobalResult()
    def run(self):
        regSpec, binSpec = 'file', self._referenceTrackFn
        trackName1 = self._queryTrackName
        trackName2 = None
        from gold.description.TrackInfo import TrackInfo
        
        formatName = TrackInfo(self._genome, trackName1).trackFormatName
        formatConv = ''
        if 'segments' in formatName:
            formatConv = '[tf1:=SegmentToStartPointFormatConverter:]'

        analysisDef = formatConv + '-> CountPointStat'

        print '<div class="debug">'
        #trackName1, trackName2, analysisDef = GalaxyInterface._cleanUpAnalysisDef(trackName1, trackName2, analysisDef)
        #trackName1, trackName2 = GalaxyInterface._cleanUpTracks([trackName1, trackName2], genome, realPreProc=True)
        #
        #userBinSource, fullRunArgs = GalaxyInterface._prepareRun(trackName1, trackName2, analysisDef, regSpec, binSpec, self._genome)
        #res = AnalysisDefJob(analysisDef, trackName1, trackName2, userBinSource, **fullRunArgs).run()
        res = GalaxyInterface.runManual([trackName1, trackName2], analysisDef, regSpec, binSpec, self._genome, printResults=False, printHtmlWarningMsgs=False)
        #print res
        print '</div>'
        
        resDictKeys = res.getResDictKeys()
        assert len(resDictKeys)==1, resDictKeys
        resDictKey = resDictKeys[0]
        targetBins = [bin for bin in res.keys() if res[bin][resDictKey]>0]
        self._result = res
        self._intersectedReferenceBins = targetBins            
    def execute(cls, choices, galaxyFn=None, username=''):

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

        combineMethod = choices[2]
        category = choices[3] if choices[3] else ''
        numSamples = choices[4] if choices[4] else '1'

        analysisDef = 'dummy [combineMethod=%s] %s [numSamples=%s] -> ConvertToNonOverlappingCategorySegmentsPythonStat' % \
                        (combineMethod, '[category=%s]' % category if category != '' else '', numSamples) #'Python'

        for regSpec in GenomeInfo.getChrList(genome):
            res = GalaxyInterface.runManual([trackName], analysisDef, regSpec, '*', genome, username=username, \
                                            printResults=False, printHtmlWarningMsgs=False)

            from gold.origdata.TrackGenomeElementSource import TrackViewGenomeElementSource
            from gold.origdata.BedComposer import CategoryBedComposer
            for resDict in res.values():
                trackView = resDict['Result']
                tvGeSource = TrackViewGenomeElementSource(
                    genome, trackView, trackName)
                CategoryBedComposer(tvGeSource).composeToFile(outFn)
Пример #7
0
    def _getBasicTrackFormat(choices, tnChoiceIndex=1, genomeChoiceIndex=0):
        genome = GeneralGuiTool._getGenomeChoice(choices, genomeChoiceIndex)[0]
        tn = GeneralGuiTool._getTrackChoice(choices, tnChoiceIndex)[0]

        from quick.application.GalaxyInterface import GalaxyInterface
        from gold.description.TrackInfo import TrackInfo
        from quick.application.ExternalTrackManager import ExternalTrackManager
        from gold.track.TrackFormat import TrackFormat

        if ExternalTrackManager.isGalaxyTrack(tn):
            geSource = ExternalTrackManager.getGESourceFromGalaxyOrVirtualTN(
                tn, genome)
            try:
                tf = GeneralGuiTool._convertToBasicTrackFormat(
                    TrackFormat.createInstanceFromGeSource(
                        geSource).getFormatName())
            except Warning:
                return genome, tn, ''
        else:
            if GalaxyInterface.isNmerTrackName(genome, tn):
                tfName = 'Points'
            else:
                tfName = TrackInfo(genome, tn).trackFormatName
            tf = GeneralGuiTool._convertToBasicTrackFormat(tfName)
        return genome, tn, tf
 def execute(cls, choices, galaxyFn=None, username=''):
     start = time.time()
     genome = choices[0]
     trackName = choices[1].split(':')
     outFn = galaxyFn
     if choices[5] == 'Write to Standardised file':
         outFn = createOrigPath(genome, choices[-1].split(':'), 'collapsed_result.bedgraph')
         ensurePathExists(outFn[:outFn.rfind('/')+1])
             
     combineMethod = choices[2]
     category = choices[3] if choices[3] else ''
     numSamples = choices[4] if choices[4] else '1'
     
     analysisDef = 'dummy [combineMethod=%s] %s [numSamples=%s] -> ConvertToNonOverlappingCategorySegmentsPythonStat' % \
                     (combineMethod, '[category=%s]' % category if category != '' else '', numSamples) #'Python'
                                               
     for regSpec in  GenomeInfo.getChrList(genome):
         res = GalaxyInterface.runManual([trackName], analysisDef, regSpec, '*', genome, username=username, \
                                         printResults=False, printHtmlWarningMsgs=False)
         
         from gold.origdata.TrackGenomeElementSource import TrackViewGenomeElementSource
         from gold.origdata.BedComposer import CategoryBedComposer
         for resDict in res.values():
             tvGeSource = TrackViewGenomeElementSource(genome, resDict['Result'], trackName)
             CategoryBedComposer(tvGeSource).composeToFile(outFn)
Пример #9
0
def countSubTracks(genome, parentTrack, recursioncount):
    if recursioncount < 10:
        thissubs = GalaxyInterface.getSubTrackNames(genome, parentTrack,
                                                    False)[0]
        tname = genome + ":" + ":".join(parentTrack)
        #ti = TrackInfo.
        if thissubs:  # has subtrakcs, ie is a folder
            thisndirs = 0
            thisntracks = 0
            for a in thissubs:
                nextparenttrack = parentTrack
                nextparenttrack.append(a[0])
                ndirs, ntracks = countSubTracks(genome, nextparenttrack,
                                                recursioncount + 1)
                thisndirs = thisndirs + ndirs
                thisntracks = thisntracks + ntracks
                nextparenttrack = nextparenttrack.remove(a[0])
            print('plan to update trackinfo', tname,
                  ' set number of folders to ', thisndirs,
                  ' and number of tracks to ', thisntracks)
            return (thisndirs + 1, thisntracks)
        else:  # is a track.
            return (0, 1)
    else:
        print "to many recursions"
    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.
        '''
        regSpec, binSpec = UserBinSelector.getRegsAndBinsSpec(choices)
        genome = choices.Genome
        #trackNames = [choices[choiceIndex].split(':') for choiceIndex in [2,4,6]]
        #trackNames = [x.split(':') for x in [choices.Track1, choices.Track2, choices.Track3]]
        trackNames = cls.getAllChosenTracks(choices)
        print trackNames
        #for tnIndex, choiceIndex in zip(range(3),[2,4,6]):
        #    tn = choices[choiceIndex].split(':')
        #    trackNames[tnIndex] = tn
            #trackNames[tnIndex] = ExternalTrackManager.getPreProcessedTrackFromGalaxyTN(genome, tn) \
            #    if ExternalTrackManager.isGalaxyTrack(tn) \
            #    else tn

        #analysisDef = 'dummy [trackNameIntensity=%s]-> ThreeWayBpOverlapStat' % '|'.join(trackNames[2])
        #Do not preserve any pair-wise relations', 'Preserve pair-wise relation between Track 1 and Track 3', 'Preserve pair-wise relation between Track 2 and Track 3']
        #['Base pair coverage of all track combinations', 'Inclusion structure between tracks', 'Observed versus expected overlap with various relations preserved', 'Hypothesis testing on multi-track relations']
        if choices.Analysis == 'Base pair coverage of all track combinations':
            analysisDef = 'dummy -> ThreeWayBpOverlapStat'
        elif choices.Analysis == 'Inclusion structure between tracks':
            analysisDef = 'dummy -> ThreeWayTrackInclusionBpOverlapStat'
        elif choices.Analysis == 'Observed versus expected overlap with various relations preserved':
            pass
        elif choices.Analysis == 'Factors of observed versus expected overlap with various relations preserved':
            analysisDef = 'Dummy [rawStatistic=ThreeWayExpectedWithEachPreserveCombinationBpOverlapStat]  [referenceResDictKey=preserveNone] -> GenericFactorsAgainstReferenceResDictKeyStat'
        elif choices.Analysis == 'Hypothesis testing on multi-track relations':
            randOption = cls._getRandomizationAnalysisOption(choices)
            numResamplingsOption = '[numResamplings=%s]' % choices.NumResamplings
            #assert len(trackNames) == 3, trackNames #currently, due to ThreeTrackBpsCoveredByAllTracksStat
            #analysisDef = 'dummy [tail=different] [rawStatistic=ThreeTrackBpsCoveredByAllTracksStat] %s %s -> RandomizationManagerStat' % (randOption, numResamplingsOption)
            resDictKey = '1'*(len(trackNames))
            analysisDef = 'dummy [tail=different] [rawStatistic=SingleValExtractorStat] [childClass=ThreeWayBpOverlapStat] [resultKey=%s] %s %s -> RandomizationManagerStat' % (resDictKey, randOption, numResamplingsOption)
            print analysisDef
        else:
            raise Exception(choices.Analysis)
        analysisDef = 'dummy [extraTracks=%s] ' % '&'.join(['|'.join(tn) for tn in trackNames[2:] ]) + analysisDef
        #GalaxyInterface.run(trackNames[0], trackNames[1], analysisDef, regSpec, binSpec, genome, galaxyFn, trackNames[2], printRunDescription=False)
        GalaxyInterface.run(trackNames[0], trackNames[1], analysisDef, regSpec, binSpec, genome, galaxyFn, printRunDescription=False)
Пример #11
0
def directGetEnrichment(diseaseTrack,
                        refTrackLeaf,
                        refTrackBase,
                        kernelType,
                        kernelParam,
                        useCache=True,
                        printProgress=False):
    RETRIEVE_FROM_CACHE = useCache
    STORE_TO_CACHE = useCache
    if kernelType == 'gaussian':
        kernelParamAssignment = ',kernelStdev=%s' % kernelParam
    elif kernelType == 'divideByOffset':
        kernelParamAssignment = ',minimumOffsetValue=%s' % kernelParam
    elif kernelType == 'binSizeNormalized':
        kernelParamAssignment = ''
    elif kernelType == 'catCoverageNormalized':
        kernelParamAssignment = ''
    elif kernelType == 'uniform':
        kernelParamAssignment = ''
    else:
        raise  #RuntimeError('unre'
    batchText = '''
@bins=%s
@TNs=%s:%s
@TNunion=%s
hg19|track|@bins|@TNs|@TNunion|DiffRelCoverageStat(globalSource=chrs,tf1=TrivialFormatConverter,tf2=TrivialFormatConverter,withOverlaps=yes,kernelType=%s%s)
''' % (diseaseTrack, refTrackBase, refTrackLeaf, refTrackBase, kernelType,
       kernelParamAssignment)
    #print 'BATCHLINE: <br>', batchText
    import hashlib
    hashName = hashlib.sha1(batchText).hexdigest()
    sf = PickleStaticFile(['files', 'Caches', 'Tool7', hashName])
    #shelf = safeshelve.open(sf.getDiskPath(True))
    #if batchText in shelf:
    if RETRIEVE_FROM_CACHE and sf.fileExists():
        print ',',
        #print 'Retrieving batch result (%s): %s' % (sf.getDiskPath(), batchText)
        #return shelf[batchText]
        return sf.loadPickledObject()
    else:
        print '.',
        #print 'Running batch: ', batchText
        #shelf.close()
        batchLines = batchText.split('\n')
        from quick.application.GalaxyInterface import GalaxyInterface
        res = GalaxyInterface.runBatchLines(batchLines,
                                            username='******',
                                            printResults=False,
                                            printProgress=printProgress)[0]
        #global TEMP_NUM_BATCH_RUNS_SO_FAR
        #print 'Running batchLines (%s): %s<br>Getting result: %s<br>' % (TEMP_NUM_BATCH_RUNS_SO_FAR, batchLines, res)
        #TEMP_NUM_BATCH_RUNS_SO_FAR += 1
        #shelf = safeshelve.open(sf.getDiskPath(True))
        #shelf[batchText] = res
        #shelf.close()
        res.batchText = batchText
        if STORE_TO_CACHE:
            sf.storePickledObject(res)
        return res
Пример #12
0
    def handleSameTrack(cls, trackName, regSpec, binSpec, genome, galaxyFn):

        analysisSpec = AnalysisSpec(RawOverlapToSelfStat)
        analysisBins = GalaxyInterface._getUserBinSource(
            regSpec, binSpec, genome)

        return doAnalysis(analysisSpec, analysisBins,
                          [Track(trackName)]).getGlobalResult()
Пример #13
0
 def execute(choices, galaxyFn=None, username=''):
     '''
     Is called when execute-button is pushed by web-user. Should print
     output as HTML to standard out, which will be directed to a results page
     in Galaxy history. If getOutputFormat is anything else than HTML, the
     output should be written to the file with path galaxyFn. If needed,
     StaticFile can be used to get a path where additional files can be put
     (e.g. generated image files). choices is a list of selections made by
     web-user in each options box.
     '''
     
         
     if GalaxyInterface._userHasFullAccess(username) or len([i for i in choices[0].split('\n') if len(i.strip())>0 and i.strip()[0]=='$'])==0:
         runStr = choices[0]
         GalaxyInterface.runBatchLines(batchLines=runStr.split('\n'), galaxyFn=galaxyFn, genome=None, username=username)
     else:
         print 'Your user does not have access to run this command line.'
Пример #14
0
 def runAllAnalysises(self, genome, tn, regSpec, binSpec):
     for analysisKey, analysisVals in self.analysisDict.items():
             trackName, analysisDef, resKey = analysisVals
             trackNames = [tn] if trackName is None else [tn, trackName]
             try:
                 self.resultDict[analysisKey] = (resKey, GalaxyInterface.runManual(trackNames, analysisDef, regSpec, binSpec, genome, galaxyFn=None, printResults=False, printProgress=False))
             except:
                 pass
Пример #15
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.
        '''

        galaxyTn = choices.history.split(':')
        inFn = ExternalTrackManager.extractFnFromGalaxyTN(galaxyTn)
        suffix = ExternalTrackManager.extractFileSuffixFromGalaxyTN(galaxyTn)

        treatTrackAs = cls._TRACK_TYPE_CONVERSION_OPTIONS[choices.conversion]

        GalaxyInterface.expandBedSegments(inFn, galaxyFn, choices.genome, \
                                          parseShortenedSizeSpec(choices.upstream), parseShortenedSizeSpec(choices.downstream), \
                                          treatTrackAs, removeChrBorderCrossing=(choices.chrBorderHandling=='Removing'), suffix=suffix)
Пример #16
0
 def retrieveFeatureTrack(self, genome, galaxyFn, regionTrackName, featureTrack):
     
     regionTrackName = regionTrackName.split(':')
     regionFileName = ExternalTrackManager.extractFnFromGalaxyTN(regionTrackName)
     
     bins = GalaxyInterface._getUserBinSource('gtrack', regionFileName, genome, featureTrack.split(':'))
     
     return self._extractor.extract(featureTrack.split(':'), bins, galaxyFn, 'gtrack')
Пример #17
0
 def _isValidTrack(prevChoices, tnChoiceIndex=1):
     from quick.application.GalaxyInterface import GalaxyInterface
     from quick.application.ProcTrackOptions import ProcTrackOptions
     
     genome = prevChoices[0]
     tn = prevChoices[tnChoiceIndex].split(':')
     
     return ProcTrackOptions.isValidTrack(genome, tn, True) or \
         GalaxyInterface.isNmerTrackName(genome, tn)
Пример #18
0
 def analyseTrackData(genome, baseTn, username, galaxyFn):
     from quick.application.GalaxyInterface import GalaxyInterface
     print GalaxyInterface.getSubTrackNames(genome,
                                            baseTn,
                                            deep=False,
                                            username=username)
     allTns = [
         baseTn + [leafTn[0]]
         for leafTn in GalaxyInterface.getSubTrackNames(
             genome, baseTn, deep=False, username=username)[0]
         if leafTn != None
     ]
     mainTns = allTns[:2]
     extraTracks = '&'.join(['^'.join(tn) for tn in allTns[2:]])
     analysisDef = '[extraTracks=%s] -> ThreeWayCoverageDepthStat' % extraTracks
     print allTns, mainTns
     GalaxyInterface.runManual(mainTns, analysisDef, 'chr1:1-150m', '*', genome, galaxyFn=galaxyFn, username=username, \
               printResults=True, printProgress=True, printHtmlWarningMsgs=True, applyBoundaryFilter=False, printRunDescription=True)
Пример #19
0
def updateTrackFolderStatistics():
    print('inne i updateTrackFolderStatistics')
    #trackInfoShelve = safeshelve.open(SHELVE_FN, 'w')   
    for genomeinfo in GalaxyInterface.getAllGenomes():
        genome = genomeinfo[1]
        if genome=="hg18":
            genome="hg18"
        print "dirname=",genome
        thisntracks=0
        thisndirs=0
        for startparenttrack in GalaxyInterface.getMainTrackNames(genome):
            #print "startparenttrack=",startparenttrack
            firstparenttrack=[startparenttrack[0]]
            ndirs,ntracks = countSubTracks(genome,firstparenttrack , 0 )
            thisndirs=thisndirs+ndirs
            thisntracks=thisntracks+ntracks
        # put counts into genomeinfo.shelve?
        print('plan to update genomeinfo', genome, ' set number of folders to ', thisndirs, ' and number of tracks to ', thisntracks)
Пример #20
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.
        '''
        genome = choices[0]
        nmer = choices[1].lower()
        regSpec = choices[2]
        analysisRegions = parseRegSpec(regSpec, genome)
        
        binSize = cls._calcBinSize(nmer, analysisRegions)
        binSpec = '*' if binSize is None else str( binSize ) 
        numBins = len( AutoBinner(analysisRegions, binSize) )
        
        from quick.application.GalaxyInterface import GalaxyInterface
        from quick.util.GenomeInfo import GenomeInfo
        trackName1 = GenomeInfo.getPropertyTrackName(genome, 'nmer') + [str(len(nmer))+'-mers',nmer]
        trackName2 = ['']
        analysisDef = 'Counts: The number of track1-points -> CountPointStat'
        #regSpec = '*'
        #print 'Using binSize: ',binSpec
        #print 'TN1: ',trackName1
        from gold.result.HtmlCore import HtmlCore
        print str(HtmlCore().styleInfoBegin(styleClass='debug'))
        GalaxyInterface.run(trackName1, trackName2, analysisDef, regSpec, binSpec, genome, galaxyFn)
        print str(HtmlCore().styleInfoEnd())

        plotFileNamer = GalaxyRunSpecificFile(['0','CountPointStat_Result_gwplot.pdf'], galaxyFn)
        textualDataFileNamer = GalaxyRunSpecificFile(['0','CountPointStat_Result.bedgraph'], galaxyFn)
        
        core = HtmlCore()
        core.paragraph('Inspect nmer frequency variation as a %s or as underlying %s.</p>' % ( plotFileNamer.getLink('plot'), textualDataFileNamer.getLink('textual data') ))
        core.divider()
        core.paragraph('The occurrence frequency of your specified nmer ("%s") has been computed along the genome, within your specified analysis region ("%s").' % (nmer, regSpec))
        core.paragraph('The analysis region was divided into %i bins, based on calculations trying to find appropriate bin size (get enough data per bin and restrict maximum number of bins).' % numBins)
        
        trackName1modified = trackName1[0:-2] + trackName1[-1:]
        preSelectedAnalysisUrl = createHyperBrowserURL(genome, trackName1modified,[''], analysis='Counts',method='auto',region=regSpec, binsize=binSpec)
        core.divider()
        core.paragraph('If you do not find the inferred bin size to be appropriate, you can set this manually in a ' + str(HtmlCore().link('new analysis', preSelectedAnalysisUrl)) + '.')
        print str(core)
 def validateAndReturnErrors(choices):
     '''
     Should validate the selected input parameters. If the parameters are not valid,
     an error text explaining the problem should be returned. The GUI then shows this text
     to the user (if not empty) and greys out the execute button (also if the text isempty).
     If all parameters are valid, the method should return None, which enables the execute button.
     '''
     winSize = choices[1]
     expression = choices[2]
     from quick.application.GalaxyInterface import GalaxyInterface
     return GalaxyInterface.validateDnaBasedExpressionAndReturnError(winSize, expression)
Пример #22
0
 def getOptionsBox3(prevChoices): 
     '''Returns a list of options to be displayed in the second options box, which will be displayed after a selection is made in the first box.
     prevChoices is a list of selections made by the web-user in the previous input boxes (that is, list containing only one element for this case)        
     '''
     from quick.application.GalaxyInterface import GalaxyInterface
     try:
         subTrackList = [v[0] for v in GalaxyInterface.getSubTrackNames(prevChoices[0], prevChoices[1].split(':'), deep=False)[0]]
         #return (repr(subTrackList), 4, True)
         return ('\n'.join(subTrackList), len(subTrackList), True)
     except:
         pass
Пример #23
0
 def trackPrepare(self, inputTracks, genome) : #just filter out the -- All subtypes -- tag if it exists
     output = []
     for track in inputTracks :
         if isinstance(track, basestring) :
             track = track.split(":")
         if track[-1] == "-- All subtypes --" :
             output.append(track[:-1])
         else :
             output.append(track)
     output = GalaxyInterface._cleanUpTracks(output, genome, realPreProc=True)        
     return output
Пример #24
0
def updateTrackFolderStatistics():
    print('inne i updateTrackFolderStatistics')
    #trackInfoShelve = safeshelve.open(SHELVE_FN, 'w')
    for genomeinfo in GalaxyInterface.getAllGenomes():
        genome = genomeinfo[1]
        if genome == "hg18":
            genome = "hg18"
        print "dirname=", genome
        thisntracks = 0
        thisndirs = 0
        for startparenttrack in GalaxyInterface.getMainTrackNames(genome):
            #print "startparenttrack=",startparenttrack
            firstparenttrack = [startparenttrack[0]]
            ndirs, ntracks = countSubTracks(genome, firstparenttrack, 0)
            thisndirs = thisndirs + ndirs
            thisntracks = thisntracks + ntracks
        # put counts into genomeinfo.shelve?
        print('plan to update genomeinfo', genome,
              ' set number of folders to ', thisndirs,
              ' and number of tracks to ', thisntracks)
    def execute(self, printHtmlBeginEnd=True, printTrackNamesTable=True):
        print GalaxyInterface.getHtmlBeginForRuns(self._galaxyFn)
        core = HtmlCore()
        if printTrackNamesTable:
            core.divBegin('trackNames')
            dataDict = OrderedDict([(x, []) for x in self._trackNames])
            tblExpandable = True
            if len(self._trackNames) < 11:
                tblExpandable = False
            core.tableFromDictionary(dataDict, ['Tracks under analysis'],
                                     tableId="resTable",
                                     expandable=tblExpandable)
            #             core.tableHeader(['Tracks under analysis:'])
            #             for trackName in self._trackNames:
            #                 core.tableLine([trackName])
            #             core.tableFooter()
            core.divEnd()
        print core
        try:
            results = GalaxyInterface.run(self._tracks[0],
                                          self._tracks[1],
                                          self.getAnalysisDefinitionString(),
                                          self._regSpec,
                                          self._binSpec,
                                          self._genome,
                                          self._galaxyFn,
                                          printRunDescription=False,
                                          printHtmlBeginEnd=printHtmlBeginEnd,
                                          fromMainTool=False)

            if self.hasVisualization():
                print self.visualizeResults(results)


#        except:
#            pass
        finally:
            core2 = HtmlCore()
            core2.hideToggle(styleClass='infomessagesmall')
            print core2
            print GalaxyInterface.getHtmlEndForRuns()
Пример #26
0
 def getOptionsBox3(prevChoices):
     '''Returns a list of options to be displayed in the second options box, which will be displayed after a selection is made in the first box.
     prevChoices is a list of selections made by the web-user in the previous input boxes (that is, list containing only one element for this case)        
     '''
     from quick.application.GalaxyInterface import GalaxyInterface
     from collections import OrderedDict
     try:
         subTrackList = [
             v[0] for v in GalaxyInterface.getSubTrackNames(
                 prevChoices[0], prevChoices[1].split(':'), deep=False)[0]
         ]
         if len(subTrackList) > 0:
             subSubTrackList = GalaxyInterface.getSubTrackNames(
                 prevChoices[0],
                 prevChoices[1].split(':') + [subTrackList[0]],
                 deep=False)[0]
             if len(subSubTrackList) == 0:
                 return OrderedDict([(v, False) for v in subTrackList])
         #return ('\n'.join(subTrackList), len(subTrackList), True)
     except:
         pass
    def validateUserBins(cls, choices):
        if cls._isBasicMode(choices):
            return None

        regSpec, binSpec = cls.getRegsAndBinsSpec(choices)
        return cls._getUserBinSourceRegistry(choices).validateRegAndBinSpec(
            regSpec, binSpec)

        errorString = GalaxyInterface._validateRegAndBinSpec(
            regSpec, binSpec, genome, [trackName1, trackName2])
        if errorString:
            return errorString
Пример #28
0
 def handleRegionClustering(self, genome, tracks, clusterMethod, extra_option):
     region_cluster_track = self.getHistoryTrackDef('track1')
     print region_cluster_track
     region_ref_track = self.params.get('reftrack1')
     if region_cluster_track[0] == 'galaxy' :
         file_type = region_cluster_track[1]
         track_path = region_cluster_track[2]
         userBinSource = GalaxyInterface._getUserBinSource('bed', track_path, genome)
         validFeature = SplittedRegionsAsFeaturesCatalog.getValidAnalyses(genome,region_ref_track,[])
         analysisDef = validFeature[0]
         result = AnalysisDefJob(analysisDef, region_ref_track, [], userBinSource).run()
         print [result[localKey][validFeature[1]] for localKey in sorted(result.keys())]
Пример #29
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 gold.application.LogSetup import setupDebugModeAndLogging
        setupDebugModeAndLogging()

        analysisDef = choices[2].replace(os.linesep, '')
        #from gold.application.StatRunner import AnalysisDefJob

        print 'Preparing arguments'
        genome = choices[3]

        prefixTN1 = cls.STD_PREFIX_TN if choices[4] == 'yes' else []
        tn1 = prefixTN1 + choices[5].split(':')
        prefixTN2 = cls.STD_PREFIX_TN if choices[6] == 'yes' else []
        tn2 = prefixTN2 + choices[7].split(':')
        if tn2[-1] == cls.NO_TRACK_SHORTNAME:
            tn2 = None
        #from gold.track.GenomeRegion import GenomeRegion
        #region = GenomeRegion(genome, 'chr1',1000,2000)
        #region2 = GenomeRegion(genome, 'chr1',5000,6000)

        #kwArgs = {}
        regVal = choices[8]
        binSpecVal = choices[9]
        #ubSource = UserBinSource(regVal, binSpecVal, genome=genome)
        from quick.application.GalaxyInterface import GalaxyInterface

        print tn1, tn2
        GalaxyInterface.runManual([tn1, tn2],
                                  analysisDef,
                                  regVal,
                                  binSpecVal,
                                  genome,
                                  galaxyFn,
                                  username=username)
    def build_feature_vector(genome, ctrack, feature, regSpec, binSpec):
        '''
        this function create a feature vector for ctrack
        feature specifies how the vector is constructed
        '''
        #print 'TEMP1:', ctrack, '<br>', LocalResultsAsFeaturesCatalog.getValidAnalyses(genome, ctrack, []),'<br>'
        #validFeature = LocalResultsAsFeaturesCatalog.getValidAnalyses(genome, ctrack, [])[feature]
        validFeature = LocalResultsAsFeaturesCatalog.getAllFeatures()[feature]
        analysisDef = validFeature[0]
        #regSpec = self.params.get("region")
        #binSpec = self.params.get("binsize")
        #userBinSource = GalaxyInterface._getUserBinSource(regSpec,binSpec,genome)

        #result = GalaxyInterface.runManual([ctrack], analysisDef, regSpec, binSpec, genome, printResults=False, printProgress=False)
        #result = AnalysisDefJob(analysisDef, ctrack, [], userBinSource).run()
        if validFeature[1] == 'Microbins':
            microBinConfig = 'extraDummy [microBin=%i] ' % int(
                binSpec.replace('k', '000').replace('m', '000000'))
            analysisDef = microBinConfig + analysisDef
            result = GalaxyInterface.runManual([ctrack],
                                               analysisDef,
                                               regSpec,
                                               '*',
                                               genome,
                                               printResults=False,
                                               printProgress=False)
            res = result.getGlobalResult()['Result']
            return res
        else:
            result = GalaxyInterface.runManual([ctrack],
                                               analysisDef,
                                               regSpec,
                                               binSpec,
                                               genome,
                                               printResults=False,
                                               printProgress=False)
            return [
                result[localKey][validFeature[1]]
                for localKey in sorted(result.keys())
            ]
    def execute(cls, choices, galaxyFn, 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.
        '''
        from quick.application.GalaxyInterface import GalaxyInterface

        genome = choices[0]
        winSize = choices[1]
        expression = choices[2]
        indexScheme = choices[3]
        assert indexScheme in ['Index 0 is left-most position of sliding window', 'Index 0 is midpoint of sliding window']
        midPointIsZero = (indexScheme == 'Index 0 is midpoint of sliding window')
        #if midPointIsZero:
            #print 'MIDPOINT!!'
        #else:
            #print choices[3]

        #if choices[4] == 'HyperBrowser track':
        #    trackName = choices[5]
        #else:
        trackName = 'galaxy:hbfunction:%s:Create track from DNA sequence' % galaxyFn

        # with open(galaxyFn, 'w+') as outputFile:
        print GalaxyInterface.getHbFunctionOutputBegin(galaxyFn, withDebug=True)

        GalaxyInterface.createDnaBasedCustomTrack(genome, trackName, winSize, expression, midPointIsZero)

        infoMsg = 'A custom track has been created by applying the expression "%s" on DNA sequence of a sliding window of size %s along the genome (%s).' % (expression, winSize,indexScheme)
        print GalaxyInterface.getHbFunctionOutputEnd(infoMsg, withDebug=True)
    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[0]
        trackName = choices[1].split(':')
        
        galaxyOutTrackName = 'galaxy:hbfunction:%s:Create function track of distance to nearest segment' % galaxyFn
        outTrackName = ExternalTrackManager.getStdTrackNameFromGalaxyTN(galaxyOutTrackName.split(':'))
        
        if choices[2] == 'No transformation':
            valTransformation = 'None'
        elif choices[2] =='Logarithmic (log10(x))':
            valTransformation = 'log10'
        elif choices[2] == 'Fifth square root (x**0.2)':
            valTransformation = 'power0.2'
        
        analysisDef ='[dataStat=MakeDistanceToNearestSegmentStat] [valTransformation=%s][outTrackName=' % valTransformation \
                     + '^'.join(outTrackName) + '] -> CreateFunctionTrackStat'
        #userBinSource, fullRunArgs = GalaxyInterface._prepareRun(trackName, None, analysisDef, '*', '*', genome)
        #
        #for el in userBinSource:
        #    print el.chr, el.start, el.end
            
        from quick.application.GalaxyInterface import GalaxyInterface

        print GalaxyInterface.getHbFunctionOutputBegin(galaxyFn, withDebug=False)
        
        GalaxyInterface.runManual([trackName], analysisDef, '*', '*', genome, username=username, printResults=False, printHtmlWarningMsgs=False)
        #job = AnalysisDefJob(analysisDef, trackName, None, userBinSource).run()
        
        print GalaxyInterface.getHbFunctionOutputEnd('A custom track has been created by finding the bp-distance to the nearest segment', withDebug=False)
    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.
        '''
        #print 'Executing...'

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

        genome = choices[1]
        flankSize = int(choices[3])
        if choices[4] == cls.REGIONS_FROM_HISTORY:
            from quick.extra.tfbs.GeneTargetsOfTF import GeneTargetsOfRegions
            regionsTn = choices[5].split(':')
            GeneTargetsOfRegions.findGeneTargets(genome, regionsTn, flankSize,
                                                 flankSize, galaxyFn)
        else:
            tfSource = choices[4]
            tfChoice = choices[5]
            from quick.extra.tfbs.GeneTargetsOfTF import GeneTargetsOfTF
            GeneTargetsOfTF.findGeneTargets(genome, tfSource, tfChoice,
                                            flankSize, flankSize, galaxyFn)

        print GalaxyInterface.getHtmlEndForRuns()
 def execute(choices, galaxyFn, 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.
     '''
     from quick.application.GalaxyInterface import GalaxyInterface
     genome = choices[0]
     winSize = choices[1]
     expression = choices[2]
     indexScheme = choices[3]
     assert indexScheme in ['Index 0 is left-most position of sliding window', 'Index 0 is midpoint of sliding window']
     midPointIsZero = (indexScheme == 'Index 0 is midpoint of sliding window')
     #if midPointIsZero:
         #print 'MIDPOINT!!'
     #else:
         #print choices[3]
     
     #if choices[4] == 'HyperBrowser track':
     #    trackName = choices[5]
     #else:
     trackName = 'galaxy:hbfunction:%s:Create track from DNA sequence' % galaxyFn
     
     
     print GalaxyInterface.getHbFunctionOutputBegin(galaxyFn, withDebug=True)
     
     GalaxyInterface.createDnaBasedCustomTrack(genome, trackName, winSize, expression, midPointIsZero)
     
     infoMsg = 'A custom track has been created by applying the expression "%s" on DNA sequence of a sliding window of size %s along the genome (%s).' % (expression, winSize,indexScheme) 
     print GalaxyInterface.getHbFunctionOutputEnd(infoMsg, withDebug=True)
    def execute(cls, choices, galaxyFn=None, username=''):
        '''
        Is called when execute-button is pushed by web-user. Should print
        output as HTML to standard out, which will be directed to a results page
        in Galaxy history. If getOutputFormat is anything else than HTML, the
        output should be written to the file with path galaxyFn. If needed,
        StaticFile can be used to get a path where additional files can be put
        (e.g. generated image files). choices is a list of selections made by
        web-user in each options box.
        '''
        cls._setDebugModeIfSelected(choices)

        batchStr = choices[0]
        batchLines = [x.strip() for x in batchStr.strip().split(os.linesep)]
        #batchLines = [x.strip() for x in choices[0].strip().split(os.linesep)]
        legalBatchLines = cls._removeIllegalLines(batchLines, username)

        if len(legalBatchLines) > 0:
            GalaxyInterface.runBatchLines(batchLines=legalBatchLines, galaxyFn=galaxyFn, \
                                          genome=None, username=username)
        else:
            return 'Your user does not have access to run these command lines.'
    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 config.Config import DebugConfig
        #DebugConfig.PASS_ON_VALIDSTAT_EXCEPTIONS = True
        #DebugConfig.PASS_ON_COMPUTE_EXCEPTIONS = True
        ##DebugConfig.VERBOSE = True
        #
        from quick.webtools.restricted.DebugAnalysisTool import DebugAnalysisTool        
        DebugAnalysisTool.setupDebugModeAndLogging(verbose=False) #set from selection box..
        
        analysisDef = choices[2].replace(os.linesep,'')
        #from gold.application.StatRunner import AnalysisDefJob

        print 'Preparing arguments'
        genome = choices[3]
        
        prefixTN1 = cls.STD_PREFIX_TN if choices[4] == 'yes' else []
        tn1 = prefixTN1 + choices[5].split(':') 
        prefixTN2 = cls.STD_PREFIX_TN if choices[6] == 'yes' else []
        tn2 = prefixTN2 + choices[7].split(':')
        if tn2[-1] == cls.NO_TRACK_SHORTNAME:
            tn2 = None
        #from gold.track.GenomeRegion import GenomeRegion
        #region = GenomeRegion(genome, 'chr1',1000,2000)
        #region2 = GenomeRegion(genome, 'chr1',5000,6000)
        
        #kwArgs = {}
        regVal = choices[8]
        binSpecVal = choices[9]
        #ubSource = UserBinSource(regVal, binSpecVal, genome=genome)
        from quick.application.GalaxyInterface import GalaxyInterface
        
        print tn1, tn2
        GalaxyInterface.runManual([tn1, tn2], analysisDef, regVal, binSpecVal, genome, galaxyFn, username=username)
Пример #37
0
    def execute(cls, choices, galaxyFn=None, username=''):
        seqs = [s.strip() for s in choices.seqs.splitlines()]
        trackNameList = []
        for nmer in seqs:
            GalaxyInterface.createNmerTrack(choices.genome, nmer)
            trackNameList.append(
                ['Sequence', 'K-mers',
                 str(len(nmer)) + '-mers', nmer])
        #example trackName = ['Sequence', 'K-mers', '7-mers', 'agagaga']
        outGSuite = GSuite()
        for trackName in trackNameList:
            trackType = TrackInfo(choices.genome,
                                  trackName).trackFormatName.lower()
            hbUri = HbGSuiteTrack.generateURI(trackName=trackName)
            outGSuite.addTrack(
                GSuiteTrack(hbUri,
                            title=' '.join(['Nmer track'] + trackName[-1:]),
                            trackType=trackType,
                            genome=choices.genome))

        GSuiteComposer.composeToFile(outGSuite,
                                     cls.extraGalaxyFn['Kmers GSuite'])
def writeGSuiteHiddenTrackStorageHtml(galaxyFn):
    from proto.config.Config import URL_PREFIX
    from proto.hyperbrowser.HtmlCore import HtmlCore
    from quick.application.GalaxyInterface import GalaxyInterface

    core = HtmlCore()
    core.append(GalaxyInterface.getHtmlBeginForRuns(galaxyFn))
    core.paragraph(
        'This history element contains GSuite track data, and is hidden by default.'
    )
    core.paragraph(
        'If you want to access the contents of this GSuite, please use the tool: '
        '%s, selecting '
        'a primary GSuite history element that refers to the files contained '
        'in this storage.' % str(HtmlCore().link(
            'Export primary tracks from a GSuite to your history',
            createGalaxyToolURL('hb_g_suite_export_to_history_tool'))))
    core.end()
    core.append(GalaxyInterface.getHtmlEndForRuns())

    with open(galaxyFn, 'w') as outputFile:
        outputFile.write(str(core))
Пример #39
0
 def _constructBins(regSpec, binSpec, genome, trackNames):
     # Construct and check bins
     try:
         from quick.application.GalaxyInterface import GalaxyInterface
         userBinSource = GalaxyInterface._getUserBinSource(regSpec, binSpec, genome, trackNames)
         return [None, userBinSource]
     except Exception, e:
         results = Results([], [], '')
         results.addError(InvalidRunSpecException('Error in specification of analysis region or binsize: ' + str(e)))
         logMessage('Error in specification of analysis region (' + regSpec +') or binsize: (' + binSpec + ')')
         if DebugConfig.PASS_ON_BATCH_EXCEPTIONS:
             raise
         return [results, None]
Пример #40
0
 def _runCategoryPointCount(cls, genome, regSpec, binSpec, trackName1, applyBoundaryFilter=True):
     analysisDef = 'Category point count: Number of elements each category of track1 (with overlaps)'+\
               '[tf1:=SegmentToStartPointFormatConverter:]'+\
               '-> FreqByCatStat'    
     print '<div class="debug">'
     res = GalaxyInterface.runManual([trackName1], analysisDef, regSpec, binSpec, genome, \
                                     printResults=False, printHtmlWarningMsgs=False, applyBoundaryFilter=applyBoundaryFilter)
     #userBinSource, fullRunArgs = GalaxyInterface._prepareRun(trackName1, None, analysisDef, regSpec, binSpec, genome)
     #if applyBoundaryFilter:
     #    userBinSource = RegionBoundaryFilter(userBinSource, GlobalBinSource(genome))
     #res = AnalysisDefJob(analysisDef, trackName1, None, userBinSource, **fullRunArgs).run()        
     print res        
     print '</div>'
     return res
Пример #41
0
def getSubTrackLeafTerms(genome,
                         parentTrack,
                         excludeSelfIfValid=True,
                         username=''):
    from quick.application.GalaxyInterface import GalaxyInterface
    subTrackTriples = GalaxyInterface.getSubTrackNames(genome,
                                                       parentTrack,
                                                       deep=False,
                                                       username=username)[0]
    filteredSubTrackLeaves = [
        x[0] for x in subTrackTriples if x not in [[], None]
        and not (excludeSelfIfValid and x[0] == '-- All subtypes --')
    ]
    return filteredSubTrackLeaves
Пример #42
0
 def execute(choices, galaxyFn=None, username=''):
     '''
     Is called when execute-button is pushed by web-user. Should print
     output as HTML to standard out, which will be directed to a results page
     in Galaxy history. If getOutputFormat is anything else than HTML, the
     output should be written to the file with path galaxyFn. If needed,
     StaticFile can be used to get a path where additional files can be put
     (e.g. generated image files). choices is a list of selections made by
     web-user in each options box.
     '''
     genome = choices[0]
     batchLines = choices[1].split('\n')
     assert choices[2] in ['False','True']
     verbose = (choices[2] == 'True')
     
     DebugAnalysisTool.setupDebugModeAndLogging(verbose=False) #set from selection box..
     try:
         GalaxyInterface.runBatchLines(batchLines, galaxyFn, genome, username)
     except Exception, e:
         print '</div>'
         print traceback.format_exc()            
         print e
         raise
Пример #43
0
def integrateTrackFromFile(inFn,
                           genome,
                           newTrackName,
                           username='',
                           privateAccess='True'):
    """inFn genome newTrackName  username='' privateAccess='True'"""
    from quick.util.CommonFunctions import convertTNstrToTNListFormat
    newTrackName = convertTNstrToTNListFormat(newTrackName, doUnquoting=True)

    if isinstance(privateAccess, basestring):
        privateAccess = ast.literal_eval(privateAccess)
    assert privateAccess in [False, True]

    from gold.util.CommonFunctions import createOrigPath
    path = createOrigPath(genome, newTrackName)
    assert not os.path.exists(
        path), 'Path already exists in standardized tracks: ' + path

    origFn = path + os.sep + os.path.basename(inFn)

    from quick.application.GalaxyInterface import GalaxyInterface
    GalaxyInterface._integrateTrack(genome, inFn, origFn, newTrackName,
                                    privateAccess, username)
Пример #44
0
    def findOverrepresentedTFsFromGeneSet(genome, tfSource, ensembleGeneIdList,upFlankSize, downFlankSize, geneSource, galaxyFn):
        #galaxyFn = '/usit/insilico/web/lookalike/galaxy_dist-20090924-dev/database/files/003/dataset_3347.dat'
        #print 'overriding galaxyFN!: ', galaxyFn
        galaxyId = extractIdFromGalaxyFn(galaxyFn)
        uniqueWebPath = getUniqueWebPath(extractIdFromGalaxyFn(galaxyFn))

        assert genome == 'hg18'
        
        tfTrackNameMappings = TfInfo.getTfTrackNameMappings(genome)
        tfTrackName = tfTrackNameMappings[tfSource]
        
        
        #Get gene track
        assert geneSource == 'Ensembl'
        targetGeneRegsTempFn = uniqueWebPath + os.sep + 'geneRegs.bed'
        geneRegsTrackName = GenomeInfo.getStdGeneRegsTn(genome)
        geneRegsFn = getOrigFn(genome, geneRegsTrackName, '.category.bed')
        GalaxyInterface.getGeneTrackFromGeneList(genome, geneRegsTrackName, ensembleGeneIdList, targetGeneRegsTempFn )
        
        assert upFlankSize == downFlankSize == 0 #Should instead extend regions to include flanks
        
        tcGeneRegsTempFn = uniqueWebPath + os.sep + 'tcGeneRegs.targetcontrol.bedgraph'
        #Think this will be okay, subtraction not necessary as targets are put first:
        controlGeneRegsTempFn = geneRegsFn
        #print targetGeneRegsTempFn, controlGeneRegsTempFn, tcGeneRegsTempFn
        GalaxyInterface.combineToTargetControl(targetGeneRegsTempFn, controlGeneRegsTempFn, tcGeneRegsTempFn)
        
        #tcGeneRegsExternalTN = ['external'] +galaxyId +  [tcGeneRegsTempFn]
        tcGeneRegsExternalTN = ExternalTrackManager.createStdTrackName(galaxyId, 'tempTc')
        
        #tcGeneRegsExternalTN = ['external'] +targetGalaxyId +  [tcGeneRegsTempFn]
        #tcGeneRegsExternalTN = ['galaxy', externalId, tcGeneRegsTempFn]
        
        targetGeneRegsExternalTN = ExternalTrackManager.createStdTrackName(galaxyId, 'tempTc', '1')
        controlGeneRegsExternalTN = ExternalTrackManager.createStdTrackName(galaxyId, 'tempTc', '0')
        
        #pre-process
        print 'Pre-processing file: %s, with trackname: %s ' % (tcGeneRegsTempFn, tcGeneRegsExternalTN)
        ExternalTrackManager.preProcess(tcGeneRegsTempFn, tcGeneRegsExternalTN, 'targetcontrol.bedgraph',genome)
        print 'Pre-processing TN: ', targetGeneRegsExternalTN
        ExternalTrackManager.preProcess(targetGeneRegsTempFn, targetGeneRegsExternalTN, 'bed',genome)
        print 'Pre-processing TN: ', controlGeneRegsExternalTN
        ExternalTrackManager.preProcess(controlGeneRegsTempFn, controlGeneRegsExternalTN, 'bed',genome)
        
        #print tcGeneRegsExternalTN
        trackName1, trackName2 = tfTrackName, tcGeneRegsExternalTN
        
        analysisDef = 'Categories differentially located in targets?: Which categories of track1-points fall more inside case than control track2-segments? [rawStatistic:=PointCountInsideSegsStat:]' +\
                  '[tf1:=SegmentToStartPointFormatConverter:] [tf2:=TrivialFormatConverter:]' +\
                  '-> DivergentRowsInCategoryMatrixStat'
        regSpec, binSpec = '*','*'
        
        #print 'skipping preproc!!'
        #ExternalTrackManager.preProcess(tcGeneRegsExternalTN[-1], tcGeneRegsExternalTN, 'targetcontrol.bedgraph', genome)
        #ExternalTrackManager.preProcess(targetGeneRegsTempFn, targetGeneRegsExternalTN, 'bed', genome)
        
        GalaxyInterface.runManual([trackName1, trackName2], analysisDef, regSpec, binSpec, genome, printResults=True, printHtmlWarningMsgs=False)
Пример #45
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.
     '''
     
     batchLines = choices[0].split('\n')
     assert choices[1] in ['False','True']
     verbose = (choices[1] == 'True')
     
     from gold.application.LogSetup import setupDebugModeAndLogging
     setupDebugModeAndLogging()
     try:
         GalaxyInterface.runBatchLines(batchLines, galaxyFn, username=username)
     except Exception, e:
         print '</div>'
         print traceback.format_exc()            
         print e
         raise
    def validateAndReturnErrors(choices):
        '''
        Should validate the selected input parameters. If the parameters are not valid,
        an error text explaining the problem should be returned. The GUI then shows this text
        to the user (if not empty) and greys out the execute button (also if the text isempty).
        If all parameters are valid, the method should return None, which enables the execute button.
        '''
        genome, errorStr = CreateDnaBasedCustomTrackTool._getGenomeChoice(choices, genomeChoiceIndex=0)
        if errorStr:
            return errorStr

        winSize = choices[1]
        expression = choices[2]
        from quick.application.GalaxyInterface import GalaxyInterface
        return GalaxyInterface.validateDnaBasedExpressionAndReturnError(winSize, expression)
Пример #47
0
    def execute(cls, choices, galaxyFn=None, username=''):
        start = time.time()
        genome = choices[0]
        trackName = choices[1].split(':')
        #outFn = open(NONSTANDARD_DATA_PATH+'/hg19/Private/Sigven/resultat.bed','w')
        analysisDef = '-> ConvertToNonOverlappingCategorySegmentsPythonStat' #'Python'
        for regSpec in  GenomeInfo.getChrList(genome):
            res = GalaxyInterface.runManual([trackName], analysisDef, regSpec, '*', genome, username=username, \
                                            printResults=False, printHtmlWarningMsgs=False)

            from gold.origdata.TrackGenomeElementSource import TrackViewGenomeElementSource
            from gold.origdata.BedComposer import CategoryBedComposer
            for resDict in res.values():
                tvGeSource = TrackViewGenomeElementSource(genome, resDict['Result'], trackName)
                CategoryBedComposer(tvGeSource).composeToFile(outFn)
Пример #48
0
    def execute(cls, choices, galaxyFn=None, username=''):
        start = time.time()
        genome = choices[0]
        trackName = choices[1].split(':')
        #outFn = open(NONSTANDARD_DATA_PATH+'/hg19/Private/Sigven/resultat.bed','w')
        analysisDef = '-> ConvertToNonOverlappingCategorySegmentsPythonStat'  #'Python'
        for regSpec in GenomeInfo.getChrList(genome):
            res = GalaxyInterface.runManual([trackName], analysisDef, regSpec, '*', genome, username=username, \
                                            printResults=False, printHtmlWarningMsgs=False)

            from gold.origdata.TrackGenomeElementSource import TrackViewGenomeElementSource
            from gold.origdata.BedComposer import CategoryBedComposer
            for resDict in res.values():
                tvGeSource = TrackViewGenomeElementSource(
                    genome, resDict['Result'], trackName)
                CategoryBedComposer(tvGeSource).composeToFile(outFn)
Пример #49
0
    def _isValidTrack(choices, tnChoiceIndex=1, genomeChoiceIndex=0):
        from quick.application.GalaxyInterface import GalaxyInterface
        from quick.application.ProcTrackOptions import ProcTrackOptions

        genome, errorStr = GeneralGuiTool._getGenomeChoice(
            choices, genomeChoiceIndex)
        if errorStr or genome is None:
            return False

        trackName, errorStr = GeneralGuiTool._getTrackChoice(
            choices, tnChoiceIndex)
        if errorStr:
            return False

        return ProcTrackOptions.isValidTrack(genome, trackName, True) or \
            GalaxyInterface.isNmerTrackName(genome, trackName)
Пример #50
0
    def _constructBins(regSpec, binSpec, genome, trackName1, trackName2):
        #Construct and check bins
        try:
            #userBinSource= UserBinSource(regSpec, binSpec)
            from quick.application.GalaxyInterface import GalaxyInterface
#            from config.Config import DEFAULT_GENOME
            userBinSource = GalaxyInterface._getUserBinSource(regSpec, binSpec, genome, trackName1, trackName2)
            return [None, userBinSource]
        except Exception, e:
            #results = Results(trackName1, trackName2, statClassName)
            results = Results([],[],'')
            results.addError(InvalidRunSpecException('Error in specification of analysis region or binsize: ' + str(e)))
            logMessage('Error in specification of analysis region (' + regSpec +') or binsize: (' + binSpec + ')')
            if DebugConfig.PASS_ON_BATCH_EXCEPTIONS:
                raise
            return [results, None]
 def PrintResultToHistItem(cls, outFn, geSource, preProcTN1, genome, username):
     analysisDef = 'dummy ->SplitToCorrespondingSubBinsBasedOnBreakpointsStat'
     #outFile = open(outFn,'w')
     with open(outFn,'w') as outFile:
         print>>outFile, '##track type: valued segments\n###seqid\tstart\tend\tvalue\tstrand'
         for ge in geSource:
             regSpec = '%s:%i-%i' %(ge.chr, ge.start+1, ge.end) #+1 since assumed 1-indexed, end-inclusive
 
             #userBinSource, fullRunArgs = GalaxyInterface._prepareRun(preProcTN1, None, analysisDef, regSpec, '*', genome)
             #res = AnalysisDefJob(analysisDef, preProcTN1, None, userBinSource, **fullRunArgs).run(printProgress=False)
             #trackName
             res = GalaxyInterface.runManual([preProcTN1], analysisDef, regSpec, '*', genome, username=username, \
                                             printResults=False, printProgress=False, printHtmlWarningMsgs=False)
 
             for region,resDict in res.items():
                 print>>outFile, resDict['Result']
Пример #52
0
    def _getAllOutputFormatsForTrack(genome, track):
        from quick.application.GalaxyInterface import GalaxyInterface

        trackOutputFormats = set()

        extractionOptions = \
            GalaxyInterface.getTrackExtractionOptions(
                genome, track.trackName)

        for opt in extractionOptions:
            extFormat, suffix = opt
            formatInfo = FileFormatInfo(
                *TrackExtractor.getAttrsFromExtractionFormat(extFormat),
                suffix=suffix)
            trackOutputFormats.add(formatInfo)

        return trackOutputFormats
Пример #53
0
    def findTFsOccurringInRegions(cls, genome, tfSource, regionsBedFn, upFlankSize, downFlankSize, galaxyFn):
        uniqueWebPath = getUniqueWebPath(extractIdFromGalaxyFn(galaxyFn))
        #assert genome == 'hg18' #other genomes not supported. TF id links do not specify genome for pre-selection of analysis
        
        tfTrackNameMappings = TfInfo.getTfTrackNameMappings(genome)
        assert tfTrackNameMappings != {}, 'No TF info for genome: %s' % genome
        
        tfTrackName = tfTrackNameMappings[tfSource]
                
        if (upFlankSize == downFlankSize == 0):
            flankedRegionsFn = regionsBedFn
        else:
            flankedRegionsFn= uniqueWebPath + os.sep + 'flankedRegs.bed'
            GalaxyInterface.expandBedSegments(regionsBedFn, flankedRegionsFn, genome, upFlankSize, downFlankSize)

        regSpec, binSpec = 'bed', flankedRegionsFn
        res = cls._runCategoryPointCount(genome, regSpec, binSpec, tfTrackName)

        tfNames = res.getResDictKeys()
        #print 'RES: ', res.getGlobalResult()[tfNames[0]], type(res.getGlobalResult()[tfNames[0]])
        import third_party.safeshelve as safeshelve
        pwm2tfids = safeshelve.open(os.sep.join([HB_SOURCE_CODE_BASE_DIR,'data','pwm2TFids.shelf']), 'r')
        tf2class = safeshelve.open(os.sep.join([HB_SOURCE_CODE_BASE_DIR,'data','TfId2Class.shelf']), 'r')
        pwmName2id= safeshelve.open(os.sep.join([HB_SOURCE_CODE_BASE_DIR,'data','pwmName2id.shelf']), 'r')
        #print tfNames[0],tfNames[1], ' VS ', pwm2tfids.keys()[0], len(pwm2tfids)
        #tfs = list(reversed(sorted([(res.getGlobalResult()[tf], tf, '%s (%i hits (class %s))'%(tf, res.getGlobalResult()[tf]), '/'.join([tf2class[x] for x in pwm2tfids[tf]]) ) for tf in tfNames]))) #num hits, tfName, tfTextInclHits
        tfs = list(reversed(sorted([(res.getGlobalResult()[tf], tf, '%s (%i hits )'%(tf, res.getGlobalResult()[tf]) + \
                                     (' (class: %s)'%'/'.join(set([str(tf2class.get(x)) for x in pwm2tfids[pwmName2id[tf]] if x in tf2class]))\
                                      if (tf in pwmName2id and pwmName2id[tf] in pwm2tfids and any([x in tf2class for x in pwm2tfids[pwmName2id[tf]]]))\
                                    else '') ) \
                                    for tf in tfNames])) ) #num hits, tfName, tfTextInclHits
        
        tfsPlural = 's' if len(tfs)!=1 else ''
        print '<p>There are %i TF%s targeting your regions of interest, using "%s" as source of TF occurrences.</p>' % (len(tfs), tfsPlural, tfSource)
        
        expansionStr = ' flanked' if not (upFlankSize == downFlankSize == 0) else ''                

        idHtmlFileNamer = GalaxyRunSpecificFile(['allTfIds.html'],galaxyFn)
        idHtmlFileNamer.writeTextToFile('<br>'.join(['<a href=/hbdev/hyper?track1=%s&track2=>%s</a>'%( quote(':'.join(tfTrackName+[tf[1]])), tf[2]) for tf in tfs]))
        print '<p>', idHtmlFileNamer.getLink('Inspect html file'), ' of all TF IDs occurring 1 or more times within your%s regions of interest, with each TF ID linking to analysis with this TF pre-selected.</p>' % (expansionStr)

        idFileNamer = GalaxyRunSpecificFile(['allTfIds.txt'],galaxyFn)
        idFileNamer.writeTextToFile(os.linesep.join([tf[2] for tf in tfs]) + os.linesep)
        print '<p>', idFileNamer.getLink('Inspect text file'), ' listing all TF IDs occurring 1 or more times within your%s regions of interest.</p>' % (expansionStr)
    
        extractedTfbsFileNamer = GalaxyRunSpecificFile(['tfbsInGeneRegions.bed'],galaxyFn)
        GalaxyInterface.extractTrackManyBins(genome, tfTrackName, regSpec, binSpec, True, 'bed', False, False, extractedTfbsFileNamer.getDiskPath(), True)
        print '<p>', extractedTfbsFileNamer.getLoadToHistoryLink('Inspect bed-file'), 'of all TF binding sites occurring within your%s regions of interest.</p>' % (expansionStr)

        for dummy,tf,dummy2 in tfs:            
            extractedTfbsFileNamer = GalaxyRunSpecificFile([tf+'_tfbsInGeneRegions.bed'],galaxyFn)
            GalaxyInterface.extractTrackManyBins(genome, tfTrackName+[tf], regSpec, binSpec, True, 'bed', False, False, extractedTfbsFileNamer.getDiskPath())
            print '<p>', extractedTfbsFileNamer.getLoadToHistoryLink('Binding sites of the TF %s' %tf, 'bed'), 'occurring within your%s regions of interest (bed-file).</p>' % (expansionStr)
Пример #54
0
    def PrintResultToHistItem(cls, outFn, geSource, preProcTN1, genome,
                              username):
        analysisDef = 'dummy ->SplitToCorrespondingSubBinsBasedOnBreakpointsStat'
        #outFile = open(outFn,'w')
        with open(outFn, 'w') as outFile:
            print >> outFile, '##track type: valued segments\n###seqid\tstart\tend\tvalue\tstrand'
            for ge in geSource:
                regSpec = '%s:%i-%i' % (
                    ge.chr, ge.start + 1, ge.end
                )  #+1 since assumed 1-indexed, end-inclusive

                #userBinSource, fullRunArgs = GalaxyInterface._prepareRun(preProcTN1, None, analysisDef, regSpec, '*', genome)
                #res = AnalysisDefJob(analysisDef, preProcTN1, None, userBinSource, **fullRunArgs).run(printProgress=False)
                #trackName
                res = GalaxyInterface.runManual([preProcTN1], analysisDef, regSpec, '*', genome, username=username, \
                                                printResults=False, printProgress=False, printHtmlWarningMsgs=False)

                for region, resDict in res.items():
                    print >> outFile, resDict['Result']
Пример #55
0
def countSubTracks(genome, parentTrack, recursioncount):
    if recursioncount < 10:
        thissubs=GalaxyInterface.getSubTrackNames(genome, parentTrack, False)[0]
        tname=genome+":"+":".join( parentTrack)
        #ti = TrackInfo.
        if thissubs: # has subtrakcs, ie is a folder
            thisndirs=0
            thisntracks=0
            for a in thissubs:               
               nextparenttrack=parentTrack
               nextparenttrack.append(a[0])               
               ndirs, ntracks =countSubTracks(genome, nextparenttrack, recursioncount+1)
               thisndirs=thisndirs+ndirs
               thisntracks=thisntracks+ntracks
               nextparenttrack=nextparenttrack.remove(a[0])
            print('plan to update trackinfo', tname,' set number of folders to ', thisndirs, ' and number of tracks to ', thisntracks)
            return(thisndirs+1, thisntracks)
        else:# is a track.          
            return (0,1)
    else:
        print "to many recursions"
Пример #56
0
    def execute(choices, galaxyFn=None, username=''):
        '''Is called when execute-button is pushed by web-user.
        Should print output as HTML to standard out, which will be directed to a results page in Galaxy history.
        If 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.
        '''
        
        genomesList = []
        for v in GalaxyInterface.getAllGenomes(username):
            if choices[3].get(v[0]):
                if choices[3][v[0]] and isdir(createDirPath(choices[1].split(':'),v[1])):
                    genomesList.append(v[1])
        #genomesList = [v[1] for v in GalaxyInterface.getAllGenomes(username) if choices[3][v[0]] and isdir(createDirPath(choices[1].split(':'),v[1]))]

        #print 'Executing...'
        genomes = [choices[0]] + genomesList
        oldTn = choices[1]
        newTn = choices[2]
        for genome in genomes:
            renameTrack(genome, oldTn.split(':'), newTn.split(':'))
            print '%s renamed to %s in genome %s.' % (oldTn, newTn, genome)
 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)
Пример #58
0
 def _getBasicTrackFormat(choices, tnChoiceIndex=1):
     from quick.application.GalaxyInterface import GalaxyInterface
     from gold.description.TrackInfo import TrackInfo
     
     genome = choices[0]
     tn = choices[tnChoiceIndex].split(':')
     
     if GalaxyInterface.isNmerTrackName(genome, tn):
         tfName = 'Points'
     else:
         tfName = TrackInfo(genome, tn).trackFormatName
     
     tfName = tfName.lower()
     
     if tfName.startswith('linked '):
         tfName = tfName[7:]
         
     tfName = tfName.replace('unmarked ','')
     tfName = tfName.replace('marked','valued')
     
     return genome, tn, tfName
Пример #59
0
    def runJob(batchLine, genome, fullAccess):
        if batchLine[0] == '#' or batchLine.strip()=='':
            return
            
        from urllib import unquote
        
        #Split and check number of columns
        cols = [x for x in batchLine.strip().split(BATCH_COL_SEPARATOR)]
        if len(cols) != 6:
            results = Results(['N/A'],['N/A'],'N/A')
            #results.addResultComponent( 'Invalid',InvalidRunResultComponent('Error in batch specification. 6 columns are required, while '\
            #                            + str(len(cols)) + ' are given.'))
            results.addError(InvalidRunSpecException('Error in batch specification. 6 columns are required, while '\
                                        + str(len(cols)) + ' are given: ' + batchLine))
            return results

        #print 'COL2: ',cols[2]
        cols[2] = unquote(cols[2])
        #print 'COL2: ',cols[2]
        from quick.application.ExternalTrackManager import ExternalTrackManager
        if ExternalTrackManager.isGalaxyTrack(cols[2].split(':')):
            cols[2] = ExternalTrackManager.extractFnFromGalaxyTN(cols[2].split(':'))
            #print 'COL2: ',cols[2]
        
        try:
            from quick.application.GalaxyInterface import GalaxyInterface
            trackName1 = [unquote(x) for x in cols[3].split(':')]
            trackName2 = [unquote(x) for x in cols[4].split(':')]
            cleanedTrackName1, cleanedTrackName2 = GalaxyInterface._cleanUpTracks([trackName1, trackName2], genome, realPreProc=True)

            cleanedTrackName1 = BatchRunner._inferTrackName(':'.join(cleanedTrackName1), genome, fullAccess)
            cleanedTrackName2 = BatchRunner._inferTrackName(':'.join(cleanedTrackName2), genome, fullAccess)
            
        except (InvalidRunSpecException,IdenticalTrackNamesError), e:
            if DebugConfig.PASS_ON_BATCH_EXCEPTIONS:
                raise
            results = Results(['N/A'],['N/A'],'N/A')
            results.addError(e)
            return results
Пример #60
0
    def execute(cls, choices, galaxyFn=None, username=''):
        
        shelveDict = {'track1':choices[3] if choices[3]!=cls.NO_TRACK_SHORTNAME else None}
        shelveDict['track2'] = choices[5] if choices[5]!=cls.NO_TRACK_SHORTNAME else None
        print len(choices)
        print cls._extraParams
        for i in range(len(cls._extraParams)):
            index = i*2+cls.FIRST_EXTRA_PARAM_BOX_NUMBER+1
            shelveDict[index] = choices[index].strip()
        
        DebugInfoShelve = safeshelve.open(cls.SHELVE_FN)
        DebugInfoShelve[choices[0]] = shelveDict
        DebugInfoShelve.close()
        
            
        try:
            
            cls.setupDebugModeAndLogging(verbose=False) #add box to select this
            
            print 'Getting Unsplittable statClass'
            statClassName = choices[0]        
            #statClass = STAT_CLASS_DICT[statClassName]
            #try:
                
                
            
            print 'Preparing arguments to init'
            unsplittableStatClass = MagicStatFactory._getClass(statClassName, 'Unsplittable')            
            genome = choices[1]
            
            from gold.track.Track import PlainTrack
            prefixTN1 = cls.STD_PREFIX_TN if choices[2] == 'yes' else []
            tn1 = prefixTN1 + choices[3].split(':') 
            track1 = PlainTrack(tn1) if choices[3]!=cls.NO_TRACK_SHORTNAME else None
            prefixTN2 = cls.STD_PREFIX_TN if choices[4] == 'yes' else []
            tn2 = prefixTN2 + choices[5].split(':')
            track2 = PlainTrack(tn2) if choices[5]!=cls.NO_TRACK_SHORTNAME else None
            from gold.track.GenomeRegion import GenomeRegion
            #region = GenomeRegion(genome, 'chr1',1000,2000)
            #region2 = GenomeRegion(genome, 'chr1',5000,6000)
            
            kwArgs = {}
            regVal = choices[cls.FIRST_EXTRA_PARAM_BOX_NUMBER+1]
            binSpecVal = choices[cls.FIRST_EXTRA_PARAM_BOX_NUMBER+3]
            ubSource = UserBinSource(regVal, binSpecVal, genome=genome)
            region = list(ubSource)[0]

            if len(cls._extraParams)>3:
                for i in range(len(cls._extraParams)):
                    paramName = choices[i*2+cls.FIRST_EXTRA_PARAM_BOX_NUMBER]
                    param = paramName[:paramName.find('(')].strip()
                    val = choices[i*2+cls.FIRST_EXTRA_PARAM_BOX_NUMBER+1].strip()
                    if val !='':
                        kwArgs[param] = val
                        shelveDict[i*2+cls.FIRST_EXTRA_PARAM_BOX_NUMBER+1] = val
                        
    
            print 'Calling __init__'
            #
            statObj = unsplittableStatClass(region, track1, track2, **kwArgs)
            
            print 'Calling createChildren'
            statObj.createChildren()
    
            print 'Calling getResult'
            statObj.getResult()
        
            #except:
            #    raise

            #print 'Preparing arguments to init'
            #genome = 'hg18'
            #prefixTN = ['DNA structure'] if choices[2] == 'yes' else []
            #from gold.track.Track import PlainTrack
            #tn1 = prefixTN + choices[3].split(':') 
            #track1 = PlainTrack(tn1)
            #tn2 = prefixTN + choices[5].split(':')
            #track2 = PlainTrack(tn2)
            #from gold.track.GenomeRegion import GenomeRegion
            ##region = GenomeRegion(genome, 'chr1',1000,2000)
            ##region2 = GenomeRegion(genome, 'chr1',5000,6000)
            #
            #kwArgs = {}
            #regVal = choices[cls.FIRST_EXTRA_PARAM_BOX_NUMBER+1]
            #binSpecVal = choices[cls.FIRST_EXTRA_PARAM_BOX_NUMBER+3]
            #ubSource = UserBinSource(regVal, binSpecVal, genome=choices[1])
            #region = list(UserBinSource)[0]
            #
            #if len(cls._extraParams)>2:
            #    for i in range(2,len(cls._extraParams)):
            #        paramName = choices[i*2+cls.FIRST_EXTRA_PARAM_BOX_NUMBER]
            #        param = paramName[:paramName.find('(')].strip()
            #        val = choices[i*2+cls.FIRST_EXTRA_PARAM_BOX_NUMBER+1].strip()
            #        if val !='':
            #            kwArgs[param] = val
            #            shelveDict[i*2+cls.FIRST_EXTRA_PARAM_BOX_NUMBER+1] = val
            #
            #
            ##extraParams += [v.strip() for v in choices.kwArgs.split(',')] if choices.kwArgs.strip() != '' else []        
            ##args = [region, track1, track2] 
            #
            #print 'Calling __init__'
            ##
            #statObj = unsplittableStatClass(region, track1, track2, **kwArgs)
            #
            #print 'Calling createChildren'
            #statObj.createChildren()
            #
            #print 'Calling getResult'
            #statObj.getResult()
            
            print 'Running StatJob'
            magicStatClass = STAT_CLASS_DICT[statClassName]
            #res = StatJob([region,region2],track1,track2,magicStatClass,**kwArgs).run()
            res = StatJob(ubSource,track1,track2,magicStatClass,**kwArgs).run()
            from quick.application.GalaxyInterface import GalaxyInterface
            GalaxyInterface._viewResults([res],galaxyFn)
            
        except Exception, e:
            print 'Error: ',e
            raise