Example #1
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.
        '''

        import gold.gsuite.GSuiteComposer as GSuiteComposer
        from gold.gsuite.GSuite import GSuite
        from gold.gsuite.GSuiteTrack import GSuiteTrack, GalaxyGSuiteTrack
        from quick.application.UserBinSource import GlobalBinSource
        from quick.extra.ProgressViewer import ProgressViewer
        from quick.extra.TrackExtractor import TrackExtractor

        genome = choices.genome
        fullGenomeBins = GlobalBinSource(genome)
        gSuite = getGSuiteFromGalaxyTN(choices.gsuite)

        progressViewer = ProgressViewer(
            [(cls.PROGRESS_PROCESS_DESCRIPTION, len(gSuite))], galaxyFn)

        outGSuite = GSuite()
        hiddenStorageFn = cls.extraGalaxyFn[getGSuiteHistoryOutputName(
            'storage', datasetInfo=choices.gsuite)]

        fileNameSet = set()
        for track in gSuite.allTracks():
            fileName = cls._getUniqueFileName(fileNameSet, track.trackName)
            title = track.title
            attributes = track.attributes
            fi = cls._getFileFormatInfo(choices, gSuite, genome, track)

            uri = GalaxyGSuiteTrack.generateURI(galaxyFn=hiddenStorageFn,
                                                extraFileName=fileName,
                                                suffix=fi.suffix)

            gSuiteTrack = GSuiteTrack(uri,
                                      title=title,
                                      genome=genome,
                                      attributes=attributes)

            TrackExtractor.extractOneTrackManyRegsToOneFile(
                track.trackName,
                fullGenomeBins,
                gSuiteTrack.path,
                fileFormatName=fi.fileFormatName,
                globalCoords=True,
                asOriginal=fi.asOriginal,
                allowOverlaps=fi.allowOverlaps)

            outGSuite.addTrack(gSuiteTrack)
            progressViewer.update()

        primaryFn = cls.extraGalaxyFn[getGSuiteHistoryOutputName(
            'primary', datasetInfo=choices.gsuite)]
        GSuiteComposer.composeToFile(outGSuite, primaryFn)
 def getExtraHistElements(cls, choices):
     from quick.webtools.GeneralGuiTool import HistElement
     return [
         HistElement(
             getGSuiteHistoryOutputName('nopreprocessed',
                                        datasetInfo=choices.history),
             'gsuite'),
         HistElement(
             getGSuiteHistoryOutputName('preprocessed',
                                        datasetInfo=choices.history),
             'gsuite')
     ]
    def getExtraHistElements(cls, choices):
        from quick.webtools.GeneralGuiTool import HistElement
        from gold.gsuite.GSuiteConstants import GSUITE_SUFFIX, GSUITE_STORAGE_SUFFIX
        
        fileList = [HistElement(getGSuiteHistoryOutputName(
                        'nomanipulate', datasetInfo=choices.history), GSUITE_SUFFIX)]
        fileList += [HistElement(getGSuiteHistoryOutputName(
                         'primary', cls.OUTPUT_DESCRIPTION, choices.history), GSUITE_SUFFIX)]
        fileList += [HistElement(getGSuiteHistoryOutputName(
                         'storage', cls.OUTPUT_DESCRIPTION, choices.history),
                         GSUITE_STORAGE_SUFFIX, hidden=True)]

        return fileList
Example #4
0
 def getExtraHistElements(cls, choices):
     from quick.webtools.GeneralGuiTool import HistElement
     histList = []
     histList.append(
         HistElement(
             getGSuiteHistoryOutputName('primary',
                                        datasetInfo=choices.gsuite),
             GSuiteConstants.GSUITE_SUFFIX))
     histList.append(
         HistElement(getGSuiteHistoryOutputName('storage',
                                                datasetInfo=choices.gsuite),
                     GSuiteConstants.GSUITE_SUFFIX,
                     hidden=True))
     return histList
 def getExtraHistElements(cls, choices):
     desc = cls.OUTPUT_GSUITE_DESCRIPTION
     return [HistElement(getGSuiteHistoryOutputName(
                             'nointersect', description=desc, datasetInfo=choices.gSuite),
                         GSuiteConstants.GSUITE_SUFFIX),
             HistElement(getGSuiteHistoryOutputName(
                             'primary', description=desc, datasetInfo=choices.gSuite),
                         GSuiteConstants.GSUITE_SUFFIX),
             HistElement(getGSuiteHistoryOutputName(
                             'nopreprocessed', description=desc, datasetInfo=choices.gSuite),
                         GSuiteConstants.GSUITE_SUFFIX),
             HistElement(getGSuiteHistoryOutputName(
                             'preprocessed', description=desc, datasetInfo=choices.gSuite),
                         GSuiteConstants.GSUITE_SUFFIX),
             HistElement(getGSuiteHistoryOutputName(
                             'storage', description=desc, datasetInfo=choices.gSuite),
                         GSuiteConstants.GSUITE_STORAGE_SUFFIX, hidden=True)]
Example #6
0
    def getOutputName(cls, choices):
        if choices.track:
            from quick.gsuite.GSuiteHbIntegration import getGSuiteHistoryOutputName

            description = ', splitted on column: %s' % choices.attr

            return getGSuiteHistoryOutputName('primary', description,
                                              choices.track)
    def getExtraHistElements(cls, choices):
        from quick.webtools.GeneralGuiTool import HistElement
        from gold.gsuite.GSuiteConstants import GSUITE_STORAGE_SUFFIX, GSUITE_SUFFIX

        desc = cls._getOutputHistoryDescription(choices)
        fileList = [
            HistElement(getGSuiteHistoryOutputName('primary', desc),
                        GSUITE_SUFFIX),
            HistElement(getGSuiteHistoryOutputName('storage', desc),
                        GSUITE_STORAGE_SUFFIX,
                        hidden=True)
        ]

        # if choices.archive:
        #for archivedFile in cls._getArchiveReader(choices):
        #    fileList.append( HistElement(archivedFile.title, archivedFile.suffix, hidden=True) )

        return fileList
Example #8
0
    def getExtraHistElements(cls, choices):
        from quick.webtools.GeneralGuiTool import HistElement
        fileList = [
            HistElement(
                getGSuiteHistoryOutputName('nodownload',
                                           datasetInfo=choices.history),
                GSUITE_SUFFIX)
        ]
        fileList += [
            HistElement(
                getGSuiteHistoryOutputName('primary',
                                           datasetInfo=choices.history),
                GSUITE_SUFFIX)
        ]
        if choices.preProcess == 'Yes':
            fileList += [
                HistElement(
                    getGSuiteHistoryOutputName('nopreprocessed',
                                               datasetInfo=choices.history),
                    GSUITE_SUFFIX)
            ]
            fileList += [
                HistElement(
                    getGSuiteHistoryOutputName('preprocessed',
                                               datasetInfo=choices.history),
                    GSUITE_SUFFIX)
            ]
        fileList += [
            HistElement(getGSuiteHistoryOutputName(
                'storage', datasetInfo=choices.history),
                        GSUITE_STORAGE_SUFFIX,
                        hidden=True)
        ]

        # if choices.history:
        #from quick.multitrack.MultiTrackCommon import getGSuiteFromGalaxyTN
        #gSuite = getGSuiteFromGalaxyTN(choices.history)
        #
        #for track in gSuite.allTracks():
        #    from gold.gsuite.GSuiteDownloader import getTitleAndSuffixWithCompressionSuffixesRemoved
        #    title, suffix = getTitleAndSuffixWithCompressionSuffixesRemoved(track)
        #    fileList.append( HistElement(title, suffix, hidden=True) )

        return fileList
    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.gsuite.GSuiteArchiver import ArchiveToGalaxyGSuiteTrackIterator, \
                                               convertArchiveToGSuite
        import gold.gsuite.GSuiteComposer as GSuiteComposer
        from quick.gsuite.GSuiteHbIntegration import \
            writeGSuiteHiddenTrackStorageHtml
        from quick.extra.ProgressViewer import ProgressViewer

        from quick.util.debug import DebugUtil
        # DebugUtil.insertBreakPoint(username=username, currentUser='******')

        archive = cls._getArchiveReader(choices)
        trackCount = sum(1 for file in archive)

        desc = cls._getOutputHistoryDescription(choices)
        progressViewer = ProgressViewer([('Extract tracks', trackCount)],
                                        galaxyFn)

        storeHierarchy = choices.storeHierarchy == 'Yes'
        hiddenStorageFn = cls.extraGalaxyFn[getGSuiteHistoryOutputName(
            'storage', desc)]
        archiveToGSuiteTrackIter = \
            ArchiveToGalaxyGSuiteTrackIterator(archive, hiddenStorageFn, storeHierarchy)
        writeGSuiteHiddenTrackStorageHtml(hiddenStorageFn)

        gSuite = convertArchiveToGSuite(archiveToGSuiteTrackIter,
                                        progressViewer)

        GSuiteComposer.composeToFile(
            gSuite,
            cls.extraGalaxyFn[getGSuiteHistoryOutputName('primary', desc)])
    def getOutputName(cls, choices):
        from quick.gsuite.GSuiteHbIntegration import getGSuiteHistoryOutputName
        from quick.util.CommonFunctions import prettyPrintTrackName

        if choices.genome:
            parentTrack = choices.parentTrack.split(':')
            if parentTrack == ['']:
                description = 'All tracks'
            else:
                description = prettyPrintTrackName(parentTrack)

            return getGSuiteHistoryOutputName('preprocessed', description)
Example #11
0
    def getOutputName(cls, choices):
        from quick.gsuite.GSuiteHbIntegration import getGSuiteHistoryOutputName
        from proto.CommonFunctions import extractNameFromDatasetInfo

        selected = [
            extractNameFromDatasetInfo(val)
            for val in choices.history.values() if val is not None
        ]
        description = selected[0] + \
                      ' + %s more' % (len(selected)-1) if len(selected) > 1 else ''

        return getGSuiteHistoryOutputName('primary', description)
    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.
        '''
        import gold.gsuite.GSuiteComposer as GSuiteComposer
        from gold.gsuite.GSuitePreprocessor import GSuitePreprocessor
        from quick.extra.ProgressViewer import ProgressViewer
        from quick.multitrack.MultiTrackCommon import getGSuiteFromGalaxyTN

        inGSuite = getGSuiteFromGalaxyTN(choices.history)

        if choices.genome != inGSuite.genome:
            inGSuite.setGenomeOfAllTracks(choices.genome)

        progressViewer = ProgressViewer(
            [('Preprocess tracks', inGSuite.numTracks())], galaxyFn)

        gSuitePreprocessor = GSuitePreprocessor()
        outGSuite, errorGSuite = gSuitePreprocessor.visitAllGSuiteTracksAndReturnOutputAndErrorGSuites\
                                                    (inGSuite, progressViewer)

        #outGSuite, errorGSuite = inGSuite.preProcessAllLocalTracksAndReturnOutputAndErrorGSuites()

        nopreprocFn = cls.extraGalaxyFn[getGSuiteHistoryOutputName(
            'nopreprocessed', datasetInfo=choices.history)]
        GSuiteComposer.composeToFile(errorGSuite, nopreprocFn)

        preprocFn = cls.extraGalaxyFn[getGSuiteHistoryOutputName(
            'preprocessed', datasetInfo=choices.history)]
        GSuiteComposer.composeToFile(outGSuite, preprocFn)
    def getExtraHistElements(cls, choices):
        from gold.gsuite.GSuiteConstants import GSUITE_SUFFIX, GSUITE_STORAGE_SUFFIX
        fileList = []

        if choices.outputType and choices.downloadAndPreprocess == 'Yes' and \
                choices.source.find('HyperBrowser') == -1 and \
                choices.transfer != 'Yes':
            from quick.webtools.GeneralGuiTool import HistElement
            desc = unidecode(choices.subCategory)

            fileList += \
                [HistElement(getGSuiteHistoryOutputName('remote', desc), GSUITE_SUFFIX),
                 HistElement(getGSuiteHistoryOutputName('nodownload', desc), GSUITE_SUFFIX),
                 HistElement(getGSuiteHistoryOutputName('primary', desc), GSUITE_SUFFIX),
                 HistElement(getGSuiteHistoryOutputName('nopreprocessed', desc), GSUITE_SUFFIX),
                 HistElement(getGSuiteHistoryOutputName('preprocessed', desc), GSUITE_SUFFIX),
                 HistElement(getGSuiteHistoryOutputName('storage', desc), GSUITE_STORAGE_SUFFIX,
                                                        hidden=True)]

        return fileList
    def getOptionsBoxHistoryElementsInfo(cls, prevChoices):
        if not prevChoices.dataType:
            return

        desc = prevChoices.subCategory

        core = HtmlCore()
        core.styleInfoBegin(styleClass='infomessagesmall')
        core.paragraph(
            'This tool will create seven history elements (one of which is hidden):'
        )
        descriptionList = \
            [('%s' % getGSuiteHistoryOutputName('storage', desc),
              'hidden history element containing the actual downloaded track data. Should '
              'in most cases be ignored'),
             ('%s' % getGSuiteHistoryOutputName('preprocessed', desc),
              'use this in the analysis tool of choice'),
             ('%s' % getGSuiteHistoryOutputName('nopreprocessed', desc),
              'preprocessing fails due to some issues with the track data. Some '
              'manipulation is probably needed before one tries preprocessing again'),
             ('%s' % getGSuiteHistoryOutputName('primary', desc),
              'use this if you need to manipulate the raw track data using a manipulation '
              'tool. The GSuite resulting from manipulation needs to be preprocessed '
              'before analysis'),
             ('%s' % getGSuiteHistoryOutputName('nodownload', desc),
              'in some cases the downloading of tracks fails, but might work if one tries again'),
             ('%s' % getGSuiteHistoryOutputName('remote', desc),
              'this refers to the original files available at a remote server. Use this '
              'if one for some reason needs to re-download all the tracks'),
             ('%s' % getGSuiteHistoryOutputName('progress', desc),
              'click the eye icon of this element to show the progress of the import')]
        for label, description in descriptionList:
            core.descriptionLine(label, description)
        core.styleInfoEnd()

        return '__rawstr__', unicode(core)
