Пример #1
0
    def __init__(self, urlGenome = None, text = None):
        assert urlGenome or text
        xmlDict = xmldict.XMLDict({
                                xmldict.XMLDict.toList : [ 'codonTable', 'acceptedMutations', 'rejectedMutations', 'attempt', 'genes', 'hanReferences', 'groups', 'strokes', 'overlaps', 'segments', 'segment' ],
                                xmldict.XMLDict.ignore : []
                                })
        if urlGenome:
            dictGenome = xmlDict.load(urlGenome)['genome']
        else:
            dictGenome = xmlDict.loads(text)['genome']

        self.author = 'author' in dictGenome and dictGenome['author'] or None
        self.creationDate = 'creationDate' in dictGenome and dictGenome['creationDate'] or None
        self.creationTool = 'creationTool' in dictGenome and dictGenome['creationTool'] or None
        self.creationParameters = 'creationParameters' in dictGenome and dictGenome['creationParameters'] or None

        if 'seed' in dictGenome:
            self.seed = dictGenome['seed'][xmldict.XMLDict.value]
            self.seedID = dictGenome['seed']['processorID']
        else:
            self.seed = None
            self.seedID = None

        self.codonTable = CodonTableElement(dictGenome=dictGenome)
        self.bases = dictGenome['bases'][xmldict.XMLDict.value]

        self.termination = Termination(dictGenome)
        self.statistics = Statistics(dictGenome)
        self.lineage = Lineage(dictGenome)
        self.gene = Gene(dictGenome['genes'][xmldict.XMLDict.children][0][1])
        return
Пример #2
0
    def __init__(self, urlHan):
        xmlDict = xmldict.XMLDict({
            xmldict.XMLDict.toList:
            ['groups', 'strokes', 'forward', 'reverse', 'overlaps']
        })
        dictHan = xmlDict.load(urlHan)['hanDefinition']

        self.uuid = dictHan['uuid']
        self.unicode = dictHan['unicode']

        self.creationDate = 'creationDate' in dictHan and dictHan[
            'creationDate'] or None
        self.creationTool = 'creationTool' in dictHan and dictHan[
            'creationTool'] or None
        self.creationParameters = 'creationParameters' in dictHan and dictHan[
            'creationParameters'] or None

        self.bounds = Rectangle(dictRect=dictHan['bounds'])
        self.length = dictHan['length'][xmldict.XMLDict.value]
        self.minimumStrokeLength = dictHan['minimumStrokeLength'][
            xmldict.XMLDict.value]

        self.aryGroups = [
            HanGroup(dictGroup)
            for tag, dictGroup in dictHan['groups'][xmldict.XMLDict.children]
        ]
        self.aryStrokes = [
            HanStroke(dictStroke)
            for tag, dictStroke in dictHan['strokes'][xmldict.XMLDict.children]
        ]
        self.aryOverlaps = 'overlaps' in dictHan and [
            HanOverlap(dictOverlap) for tag, dictOverlap in dictHan['overlaps']
            [xmldict.XMLDict.children]
        ] or []
        return
Пример #3
0
    def __init__(self, urlCodonTable=None):
        dictCodonTable = None
        if urlCodonTable:
            xmlDict = xmldict.XMLDict({
                                    xmldict.XMLDict.toList : [ 'codonTable' ],
                                    xmldict.XMLDict.ignore : []
                                    })
            dictCodonTable = xmlDict.load(urlCodonTable)['codonTable']

        super(CodonTable, self).__init__(dictCodonTable=dictCodonTable)
        return
Пример #4
0
    def validate(self, urls, grf):
        if self.strNameType == 'asis' and not self.strName:
            raise BiologicError('asis requires specifying a name')
            
        if (grf & self.GENOME) or self.strNameType != 'dir':
            if not self.strGenome:
                raise BiologicError('Required genome was not supplied')
            urls.validate(URLs.GENOME)
            self.urlGenome = pathToURL(makeHanPath(resolvePath(self.strGenome)), urls.urlGenome)
            
        if grf & (self.DATA | self.REPORT):
            if self.strNameType == 'asis' or self.strNameType == 'file':
                self.idGenome = os.path.splitext(os.path.basename(self.urlGenome))[0]
            elif self.strNameType == 'uuid':
                if not Constants.reUUID.match(self.strGenome):
                    xmlDict = XMLDict.XMLDict({ XMLDict.XMLDict.ignore : [ 'seed', 'bases', 'statistics', 'lineage', 'genes' ] })
                    try: self.idGenome = str(xmlDict.load(self.urlGenome)['genome']['uuid']).upper()
                    except LookupError, err: raise BiologicError('Genome (%s) is missing a UUID' % self.urlGenome)
            elif self.strNameType == 'unicode':
                aryParts = os.path.split(self.urlGenome)
                mo = Constants.reBASENAMEUNICODE.match(aryParts[1])
                if mo and mo.groups():
                    self.idGenome = mo.groups()[0]
                else:
                    raise BiologicError('unicode name patterns required a genome file whose name begins with a unicode value')
            
        if grf & self.PLAN or self.fAppendPlan:
            if not self.strPlan:
                raise BiologicError('Required plan was not supplied')
            urls.validate(URLs.PLAN)
            self.urlPlan = pathToURL(resolvePath(self.strPlan), urls.urlPlan)
            self.idPlan = os.path.splitext(os.path.basename(self.urlPlan))[0]

        if grf & self.DATA:
            if not self.strDataPath:
                raise BiologicError('Required datapath was not supplied')
            self.pathData = resolvePath(self.strDataPath)
            if self.strNameType == 'asis':
                self.pathData = os.path.join(self.pathData, self.strName)
            else:
                idGenome = self.fAppendPlan and (self.idGenome + '--' + self.idPlan) or self.idGenome
                self.pathData = os.path.join(self.pathData, self.strName, idGenome)

            # Expand the data path unless expanding reports (since report expansion will set the data path as needed)
            if self.strExpand and not grf & self.REPORT:
                self.urlGenome, self.pathExpandData = self.__expandGenome__(self.pathData, Constants.extXML)
                self.pathData = os.path.join(self.pathData, self.pathExpandData)
                if not self.nFirstPlanTrial:
                    self.nFirstPlanTrial = 1

            self.pathData = os.path.normpath(os.path.normcase(self.pathData))
                
        if grf & self.REPORT:
            if not self.strReportPath:
                raise BiologicError('Required reportpath was not supplied')
            self.pathReport = resolvePath(self.strReportPath)
            if self.strNameType == 'asis':
                self.pathReport = os.path.join(self.pathReport, self.strName)
            elif self.strNameType == 'dir':
                strHead, strTail = os.path.split(self.strDataPath)
                if not strTail:
                    strHead, strTail = os.path.split(strHead)
                strTail, strExt = os.path.splitext(strTail)
                self.pathReport = os.path.join(self.pathReport, strTail)
            else:
                idGenome = self.fAppendPlan and (self.idGenome + '--' + self.idPlan) or self.idGenome
                self.pathReport = os.path.join(self.pathReport, self.strName, idGenome)

            if self.strNameType != 'dir' and self.strExpand:
                strNotUsed, self.pathExpandReport = self.__expandGenome__(self.pathReport, Constants.extXML)
                self.pathReport = os.path.join(self.pathReport, self.pathExpandReport)
                
                # Map the report path to the data path (since the data may have already been expanded once or more)
                self.pathData = os.path.normpath(os.path.normcase(os.path.join(self.pathData, self.pathExpandReport)))

            self.pathReport = os.path.normpath(os.path.normcase(self.pathReport))