Пример #1
0
    def validateAndReturnErrors(cls, 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 (even if the text is empty). If all parameters are valid,
        the method should return None, which enables the execute button.
        '''

        errorStr = cls._checkTrack(choices,
                                   trackChoiceIndex='track',
                                   genomeChoiceIndex='genome')
        if errorStr:
            return errorStr

        if choices.track and not choices.attr:
            return 'You have chosen a track with no attributes (columns) supported for splitting. ' \
                   'Attributes that do not support splitting are: ' + ', '.join(cls.UNSUPPORTED_ATTRS)

        geSource = etm.getGESourceFromGalaxyOrVirtualTN(
            choices.track, choices.genome)
        trackFormat = TrackFormat.createInstanceFromGeSource(geSource)

        if trackFormat.isDense():
            return 'The track format of the selected track file is: %s' % trackFormat.getFormatName() +\
                   ' This tool only supports track types Points, Segments, or variations of these.'
Пример #2
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
Пример #3
0
 def getOptionsBox3(prevChoices):
     if prevChoices[-1]:
         return ('__hidden__', prevChoices[-1])
     elif prevChoices[0] and prevChoices[1]:
         from quick.application.ExternalTrackManager import ExternalTrackManager
         geSource = ExternalTrackManager.getGESourceFromGalaxyOrVirtualTN(
             prevChoices[-2].split(':'), prevChoices[0])
         catSet = set([ge.val for ge in geSource if ge.val])
         return ('__hidden__', repr(catSet))
Пример #4
0
    def _getRawTrackView(self, region, borderHandling, allowOverlaps):
        assert region.start == 0 and region.end == 1
        
        from collections import OrderedDict
        from gold.track.CommonMemmapFunctions import findEmptyVal
        from gold.track.TrackView import TrackView
        import numpy as np
        
        geSource = ExternalTrackManager.getGESourceFromGalaxyOrVirtualTN(self.trackName, region.genome)
        prefixList = geSource.getPrefixList()
        valDataType = geSource.getValDataType()
        valDim = geSource.getValDim()
        weightDataType = geSource.getEdgeWeightDataType()
        weightDim = geSource.getEdgeWeightDim()

        startList, endList, valList, strandList, idList, edgesList, weightsList = [None]*7
        extraLists=OrderedDict()
        
        tf = TrackFormat.createInstanceFromPrefixList(prefixList, valDataType, valDim, \
                                                      weightDataType, weightDim)
        if allowOverlaps and (tf.isDense() or geSource.hasNoOverlappingElements()):
            raise IncompatibleTracksError(prettyPrintTrackName(self.trackName) + ' with format: '\
                                          + str(tf) + ' does not satisfy ' + str(self._trackFormatReq))
        
        denseAndInterval = tf.isDense() and tf.isInterval()
        numEls = 2 if denseAndInterval else 1
        
        if valDataType == 'S':
            valDataType = 'S2'
        if weightDataType == 'S':
            weightDataType = 'S2'
        
        for prefix in prefixList:
            if prefix == 'start':
                startList = np.array([-1], dtype='int32')
            elif prefix == 'end':
                if denseAndInterval:
                    endList = np.array([0, 1], dtype='int32')
                else:
                    endList = np.array([0], dtype='int32')
            elif prefix == 'val':
                valList = np.array([findEmptyVal(valDataType)] * valDim * numEls, \
                                   dtype=valDataType).reshape((numEls, valDim) if valDim > 1 else numEls)
            elif prefix == 'strand':
                strandList = np.array([1] * numEls, dtype='int8')
            elif prefix == 'id':
                idList = np.array([''] * numEls, dtype='S1')
            elif prefix == 'edges':
                edgesList = np.array([['']] * numEls, dtype='S1')
            elif prefix == 'weights':
                weightsList = np.array([[[findEmptyVal(weightDataType)]]] * weightDim * numEls, \
                                       dtype=weightDataType).reshape((numEls, 1, weightDim) if weightDim > 1 else (numEls, 1))
            else:
                extraLists[prefix] = np.array([''] * numEls, dtype='S1')
        
        return TrackView(region, startList, endList, valList, strandList, idList, edgesList, weightsList, borderHandling, allowOverlaps, extraLists)
Пример #5
0
    def _getRawTrackView(self, region, borderHandling, allowOverlaps):
        assert len(region) == 1

        from collections import OrderedDict
        from gold.track.CommonMemmapFunctions import findEmptyVal
        from gold.track.TrackView import TrackView
        import numpy as np

        geSource = ExternalTrackManager.getGESourceFromGalaxyOrVirtualTN(self.trackName, region.genome)
        prefixList = geSource.getPrefixList()
        valDataType = geSource.getValDataType()
        valDim = geSource.getValDim()
        weightDataType = geSource.getEdgeWeightDataType()
        weightDim = geSource.getEdgeWeightDim()

        startList, endList, valList, strandList, idList, edgesList, weightsList = [None]*7
        extraLists=OrderedDict()

        tf = TrackFormat.createInstanceFromPrefixList(prefixList, valDataType, valDim, \
                                                      weightDataType, weightDim)
        if allowOverlaps and (tf.isDense() or geSource.hasNoOverlappingElements()):
            raise IncompatibleTracksError(prettyPrintTrackName(self.trackName) + ' with format: '\
                                          + str(tf) + ' does not satisfy ' + str(self._trackFormatReq))

        denseAndInterval = tf.isDense() and tf.isInterval()
        numEls = 2 if denseAndInterval else 1

        if valDataType == 'S':
            valDataType = 'S2'
        if weightDataType == 'S':
            weightDataType = 'S2'

        for prefix in prefixList:
            if prefix == 'start':
                startList = np.array([-1], dtype='int32')
            elif prefix == 'end':
                if denseAndInterval:
                    endList = np.array([0, 1], dtype='int32')
                else:
                    endList = np.array([0], dtype='int32')
            elif prefix == 'val':
                valList = np.array([findEmptyVal(valDataType)] * valDim * numEls, \
                                   dtype=valDataType).reshape((numEls, valDim) if valDim > 1 else numEls)
            elif prefix == 'strand':
                strandList = np.array([1] * numEls, dtype='int8')
            elif prefix == 'id':
                idList = np.array([''] * numEls, dtype='S1')
            elif prefix == 'edges':
                edgesList = np.array([['']] * numEls, dtype='S1')
            elif prefix == 'weights':
                weightsList = np.array([[[findEmptyVal(weightDataType)]]] * weightDim * numEls, \
                                       dtype=weightDataType).reshape((numEls, 1, weightDim) if weightDim > 1 else (numEls, 1))
            else:
                extraLists[prefix] = np.array([''] * numEls, dtype='S1')

        return TrackView(region, startList, endList, valList, strandList, idList, edgesList, weightsList, borderHandling, allowOverlaps, extraLists)
Пример #6
0
 def getExtraHistElements(cls, choices):
     if choices.genome and choices.catTrack:
         from quick.webtools.GeneralGuiTool import HistElement
         genome = choices.genome
         outputType = choices.outputType
         catTrack = choices.catTrack.split(':')
         geSource = ExternalTrackManager.getGESourceFromGalaxyOrVirtualTN(
             catTrack, genome)
         return [HistElement(ge.val, outputType) for ge in geSource
                 ] + [HistElement('GSuite from categorical', 'gsuite')]
Пример #7
0
 def getOptionsBoxFormat(prevChoices):
     if prevChoices.track:
         geSource = etm.getGESourceFromGalaxyOrVirtualTN(
             prevChoices.track, prevChoices.genome)
         tf = TrackFormat.createInstanceFromGeSource(geSource)
         matchingComposers = findMatchingFileFormatComposers(tf)
         conversions = [geSource.getFileFormatName() + \
                        ' (no conversion, track type: %s)' % tf.getFormatName()]
         conversions += ['%s -> %s (track type: %s)' % (geSource.getFileFormatName(), \
                         composerInfo.fileFormatName, composerInfo.trackFormatName) \
                         for composerInfo in matchingComposers \
                         if geSource.getFileFormatName() != composerInfo.fileFormatName]
         return conversions
    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)
Пример #9
0
    def execute(cls, choices, galaxyFn=None, username=''):
        from quick.application.ExternalTrackManager import ExternalTrackManager

        histFn = ExternalTrackManager.extractFnFromGalaxyTN(choices[1])
        chosenCatsList = [k for k, v in choices[-1].items() if v]
        geSource = ExternalTrackManager.getGESourceFromGalaxyOrVirtualTN(
            choices[1].split(':'), choices[0])
        utfil = open(galaxyFn, 'w')
        for ge in geSource:
            if ge.val in chosenCatsList:
                print >> utfil, '\t'.join(
                    [ge.chr, str(ge.start),
                     str(ge.end), ge.val])
        utfil.close()
Пример #10
0
    def getOptionsBoxStatistics(cls, prevChoices):
        if prevChoices.showStatistics == cls.SHOW_STATISTICS_CHOICE_YES:
            geSource = etm.getGESourceFromGalaxyOrVirtualTN(
                prevChoices.track, prevChoices.genome)

            valDict = defaultdict(int)
            numEls = 0
            for ge in geSource:
                valDict[str(getattr(ge, prevChoices.attr))] += 1
                numEls += 1

            return [['Statistic', 'Result'], \
                    ['Number of elements in track', str(numEls)],
                    ['Number of unique attribute values', str(len(valDict))],
                    ['Attribute(s) least represented in track (number of elements)', \
                     '|'.join(findKeysWithMinVal(valDict)) + ' (%s)' % min(valDict.values())],
                    ['Attribute(s) most represented in track (number of elements)', \
                     '|'.join(findKeysWithMaxVal(valDict)) + ' (%s)' % max(valDict.values())]]
Пример #11
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()
Пример #12
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
        geSource = etm.getGESourceFromGalaxyOrVirtualTN(choices.track, genome)
        #hiddenStorageFn = cls.extraGalaxyFn[cls.HISTORY_HIDDEN_TRACK_STORAGE]
        hiddenStorageFn = galaxyFn
        composerCls = cls._getComposerCls(choices)
        valAttr = choices.attr

        gSuite = createGalaxyGSuiteBySplittingInputFileOnAttribute\
            (hiddenStorageFn, geSource, genome, composerCls, valAttr)

        GSuiteComposer.composeToFile(gSuite, galaxyFn)
Пример #13
0
    def execute(choices, galaxyFn=None, username=''):
        utfil = open(galaxyFn, 'w')
        genome = choices[0]
        trackName = choices[1].split(':')
        intervals = sorted([float(v.strip()) for v in choices[2].split(',')])
        geSource = ExternalTrackManager.getGESourceFromGalaxyOrVirtualTN(
            trackName, genome)

        for ge in geSource:
            value = ge.val
            counter = 0
            while counter < len(intervals) and intervals[counter] <= value:
                counter += 1
            if counter == len(intervals):
                category = str(intervals[-1]) + '-inf'
            else:
                category = str(intervals[counter - 1]) + '-' + str(
                    intervals[counter]) if counter > 0 else '0.0-' + str(
                        intervals[0])
            print >> utfil, '%s\t%i\t%i\t%s' % (ge.chr, ge.start, ge.end,
                                                category)
Пример #14
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.
        '''
        categoryToGenomeElementListDict = defaultdict(list)
        genome = choices.genome
        outputType = choices.outputType
        catTrack = choices.catTrack.split(':')
        geSource = ExternalTrackManager.getGESourceFromGalaxyOrVirtualTN(
            catTrack, genome)
        for ge in geSource:
            categoryToGenomeElementListDict[ge.val].append(ge)

        for category, genomeElementList in categoryToGenomeElementListDict.iteritems(
        ):
            geSourceWrapper = ListGESourceWrapper(geSource, genomeElementList)
            composer = cls.getComposer(geSourceWrapper, outputType)
            #             staticFile = GalaxyRunSpecificFile(catTrack + [category, outputType], galaxyFn)
            composer.composeToFile(cls.extraGalaxyFn[category])

        outGSuite = GSuite()
        for category, galaxyFileName in OrderedDict([
            (x, cls.extraGalaxyFn[x])
                for x in categoryToGenomeElementListDict.keys()
        ]).iteritems():
            uri = GalaxyGSuiteTrack.generateURI(galaxyFn=galaxyFileName,
                                                suffix=outputType)
            outGSuite.addTrack(GSuiteTrack(uri, title=category, genome=genome))
        GSuiteComposer.composeToFile(
            outGSuite, cls.extraGalaxyFn['GSuite from categorical'])

        print 'Execution done!'
Пример #15
0
    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 (even if the text is empty). If all parameters are valid,
        the method should return None, which enables the execute button.
        '''

        if not choices.genome:
            return 'Please select genome'

        if not choices.catTrack:
            return 'Please select categorical track from history'

        geSource = ExternalTrackManager.getGESourceFromGalaxyOrVirtualTN(
            choices.catTrack.split(':'), choices.genome)

        trackFormat = TrackFormat.createInstanceFromGeSource(geSource)

        if trackFormat.getValTypeName() != 'Category':
            return 'Please select <b>categorical</b> track from history, current is of type ' + trackFormat.getValTypeName(
            )
Пример #16
0
 def getOptionsBoxAttr(cls, prevChoices):
     if prevChoices.track:
         geSource = etm.getGESourceFromGalaxyOrVirtualTN(
             prevChoices.track, prevChoices.genome)
         return [prefix for prefix in geSource.getPrefixList() \
                 if prefix not in cls.UNSUPPORTED_ATTRS ]