Example #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.
        '''
        DebugMixin._setDebugModeIfSelected(choices)
        genome = choices.genome
        gSuite = getGSuiteFromGalaxyTN(choices.gsuite)
        #         fullCategory = AnalysisManager.combineMainAndSubCategories(choices.analysisCategory, 'Basic')
        fullCategory = AnalysisManager.combineMainAndSubCategories(
            'Descriptive statistics', 'Basic')
        tracks = list(gSuite.allTracks())
        analysisName = choices.analysis
        # selectedAnalysis = GSuiteSingleValueAnalysisPerTrackTool \
        #     ._resolveAnalysisFromName(gSuite.genome, fullCategory, tracks[0].trackName, analysisName)

        selectedAnalysis = cls.ANALYSIS_PRETTY_NAME_TO_ANALYSIS_SPEC_MAPPING[
            choices.analysis]

        regSpec, binSpec = UserBinMixin.getRegsAndBinsSpec(choices)
        analysisBins = GalaxyInterface._getUserBinSource(regSpec,
                                                         binSpec,
                                                         genome=genome)
        # paramName, paramValues = selectedAnalysis.getFirstOptionKeyAndValues()
        # if paramName and paramValues:
        #     if len(paramValues) == 1:
        #         selectedAnalysis.addParameter(paramName, paramValues[0])
        #     else:
        #         selectedAnalysis.addParameter(paramName, choices.paramOne)

        tableDict = OrderedDict()

        for track in tracks:
            tableDict[track.title] = OrderedDict()
            result = doAnalysis(selectedAnalysis, analysisBins, [track])
            resultDict = result.getGlobalResult()
            if 'Result' in resultDict:
                track.setAttribute(analysisName.lower(),
                                   str(resultDict['Result']))
                tableDict[
                    track.title][analysisName] = strWithNatLangFormatting(
                        resultDict['Result'])
            else:
                for attrName, attrVal in resultDict.iteritems():
                    attrNameExtended = analysisName + ':' + attrName
                    track.setAttribute(attrNameExtended.lower(), str(attrVal))
                    tableDict[track.title][
                        attrNameExtended] = strWithNatLangFormatting(attrVal)
                    # assert isinstance(resultDict['Result'], (int, basestring, float)), type(resultDict['Result'])

        core = HtmlCore()
        core.begin()
        core.header('Results: ' + analysisName)

        def _produceTable(core, tableDict=None, tableId=None):
            return core.tableFromDictOfDicts(tableDict,
                                             firstColName='Track title',
                                             tableId=tableId,
                                             expandable=True,
                                             visibleRows=20,
                                             presorted=0)

        tableId = 'results_table'
        tableFile = GalaxyRunSpecificFile([tableId, 'table.tsv'], galaxyFn)
        tabularHistElementName = 'Raw results: ' + analysisName

        gsuiteFile = GalaxyRunSpecificFile(
            [tableId, 'input_with_results.gsuite'], galaxyFn)
        GSuiteComposer.composeToFile(gSuite, gsuiteFile.getDiskPath())
        gsuiteHistElementName = \
            getGSuiteHistoryOutputName('result', ', ' + analysisName, choices.gsuite)

        core.tableWithImportButtons(
            tabularFile=True,
            tabularFn=tableFile.getDiskPath(),
            tabularHistElementName=tabularHistElementName,
            gsuiteFile=True,
            gsuiteFn=gsuiteFile.getDiskPath(),
            gsuiteHistElementName=gsuiteHistElementName,
            produceTableCallbackFunc=_produceTable,
            tableDict=tableDict,
            tableId=tableId)
        core.end()
        print core
Example #16
0
 def getOutputName(cls, choices):
     if choices.history:
         from quick.gsuite.GSuiteHbIntegration import getGSuiteHistoryOutputName
         return getGSuiteHistoryOutputName('same', ', subset of tracks',
                                           choices.history)
    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.gsuite.GSuite import GSuite
        from gold.gsuite.GSuiteTrack import GalaxyGSuiteTrack, GSuiteTrack
        from gold.gsuite.GSuiteComposer import composeToFile
        from gold.gsuite.GSuiteFunctions import getTitleWithSuffixReplaced
        from quick.gsuite.GSuiteHbIntegration import \
            writeGSuiteHiddenTrackStorageHtml
        from quick.extra.ProgressViewer import ProgressViewer
        from quick.util.CommonFunctions import ensurePathExists

        gSuite = getGSuiteFromGalaxyTN(choices.history)
        outGSuite = GSuite()
        errorGSuite = GSuite()

        progressViewer = ProgressViewer(
            [('Manipulate tracks', gSuite.numTracks())], galaxyFn)

        hiddenStorageFn = cls.extraGalaxyFn[getGSuiteHistoryOutputName(
            'storage', cls.OUTPUT_DESCRIPTION, choices.history)]

        for track in gSuite.allTracks():
            newSuffix = cls._getSuffix(choices, track)

            fileName = os.path.basename(track.path)
            fileName = changeSuffixIfPresent(fileName,
                                             oldSuffix=track.suffix,
                                             newSuffix=newSuffix)
            title = getTitleWithSuffixReplaced(track.title, newSuffix)

            try:
                if fileName.endswith('.' + newSuffix):
                    uri = GalaxyGSuiteTrack.generateURI(
                        galaxyFn=hiddenStorageFn, extraFileName=fileName)
                else:
                    uri = GalaxyGSuiteTrack.generateURI(
                        galaxyFn=hiddenStorageFn,
                        extraFileName=fileName,
                        suffix=newSuffix)

                gSuiteTrack = GSuiteTrack(uri,
                                          title=title,
                                          genome=track.genome,
                                          attributes=track.attributes)

                trackFn = gSuiteTrack.path
                ensurePathExists(trackFn)
                cls._runOperation(choices, track.path, trackFn)

                outGSuite.addTrack(gSuiteTrack)

            except Exception as e:
                track.comment = 'An error occurred for the following track: ' + str(
                    e).partition('\n')[0]
                errorGSuite.addTrack(track)

            progressViewer.update()

        primaryFn = cls.extraGalaxyFn[getGSuiteHistoryOutputName(
            'primary', cls.OUTPUT_DESCRIPTION, choices.history)]

        composeToFile(outGSuite, primaryFn)

        errorFn = cls.extraGalaxyFn[getGSuiteHistoryOutputName(
            'nomanipulate', datasetInfo=choices.history)]
        composeToFile(errorGSuite, errorFn)

        writeGSuiteHiddenTrackStorageHtml(hiddenStorageFn)
 def getOutputName(cls, choices):
     return getGSuiteHistoryOutputName('progress', cls.OUTPUT_DESCRIPTION,
                                       choices.history)
Example #19
0
    def getOutputName(cls, choices):
        from quick.gsuite.GSuiteHbIntegration import getGSuiteHistoryOutputName

        description = cls._getAttrSelectionDescription(choices)
        return getGSuiteHistoryOutputName('primary', description)
 def getOutputName(cls, choices=None):
     from quick.gsuite.GSuiteHbIntegration import getGSuiteHistoryOutputName
     return getGSuiteHistoryOutputName('primary',
                                       description=cls.GSUITE_DESCRIPTION,
                                       datasetInfo=choices.gsuite)
    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.
        '''

        import gold.gsuite.GSuiteComposer as GSuiteComposer
        from gold.gsuite.GSuite import GSuite
        from gold.gsuite.GSuiteTrack import GSuiteTrack, HbGSuiteTrack
        from gold.origdata.TrackGenomeElementSource import TrackViewListGenomeElementSource
        from gold.origdata.FileFormatComposer import getComposerClsFromFileSuffix
        from quick.multitrack.MultiTrackCommon import getGSuiteFromGalaxyTN
        from quick.application.ExternalTrackManager import ExternalTrackManager
        from quick.application.GalaxyInterface import GalaxyInterface
        from quick.application.UserBinSource import UserBinSource
        from quick.extra.TrackExtractor import TrackExtractor

        genome = choices.genome
        gSuite = getGSuiteFromGalaxyTN(choices.gSuite)

        if choices.withOverlaps == cls.NO_OVERLAPS:
            if choices.trackSource == cls.FROM_HISTORY_TEXT:
                filterTrackName = ExternalTrackManager.getPreProcessedTrackFromGalaxyTN(genome, choices.trackHistory)
            else:
                filterTrackName = choices.track.split(':')
        else:
            if choices.trackSource == cls.FROM_HISTORY_TEXT:
                regSpec = ExternalTrackManager.extractFileSuffixFromGalaxyTN(choices.trackHistory)
                binSpec = ExternalTrackManager.extractFnFromGalaxyTN(choices.trackHistory)
            else:
                regSpec = 'track'
                binSpec = choices.track

            userBinSource = UserBinSource(regSpec, binSpec, genome)

        desc = cls.OUTPUT_GSUITE_DESCRIPTION
        emptyFn = cls.extraGalaxyFn \
            [getGSuiteHistoryOutputName('nointersect', description=desc, datasetInfo=choices.gSuite)]
        primaryFn = cls.extraGalaxyFn \
            [getGSuiteHistoryOutputName('primary', description=desc, datasetInfo=choices.gSuite)]
        errorFn = cls.extraGalaxyFn \
            [getGSuiteHistoryOutputName('nopreprocessed', description=desc, datasetInfo=choices.gSuite)]
        preprocessedFn = cls.extraGalaxyFn \
            [getGSuiteHistoryOutputName('preprocessed', description=desc, datasetInfo=choices.gSuite)]
        hiddenStorageFn = cls.extraGalaxyFn \
            [getGSuiteHistoryOutputName('storage', description=desc, datasetInfo=choices.gSuite)]

        analysisDef = '-> TrackIntersectionStat'
