Пример #1
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
Пример #2
0
    def _checkTrack(choices,
                    trackChoiceIndex=1,
                    genomeChoiceIndex=0,
                    filetype=None,
                    validateFirstLine=True):
        genome, errorStr = GeneralGuiTool._getGenomeChoice(
            choices, genomeChoiceIndex)
        if errorStr:
            return errorStr

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

        from quick.application.ExternalTrackManager import ExternalTrackManager
        if ExternalTrackManager.isGalaxyTrack(trackName):
            errorStr = GeneralGuiTool._checkHistoryTrack(
                choices, trackChoiceIndex, genome, filetype, validateFirstLine)
            if errorStr:
                return errorStr
        else:
            if not GeneralGuiTool._isValidTrack(choices, trackChoiceIndex,
                                                genomeChoiceIndex):
                return 'Please select a valid track'
Пример #3
0
 def _collectTracks(self):
     tracks = [self._track, self._track2]
     if 'trackNameIntensity' in self._kwArgs:
         assert not 'extraTracks' in self._kwArgs
         self._kwArgs['extraTracks'] = self._kwArgs['trackNameIntensity']
         
     if 'extraTracks' in self._kwArgs:
         from gold.track.Track import PlainTrack
         import re
         from config.Config import MULTIPLE_EXTRA_TRACKS_SEPARATOR
         extraTracks = self._kwArgs['extraTracks']
         if type(extraTracks) == str:
             extraTracks = extraTracks.split(MULTIPLE_EXTRA_TRACKS_SEPARATOR)
         for extraT in extraTracks:
             if type(extraT) == str:
                 #extraT = extraT.split('|')
                 #extraT = re.split('\^|\|',extraT)                    
                 extraT = convertTNstrToTNListFormat(extraT)
             if type(extraT) == list:
                 #print 'TEMP1: ', extraT
                 from urllib import unquote
                 extraT = [unquote(part) for part in extraT]
                 from quick.application.ExternalTrackManager import ExternalTrackManager
                 if ExternalTrackManager.isGalaxyTrack(extraT):
                     extraT = ExternalTrackManager.getPreProcessedTrackFromGalaxyTN(self.getGenome(), extraT)
                 extraT = PlainTrack(extraT)
                 tracks.append(extraT)
             
     return tracks
    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)
Пример #5
0
    def _collectTracks(self):
        tracks = [self._track, self._track2]
        #Map trackNameIntensity over to extraTrack, if extraTrack does not exist in itself (to allow selection of third track in GUI and through some existing code interfaces)
        if 'trackNameIntensity' in self._kwArgs:
            if not 'extraTracks' in self._kwArgs:
                self._kwArgs['extraTracks'] = self._kwArgs[
                    'trackNameIntensity']

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

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

        return tracks
Пример #6
0
    def parseBatchLine(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, None, None, None, None

        bc = BatchContents()

        bc.regSpec = cols[1]
        bc.binSpec = unquote(cols[2])
        from quick.application.ExternalTrackManager import ExternalTrackManager
        if ExternalTrackManager.isGalaxyTrack(bc.binSpec.split(':')):
            bc.binSpec = ExternalTrackManager.extractFnFromGalaxyTN(
                bc.binSpec.split(':'))

        try:
            from quick.application.GalaxyInterface import GalaxyInterface
            bc.trackName1 = [unquote(x) for x in cols[3].split(':')]
            bc.trackName2 = [unquote(x) for x in cols[4].split(':')]
            bc.cleanedTrackName1, bc.cleanedTrackName2 = GalaxyInterface._cleanUpTracks(
                [bc.trackName1, bc.trackName2], genome, realPreProc=True)

            bc.cleanedTrackName1 = BatchRunner._inferTrackName(
                bc.cleanedTrackName1, genome, fullAccess)
            bc.cleanedTrackName2 = BatchRunner._inferTrackName(
                bc.cleanedTrackName2, genome, fullAccess)

        except (InvalidRunSpecException, IdenticalTrackNamesError), e:
            if DebugConfig.PASS_ON_BATCH_EXCEPTIONS:
                raise
            bc.errorResult = Results(['N/A'], ['N/A'], 'N/A')
            bc.errorResult.addError(e)
            return bc
Пример #7
0
    def parseBatchLine(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.addError(InvalidRunSpecException('Error in batch specification. 6 columns are required, while '\
                                        + str(len(cols)) + ' are given: ' + batchLine))
            return results, None, None, None, None 

        bc = BatchContents()
        
        bc.regSpec = cols[1]
        bc.binSpec = unquote(cols[2])

        from quick.application.ExternalTrackManager import ExternalTrackManager
        if ExternalTrackManager.isGalaxyTrack(bc.binSpec.split(':')):
            bc.binSpec = ExternalTrackManager.extractFnFromGalaxyTN(bc.binSpec.split(':'))

        bc.statClassName, bc.paramDict = BatchRunner._parseClassAndParams(cols[5])

        bc.trackNames = [[unquote(x) for x in cols[i].split(':')] for i in [3, 4]]
        if 'trackNameIntensity' in bc.paramDict:
            bc.trackNames.append(convertTNstrToTNListFormat(bc.paramDict['trackNameIntensity'], doUnquoting=True))

        from quick.application.GalaxyInterface import GalaxyInterface

        partlyCleanedTrackNames = GalaxyInterface._cleanUpTracks(bc.trackNames, genome, realPreProc=True)

        try:
            bc.cleanedTrackNames = BatchRunner._inferTrackNames(partlyCleanedTrackNames, genome, fullAccess)

        except (InvalidRunSpecException,IdenticalTrackNamesError), e:
            if DebugConfig.PASS_ON_BATCH_EXCEPTIONS:
                raise
            bc.errorResult = Results(['N/A'],['N/A'],'N/A')
            bc.errorResult.addError(e)
            return bc
Пример #8
0
    def _getValueTypeName(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)
            valTypeName = TrackFormat.createInstanceFromGeSource(
                geSource).getValTypeName()
        else:
            if GalaxyInterface.isNmerTrackName(genome, tn):
                valTypeName = ''
            else:
                valTypeName = TrackInfo(genome, tn).markType
        return valTypeName.lower()
Пример #9
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