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...'
        genome = choices[0]
        galaxyTN = choices[1].split(':')
        #print 'galaxyTN: ',galaxyTN , type(galaxyTN)
        fn = ExternalTrackManager.extractFnFromGalaxyTN(galaxyTN)
        print 'Disk path for selected history element: <br>%s<br><br>' % fn
        from proto.hyperbrowser.StaticFile import GalaxyRunSpecificFile
        staticFile = GalaxyRunSpecificFile([],fn)
        print 'HyperBrowser data path (static file path) corresponding to selected history element: <br>%s<br><br>' % staticFile.getDiskPath()

        from config.Config import EXT_PROCESSED_DATA_PATH
        try:
            tn = ExternalTrackManager.getStdTrackNameFromGalaxyTN(galaxyTN)[:-1]
            preProcPath = '/'.join([EXT_PROCESSED_DATA_PATH,'100000','noOverlaps',genome] + tn)
            import os
            lastTnPart = os.listdir(preProcPath)
            assert len(lastTnPart)==1, lastTnPart
            #preProcPath += '/'+lastTnPart[0]
            tn += lastTnPart
            preProcPath = '/'.join([EXT_PROCESSED_DATA_PATH,'100000','noOverlaps',genome] + tn)

            print 'HyperBrowser pre-processed track name (if applicable): <br>%s<br><br>' % tn
            print 'HyperBrowser pre-processed track path (if applicable): <br>%s<br><br>' % preProcPath
        except:
            print '(Not printing track name, as history element does not appear to be a (valid) track.)<br>'
        print 'HyperBrowser URL path (static file URL) corresponding to selected history element: <br>%s<br><br>' % staticFile.getURL()

        # Does not work correctly, as the id needs to be the history id, and not the dataset id,
        # which may be different. Dataset id may perhaps be found from history id in the following manner (untested):
        #
        # data = trans.sa_session.query( trans.app.model.HistoryDatasetAssociation ).get( trans.security.decode_id( history_id ) )
        # dataset_id = extractIdFromGalaxyFn(data.file_name)
        #
        # Not sure how to go the other way.
        #
        #from quick.util.CommonFunctions import extractIdFromGalaxyFn
        #from galaxy.web.security import SecurityHelper
        #from config.Config import GALAXY_ID_SECRET
        #secHelper = SecurityHelper(id_secret=GALAXY_ID_SECRET)
        #id = extractIdFromGalaxyFn(galaxyFn)
        #encodedId = secHelper.encode_id(id[1])
        #print 'Galaxy URL id: <br>%s<br><br>' % encodedId

        import os.path, time
        print "Time of creation for Galaxy history file: %s" % time.ctime(os.path.getctime(fn))
        print "Last modification for Galaxy history file: %s" % time.ctime(os.path.getmtime(fn))
    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.genome

        trackChoice = choices.history if choices.source == 'history' else choices.track
        trackName = trackChoice.split(':')

        if ExternalTrackManager.isGalaxyTrack(trackName):
            geSource = ExternalTrackManager.getGESourceFromGalaxyOrVirtualTN(
                trackName, genome)
            if not geSource.hasOrigFile():  #hbfunction
                stdTrackName = ExternalTrackManager.getStdTrackNameFromGalaxyTN(
                    trackName)
                ExternalTrackManager.renameExistingStdTrackIfNeeded(
                    genome, stdTrackName)
                geSource = FullTrackGenomeElementSource(genome,
                                                        stdTrackName,
                                                        allowOverlaps=False)
        else:
            try:
                geSource = FullTrackGenomeElementSource(genome,
                                                        trackName,
                                                        allowOverlaps=True)
                for ge in geSource:
                    break
            except:
                geSource = FullTrackGenomeElementSource(genome,
                                                        trackName,
                                                        allowOverlaps=False)

        threshold = float(choices.threshold)
        rule = RULE_DICT[choices.rule]

        composerCls = getComposerClsFromFileFormatName(choices.format)
        geModifier = GEValueThresholder(geSource, genome, threshold, rule)
        if choices.merge == 'Yes':
            if not geModifier.isSorted():
                geModifier = GenomeElementSorter(geModifier)
            geModifier = GEAdjacencyClusterer_Segment(geModifier)

        composerCls(geModifier).composeToFile(galaxyFn, ignoreEmpty=True)
Пример #4
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.genome
        
        trackChoice = choices.history if choices.source == 'history' else choices.track
        trackName = trackChoice.split(':')
        
        galaxyOutTrackName = 'galaxy:hbfunction:%s:Create function track of distance to nearest segment' % galaxyFn
        outTrackName = ExternalTrackManager.getStdTrackNameFromGalaxyTN(galaxyOutTrackName.split(':'))
        
        if choices.transform == 'no transformation':
            valTransformation = 'None'
        elif choices.transform =='logarithmic (log10(x))':
            valTransformation = 'log10'
        elif choices.transform == 'fifth square root (x**0.2)':
            valTransformation = 'power0.2'
        else:
            raise ShouldNotOccurError
        
        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)