#         analysisDef = '-> TrackIntersectionWithValStat'

        numTracks = gSuite.numTracks()
        progressViewer = ProgressViewer([(cls.PROGRESS_INTERSECT_MSG, numTracks),
                                         (cls.PROGRESS_PREPROCESS_MSG, numTracks)], galaxyFn)
        emptyGSuite = GSuite()
        primaryGSuite = GSuite()

        for track in gSuite.allTracks():
            newSuffix = cls.OUTPUT_TRACKS_SUFFIX
            extraFileName = os.path.sep.join(track.trackName)
            extraFileName = changeSuffixIfPresent(extraFileName, newSuffix=newSuffix)
            title = getTitleWithSuffixReplaced(track.title, newSuffix)

            primaryTrackUri = GalaxyGSuiteTrack.generateURI(
                galaxyFn=hiddenStorageFn, extraFileName=extraFileName,
                suffix=newSuffix if not extraFileName.endswith(newSuffix) else '')
            primaryTrack = GSuiteTrack(primaryTrackUri, title=title,
                                       genome=track.genome, attributes=track.attributes)

            if choices.withOverlaps == cls.NO_OVERLAPS:
                res = GalaxyInterface.runManual([track.trackName, filterTrackName], analysisDef, '*', '*',
                                                 genome=genome, galaxyFn=galaxyFn, username=username)

                trackViewList = [res[key]['Result'] for key in sorted(res.keys())]

                tvGeSource = TrackViewListGenomeElementSource(genome, trackViewList)

                composerCls = getComposerClsFromFileSuffix(cls.OUTPUT_TRACKS_SUFFIX)
                composerCls(tvGeSource).composeToFile(primaryTrack.path)
            else:
                TrackExtractor.extractOneTrackManyRegsToOneFile( \
                    track.trackName, userBinSource, primaryTrack.path, fileFormatName=cls.OUTPUT_TRACKS_SUFFIX, \
                    globalCoords=True, asOriginal=False, allowOverlaps=True)

            # Temporary hack until better solution for empty result tracks have been implemented

            from gold.origdata.GenomeElementSource import GenomeElementSource
            geSource = GenomeElementSource(primaryTrack.path, genome=genome, suffix=cls.OUTPUT_TRACKS_SUFFIX)

            try:
                geSource.parseFirstDataLine()
                primaryGSuite.addTrack(primaryTrack)
            except Exception, e: # Most likely empty file
                primaryTrack.comment = e.message
                emptyGSuite.addTrack(primaryTrack)
                numTracks -= 1
                progressViewer.updateProgressObjectElementCount(
                    cls.PROGRESS_PREPROCESS_MSG, numTracks)
            #

            progressViewer.update()
 def getOutputName(cls, choices):
     return getGSuiteHistoryOutputName('progress', description=cls.OUTPUT_GSUITE_DESCRIPTION,
                                       datasetInfo=choices.gSuite)
 def getOutputName(cls, choices):
     description = cls._getOutputHistoryDescription(choices)
     return getGSuiteHistoryOutputName('progress', description)
