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(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, 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)
Ejemplo n.º 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)
Ejemplo n.º 5
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)