Beispiel #1
0
    def execute(cls, choices, galaxyFn=None, username=''):
        cls._setDebugModeIfSelected(choices, galaxyFn)

        with stdout_redirector(open(galaxyFn, "w", 0)):
            core = HtmlCore()
            core.append(GalaxyInterface.getHtmlBeginForRuns(galaxyFn))
            core.append(
                GalaxyInterface.getHtmlForToggles(withRunDescription=False))
            core.styleInfoBegin(styleClass='debug')
            core.paragraph(
                'GalaxyInterface.startPreProcessing({}, {}, {})'.format(
                    choices.genome, choices.track, username))
            print core

            if choices.parsingError == cls.MOVE_TO_PARSING_ERROR_CHOICE:
                finished = False
                while not finished:
                    DebugConfig.PASS_ON_PREPROCESS_EXCEPTIONS = True
                    try:
                        GalaxyInterface.startPreProcessing(
                            choices.genome, choices.track, username)
                        finished = True
                    except (PreprocessWarning, PreprocessError) as e:
                        print e
                        match = re.search("trackName=\"([^\"]+)\"", str(e))
                        if match:
                            trackName = match.group(1).split(':')
                            PlainMover().parseFiles(choices.genome,
                                                    trackName,
                                                    direction='std_to_error')
            else:  # cls.DO_NOTHING_CHOICE
                GalaxyInterface.startPreProcessing(choices.genome,
                                                   choices.track, username)

            core = HtmlCore()
            core.styleInfoEnd()
            core.script('done = true;')
            core.end()
            print core
Beispiel #2
0
class GtrackSpecParser(object):
    def __init__(self, filPath, outFilePath):
        self.core = HtmlCore()
        self.specStr = open(filPath, 'r').read()
        self.outFilePath = outFilePath
        self.htmlMal = '<html><body>%s</body></html>'
        self.htmlStr = ''
        self.divCounter = 0
        self.fullContentTab = []

    def getContentList(self):
        return self.specStr.split('\n----------------')[2].strip().split('\n')

    def getContentlineSearcStr(self, line):
        anchorIndex = 0
        if line.strip().startswith('*'):
            anchorIndex = 2
            searchStr = line[2:].strip() + '\n----'
        elif len(line.strip()) and line.strip().startswith('-'):
            anchorIndex = line.find('-') + 4
            searchStr = line.strip()[2:].strip() + '\n  ----'
        elif line.strip() != '':
            anchorIndex = 8
            searchStr = line.strip().replace('  ', ' ') + '\n  ----'
        else:
            searchStr = None
        return searchStr, anchorIndex
        #x.  Comments

    def findAll(self, substring, string):
        starts = [
            match.start()
            for match in re.finditer(re.escape(substring), string)
        ]
        return [
            x for i, x in enumerate(starts)
            if i == 0 or i > 0 and x - starts[i - 1] != len(substring)
        ]

    def checkHeader(self, header, contentStr, devNotes=True):
        headerIndex = contentStr.find(header)
        falseHeaderIndex = contentStr.find('"' + header)
        if headerIndex != -1 and not (falseHeaderIndex != -1
                                      and headerIndex == falseHeaderIndex + 1):
            devChunckList = contentStr.split(header)
            resultStr = devChunckList[0]
            for value in devChunckList[1:]:
                resultStr += '''<a onclick ="javascript:ShowHide('HiddenDiv%s')" href="javascript:;" >%s</a>''' % (
                    str(self.divCounter), header)
                dashLine = '-' * len(header)
                if devNotes:
                    dotList = value.split(dashLine)
                    resultStr += '<div class="mid" id="HiddenDiv%s" style="DISPLAY: none" >%s%s%s%s</div>' % (
                        str(self.divCounter), dotList[0], dashLine, dotList[1],
                        dashLine) + dashLine.join(dotList[2:])
                else:
                    lastDashLine = self.findAll('----', value)[-1]
                    if value[lastDashLine - 2:lastDashLine] == '  ':
                        lastDashLine -= 2
                    mainContent = ''.join(value[1:lastDashLine])
                    newHeader = ''.join(value[lastDashLine:])
                    resultStr += '<div class="mid" id="HiddenDiv%s" style="DISPLAY: none" >%s</div>\n  ' % (
                        str(self.divCounter),
                        mainContent) + dashLine + '\n\n' + newHeader
                self.divCounter += 1
            return resultStr
        else:
            return contentStr

    def checkRestrictions(self, contentStr):
        if contentStr.find('- Restrictions') > 0:
            devChunckList = contentStr.split('- Restrictions')
            resultStr = devChunckList[0]
            for value in devChunckList[1:]:
                resultStr += '''- <a onclick ="javascript:ShowHide('HiddenDiv%s')" href="javascript:;" >Restrictions</a>\n''' % str(
                    self.divCounter)
                restrictTab, extraTab = [], []
                valueTab = value.split('\n')

                for index, resVal in enumerate(valueTab):
                    if resVal.strip() == '' or (len(resVal) > 2
                                                and resVal[2].isspace()):
                        restrictTab.append(resVal)
                    else:
                        extraTab = valueTab[index:]
                        break

                for val in restrictTab:
                    if val.strip() == '':
                        restrictTab = restrictTab[1:]
                    else:
                        break

                for val in reversed(restrictTab):
                    if val.strip() == '':
                        restrictTab = restrictTab[:-1]
                    else:
                        break

                resultStr += '<div class="mid" id="HiddenDiv%s" style="DISPLAY: none" >\n%s</div>' % (
                    str(self.divCounter),
                    '\n'.join(restrictTab)) + '\n\n' + '\n'.join(extraTab)
                self.divCounter += 1
            return resultStr
        else:
            return contentStr

    def parseSpecFile(self):
        contentList = self.getContentList()
        self.core.begin()
        self.core.script(
            "function ShowHide(divId)\n{\nif(document.getElementById(divId).style.display == 'none')\n{\ndocument.getElementById(divId).style.display='block';\n}\nelse\n{\ndocument.getElementById(divId).style.display = 'none';\n}\n}\n"
        )
        self.core.append('<pre class="largefont">' +
                         self.specStr.split(contentList[0])[0])
        for i in contentList:
            searchStr, entry = self.getContentlineSearcStr(i)
            self.core.append(i[:entry])
            self.core.link(i[entry:], '#' + searchStr.split('\n')[0])
            self.core.append('\n')

        self.core.append('\n\n\n')
        for index, value in enumerate(contentList):
            print value
            startPoint, entry = self.getContentlineSearcStr(value)
            endPoint, entry = self.getContentlineSearcStr(
                contentList[index +
                            1]) if index + 1 < len(contentList) else (None, 0)
            self.core.anchor('', startPoint.split('\n')[0])
            content = self.specStr[self.specStr.find(
                startPoint):] if not endPoint else self.specStr[
                    self.specStr.find(startPoint):self.specStr.find(endPoint)]
            # content = self.checkHeader('Parser notes:', content, True)
            content = self.checkRestrictions(content)
            self.core.append(content)
        self.core.append('</pre>')
        self.core.end()
        utfil = open(self.outFilePath, 'w')
        utfil.write(str(self.core))