Example #24
0
 def getOutputName(cls, choices):
     return getGSuiteHistoryOutputName('progress',
                                       datasetInfo=choices.gsuite)
Example #25
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.gsuite.GSuitePreprocessor import GSuitePreprocessor
        import gold.gsuite.GSuiteComposer as GSuiteComposer
        from quick.gsuite.GSuiteHbIntegration import \
            writeGSuiteHiddenTrackStorageHtml
        from quick.extra.ProgressViewer import ProgressViewer
        from quick.multitrack.MultiTrackCommon import getGSuiteFromGalaxyTN

        inGSuite = getGSuiteFromGalaxyTN(choices.history)
        trackCount = inGSuite.numTracks()

        progressViewer = ProgressViewer(
            [('Download tracks', trackCount)] +
            ([('Preprocess tracks',
               trackCount)] if choices.preProcess == 'Yes' else []), galaxyFn)

        #from gold.gsuite.GSuiteDownloader import GSuiteMultipleGalaxyFnDownloader
        #gSuiteDownloader = GSuiteMultipleGalaxyFnDownloader()
        #outGSuite, errorGSuite = \
        #    gSuiteDownloader.visitAllGSuiteTracksAndReturnOutputAndErrorGSuites(inGSuite, progressViewer, cls.extraGalaxyFn)

        from gold.gsuite.GSuiteDownloader import GSuiteSingleGalaxyFnDownloader
        gSuiteDownloader = GSuiteSingleGalaxyFnDownloader()
        hiddenStorageFn = cls.extraGalaxyFn\
            [getGSuiteHistoryOutputName('storage', datasetInfo=choices.history)]
        outGSuite, errorGSuite = \
            gSuiteDownloader.visitAllGSuiteTracksAndReturnOutputAndErrorGSuites \
                (inGSuite, progressViewer, hiddenStorageFn, [])
        writeGSuiteHiddenTrackStorageHtml(hiddenStorageFn)

        #outGSuite, errorGSuite = \
        #    inGSuite.downloadAllRemoteTracksAsMultipleDatasetsAndReturnOutputAndErrorGSuites(cls.extraGalaxyFn, progressViewer)

        #outGSuite, errorGSuite = \
        #    inGSuite.downloadAllRemoteTracksAsSingleDatasetAndReturnOutputAndErrorGSuites(galaxyFn, ['cell', 'title'], progressViewer=progressViewer)

        errorFn = cls.extraGalaxyFn\
            [getGSuiteHistoryOutputName('nodownload', datasetInfo=choices.history)]
        GSuiteComposer.composeToFile(errorGSuite, errorFn)

        outGSuite.setGenomeOfAllTracks(choices.genome)
        downloadFn = cls.extraGalaxyFn\
            [getGSuiteHistoryOutputName('primary', datasetInfo=choices.history)]
        GSuiteComposer.composeToFile(outGSuite, downloadFn)

        if choices.preProcess == 'Yes':
            progressViewer.updateProgressObjectElementCount(
                'Preprocess tracks', outGSuite.numTracks())

            gSuitePreprocessor = GSuitePreprocessor()
            outGSuite, errorGSuite = gSuitePreprocessor.visitAllGSuiteTracksAndReturnOutputAndErrorGSuites\
                                                        (outGSuite, progressViewer)

            #outGSuite, errorGSuite = outGSuite.preProcessAllLocalTracksAndReturnOutputAndErrorGSuites(progressViewer)

            noPreprocessedFn = cls.extraGalaxyFn\
                [getGSuiteHistoryOutputName('nopreprocessed', datasetInfo=choices.history)]
            GSuiteComposer.composeToFile(errorGSuite, noPreprocessedFn)

            preprocessedFn = cls.extraGalaxyFn\
                [getGSuiteHistoryOutputName('preprocessed', datasetInfo=choices.history)]
            GSuiteComposer.composeToFile(outGSuite, preprocessedFn)
 def getOutputName(cls, choices):
     if choices.gsuite:
         from quick.gsuite.GSuiteHbIntegration import getGSuiteHistoryOutputName
         return getGSuiteHistoryOutputName('same', ', metadata edited',
                                           choices.gsuite)
    def execute(cls, choices, galaxyFn=None, username=''):
        if not choices.source:
            return
        source = choices.source.split('[')[0].strip()
        fileTypes = []
        gsm = TrackGlobalSearchModule(cls.useSqlite)
        desc = choices.subCategory

        if choices.source.find('HyperBrowser') == -1:
            #items = gsm.getItems(choices.search,choices.subCategory)
            # # allFileTypes = [x.split('[')[0] for x,selected in prevChoices.filetype.iteritems()]
            # # fileTypes = [x.split('[')[0] for x,selected in prevChoices.filetype.iteritems() if selected]
            ##allDataTypes = [x.split('[')[0].strip() for x,selected in choices.dataType.iteritems()]
            #dataTypes = [x.split('[')[0].strip() for x,selected in choices.dataType.iteritems() if selected]
            dataTypes = [choices.dataType.split('[')[0].strip()]

            ##Was made to speadup so that there will be no filetype comparisons,
            ##but deactivated for now since there is hardcoded filtering in
            ##prevChoices.fileType
            #if len(allFileTypes) == len(fileTypes):
            #    fileTypes = []

        if 'all tracks' in choices.outputType:
            remoteGSuite = gsm.getGSuite(choices.search,
                                         choices.subCategory,
                                         source,
                                         dataTypes,
                                         filterFileSuffix=True)
        elif choices.outputType == 'Select tracks manually':
            remoteGSuite = gsm.getGSuite(choices.search,choices.subCategory,source,dataTypes,\
                                         filterFileSuffix = True,selectedFileIDs = choices.results)
        elif choices.outputType == 'Select 10 random tracks':
            remoteGSuite = gsm.getRandomGSuite(choices.search,choices.subCategory,source,dataTypes,\
                                               filterFileSuffix = True,count = 10)
        elif choices.outputType == 'Select 50 random tracks':
            remoteGSuite = gsm.getRandomGSuite(choices.search,choices.subCategory,source,dataTypes,\
                                               filterFileSuffix = True,count = 50)

        if choices.downloadAndPreprocess == 'Yes' and choices.source.find(
                'HyperBrowser') == -1:
            trackCount = remoteGSuite.numTracks()
            progressViewer = \
                ProgressViewer([('Download tracks', trackCount),
                                ('Preprocess tracks', trackCount)], galaxyFn)

            #from gold.gsuite.GSuiteDownloader import GSuiteMultipleGalaxyFnDownloader
            #gSuiteDownloader = GSuiteMultipleGalaxyFnDownloader()
            #localGSuite, errorLocalGSuite = \
            #    gSuiteDownloader.visitAllGSuiteTracksAndReturnOutputAndErrorGSuites\
            #        (remoteGSuite, progressViewer, cls.extraGalaxyFn)
            from gold.gsuite.GSuiteDownloader import GSuiteSingleGalaxyFnDownloader
            from quick.gsuite.GSuiteHbIntegration import \
                writeGSuiteHiddenTrackStorageHtml

            gSuiteDownloader = GSuiteSingleGalaxyFnDownloader()
            hiddenStorageFn = cls.extraGalaxyFn[getGSuiteHistoryOutputName(
                'storage', desc)]
            localGSuite, errorLocalGSuite = \
                gSuiteDownloader.visitAllGSuiteTracksAndReturnOutputAndErrorGSuites \
                    (remoteGSuite, progressViewer, hiddenStorageFn, [])
            writeGSuiteHiddenTrackStorageHtml(hiddenStorageFn)

            progressViewer.updateProgressObjectElementCount(
                'Preprocess tracks', localGSuite.numTracks())
            gSuitePreprocessor = GSuitePreprocessor()
            preProcessedGSuite, errorPreProcessGSuite = \
                gSuitePreprocessor.visitAllGSuiteTracksAndReturnOutputAndErrorGSuites\
                    (localGSuite, progressViewer)
            #preProcessedGSuite, errorPreProcessGSuite = localGSuite.preProcessAllLocalTracksAndReturnOutputAndErrorGSuites(progressViewer)
            GSuiteComposer.composeToFile(
                remoteGSuite,
                cls.extraGalaxyFn[getGSuiteHistoryOutputName('remote', desc)])
            GSuiteComposer.composeToFile(
                errorLocalGSuite, cls.extraGalaxyFn[getGSuiteHistoryOutputName(
                    'nodownload', desc)])
            GSuiteComposer.composeToFile(
                localGSuite,
                cls.extraGalaxyFn[getGSuiteHistoryOutputName('primary', desc)])
            GSuiteComposer.composeToFile(
                errorPreProcessGSuite,
                cls.extraGalaxyFn[getGSuiteHistoryOutputName(
                    'nopreprocessed', desc)])
            GSuiteComposer.composeToFile(
                preProcessedGSuite,
                cls.extraGalaxyFn[getGSuiteHistoryOutputName(
                    'preprocessed', desc)])

        else:
            GSuiteComposer.composeToFile(remoteGSuite, galaxyFn)
 def getOutputName(cls, choices):
     if choices.downloadAndPreprocess == 'Yes':  # and choices.source.find('HyperBrowser') == -1:
         return getGSuiteHistoryOutputName('progress', choices.subCategory)
     else:
         return getGSuiteHistoryOutputName('primary', choices.subCategory)
 def getOutputName(cls, choices):
     from quick.gsuite.GSuiteHbIntegration import getGSuiteHistoryOutputName
     return getGSuiteHistoryOutputName('primary', ', tracks exported',
                                       choices.gsuite)