Esempio n. 1
0
    def getRevEngBatchLine(analysisDef, trackNames, cleanedTrackNames, regSpec,
                           binSpec, genome, **kwArgs):
        #analysisDef is assumed to be unquoted

        #if this is to work, must check explicitly against special keywords  in regSpec (or check that regSpec is a valid region that is to have region..)...
        #if not genome in regSpec:
        #    regSpec = genome+':'+regSpec
        try:
            if DebugConfig.VERBOSE:
                logMessage('getting RevEngBatchLine:')
            #analysisDef =analysisDef.replace('%20PointCountInSegsPvalStat%2C','') #REMOVE
            #print 'NOWAG: ',analysisDef

            analysis = Analysis(analysisDef, genome, cleanedTrackNames[0],
                                cleanedTrackNames[1], **kwArgs)

            #assert unquote(regSpec) == regSpec
            assert unquote(
                binSpec
            ) == binSpec  #To assure that unquote can be safely applied to binSpec without any consequences (we don't want to always quote, but still want the possibility to use quoted history track names)
            quotedTrackName1 = (':'.join(
                [quote(x, safe='') for x in trackNames[0]]))
            quotedTrackName2 = (':'.join([
                quote(x, safe='') for x in trackNames[1]
            ])) if trackNames[1] is not None else 'None'
            intensityChoice = analysis.getChoice('trackNameIntensity')
            if intensityChoice:
                quotedIntensityTrackName = quote(intensityChoice, safe='^|')
                analysis.changeChoices('trackNameIntensity',
                                       [(quotedIntensityTrackName, ) * 2])

            stat = analysis.getStat()
            if stat is None:
                return 'No corr batch line, as no valid statistic was found.. '
            #print 'CAME HERE'
            statClassName = stat.__name__
            #fixme: Add space, but this is not checked in batchrunner...
            params = ','.join(['='.join(choicePair) for choicePair in analysis.getAllChoices(filterByActivation=True).items() \
                                 if choicePair[0] not in ['H0','H1_more','H1_less','H1_different','H1_ha1','H1_ha2','H1_ha3','H1_ha4','H1_ha5'] ])
            statText = statClassName + '(' + params + ')'

            batchElements = [
                genome, regSpec, binSpec, quotedTrackName1, quotedTrackName2,
                statText
            ]
            #batchElements = [el.replace(BATCH_COL_SEPARATOR, '\\' + BATCH_COL_SEPARATOR) for el in batchElements]
            #batchElements = [quote(el, safe='') for el in batchElements]
            oneLineBatch = BATCH_COL_SEPARATOR.join(batchElements)

            #return oneLineBatch
            #Under construction...:
            from collections import OrderedDict
            #batchVariables = OrderedDict([('@GENOME',genome), ('@REGION',regSpec), ('@BINNING',binSpec), ('@TN1',tn1), ('@TN2',tn2), ('@ANALYSIS',statText)])
            batchVariables = OrderedDict([('@REGION', regSpec),
                                          ('@BINNING', binSpec),
                                          ('@TN1', quotedTrackName1),
                                          ('@TN2', quotedTrackName2),
                                          ('@ANALYSIS', statText)])
            batchComposition = BATCH_COL_SEPARATOR.join([genome] +
                                                        batchVariables.keys())
            fullBatchList = [
                '='.join(assignment) for assignment in batchVariables.items()
            ] + [batchComposition]
            fullBatch = '<br>'.join(fullBatchList)

            batchLinkDef = '<a href="%s/hyper?mako=generictool&tool_id=hb_batch_run_tool&command=%s&dbkey=%s">%s</a>'
            oneLineBatchLink = batchLinkDef % (URL_PREFIX, quote(oneLineBatch),
                                               genome, 'single line version')
            fullBatchLink = batchLinkDef % (URL_PREFIX,
                                            quote('\n'.join(fullBatchList)),
                                            genome, 'variable based version')

            #return oneLineBatch + '<br><br>or corresponding spec using variable assignment:<br><br>' + fullBatch + '<br><br>Execute batchline in ' \
            #+ oneLineBatchLink + ' / ' + fullBatchLink
            return oneLineBatch + '<br><br>Execute batchline in ' + oneLineBatchLink + ' / ' + fullBatchLink

        except Exception, e:
            #raise
            logException(e, logging.WARNING,
                         'Could not generate corresponding batch line: ')
            #if DebugConfig.VERBOSE:
            logMessage('analysis, genome, trackName1, trackName2: \n' +
                       str([analysis, genome, trackNames[0], trackNames[1]]))
            return 'Warning: Could not generate corresponding batch line.'