Example #1
0
def buildHan(uchHan):
    Common.say('Creating Han Definition file for ' + uchHan)

    hcf = Genome.HCF(Common.pathToURL(Common.makeHanPath(uchHan + Common.Constants.extHCF), Globals.urlHan))
    
    aryGroups = [ _HAN_GROUP % (str(hcfG.bounds), hcfG.length, hcfG.ptCenter.x, hcfG.ptCenter.y,
                            ' '.join([ str(i+1) for i in hcfG.containedStrokes])) for hcfG in hcf.aryGroups ]
    aryStrokes = [ _HAN_STROKE % (str(hcfS.bounds),
                                hcfS.length,
                                '\n'.join([ _HAN_POINT % (ptd.x, ptd.y, ptd.distance) for ptd in hcfS.aryPointsForward]),
                                '\n'.join([ _HAN_POINT % (ptd.x, ptd.y, ptd.distance) for ptd in hcfS.aryPointsReverse]) ) for hcfS in hcf.aryStrokes ]
    aryOverlaps = [ _HAN_OVERLAP % (hcfO.firstStroke, hcfO.secondStroke, hcfO.fRequired and 'true' or 'false') for hcfO in hcf.aryOverlaps ]
    strHan = _HAN_DEFINITION % (str(uuid.uuid4()).upper(), hcf.unicode, datetime.datetime.utcnow().isoformat(), _NAME,
                                str(hcf.bounds), hcf.length, hcf.minimumStrokeLength,
                                '\n'.join(aryGroups),
                                '\n'.join(aryStrokes),
                                aryOverlaps and ('<overlaps>%s</overlaps>' % '\n'.join(aryOverlaps)) or '')
                                
    strPath = Common.resolvePath(os.path.join(Globals.strArchetypePath, Common.makeHanPath(hcf.unicode + Common.Constants.extHan)))
    strDir = os.path.dirname(strPath)
    if not os.path.exists(strDir):
        try: os.makedirs(os.path.dirname(strPath))
        except OSError, err: raise Common.BiologicError('Unable to create %s - %s' % (strDir, str(err)))

    try:
        fileHan = os.open(strPath, os.O_CREAT | os.O_TRUNC | os.O_WRONLY, 0664)
        os.write(fileHan, strHan)
    except IOError, err: raise Common.BiologicError('Unable to create %s - %s' % (strPath, str(err)))
    os.close(fileHan)
    
    Common.say('Han definition written to ' + strPath)
    return
Example #2
0
def loadHan(strUnicode):
    urlHan = Common.pathToURL(Common.makeHanPath(strUnicode + Common.Constants.extHan), Globals.urlHan)
    try: han = Genome.Han(urlHan)
    except LookupError, err: raise Common.BiologicError('%s is missing one or more required elements or attributes - %s' % (urlHan, str(err)))
    except OSError, err: raise Common.BiologicError('Unable to open URL %s - %s' % (urlHan, str(err)))
    except urllib2.URLError, err: raise Common.BiologicError('Unable to open URL %s - %s' % (urlHan, str(err)))
    return han
Example #3
0
        if option in ('-v', '--version'):
            Globals.fVersion = True

        if option in ('-h', '--help'):
            raise Usage('')

    try:
        Globals.urls.validate(Common.URLs.HAN | Common.URLs.SCHEMA)
        Globals.names.validate(
            Globals.urls,
            Common.Names.DATA | Common.Names.GENOME | Common.Names.PLAN)
    except Common.BiologicError, err:
        raise Usage(str(err))

    if Globals.urlGlobals:
        Globals.urlGlobals = Common.pathToURL(Globals.urlGlobals,
                                              Globals.urls.urlPlan)

    Common.replacePath(Globals.names.pathData)

    if Globals.aryLog[2]:
        if not os.path.isabs(Globals.aryLog[2]):
            Globals.aryLog[2] = os.path.abspath(
                os.path.join(Globals.names.pathData, Globals.aryLog[2]))
        Globals.aryLog[2] = os.path.normpath(
            os.path.normcase(Globals.aryLog[2]))


#==============================================================================
# Main
#==============================================================================
def main(argv=None):
Example #4
0
            Common.Globals.fQuiet = True

        if option in ('-v', '--version'):
            Globals.fVersion = True

        if option in ('-h', '--help'):
            raise Usage('')

    try:
        Globals.urls.validate(Common.URLs.HAN | Common.URLs.SCHEMA)
        Globals.names.validate(Globals.urls, Common.Names.DATA | Common.Names.GENOME | Common.Names.PLAN)
    except Common.BiologicError, err:
        raise Usage(str(err))

    if Globals.urlGlobals:
        Globals.urlGlobals = Common.pathToURL(Globals.urlGlobals, Globals.urls.urlPlan)

    Common.replacePath(Globals.names.pathData)

    if Globals.aryLog[2]:
        if not os.path.isabs(Globals.aryLog[2]):
            Globals.aryLog[2] = os.path.abspath(os.path.join(Globals.names.pathData, Globals.aryLog[2]))
        Globals.aryLog[2] = os.path.normpath(os.path.normcase(Globals.aryLog[2]))
        

        
#==============================================================================
# Main
#==============================================================================
def main(argv=None):
    try:
Example #5
0
        if not os.path.exists(Globals.strArchetypePath):
            try: os.makedirs(Globals.strArchetypePath)
            except OSError: raise Usage('Unable to create ' + Globals.strArchetypePath)
        
    if len(Globals.aryGenes) > 0 and not Globals.strGenePath:
        raise Usage('Required gene output path was not specified')

    if len(Globals.aryGenes) > 0:
        Globals.strGenePath = Common.resolvePath(Globals.strGenePath)
        if not os.path.exists(Globals.strGenePath):
            try: os.makedirs(Globals.strGenePath)
            except OSError: raise Usage('Unable to create ' + Globals.strGenePath)
        
    if not Globals.urlHan:
        raise Usage('Required Han URL was not specified')
    Globals.urlHan = Common.pathToURL(Globals.urlHan, Common.Constants.schemeFile)
    
#------------------------------------------------------------------------------
# Function: loadHan
# 
#------------------------------------------------------------------------------
def loadHan(strUnicode):
    urlHan = Common.pathToURL(Common.makeHanPath(strUnicode + Common.Constants.extHan), Globals.urlHan)
    try: han = Genome.Han(urlHan)
    except LookupError, err: raise Common.BiologicError('%s is missing one or more required elements or attributes - %s' % (urlHan, str(err)))
    except OSError, err: raise Common.BiologicError('Unable to open URL %s - %s' % (urlHan, str(err)))
    except urllib2.URLError, err: raise Common.BiologicError('Unable to open URL %s - %s' % (urlHan, str(err)))
    return han

#==============================================================================
# Main Routines
Example #6
0
            if len(aryArgs) > 1 and aryArgs[1]:
                Globals.urlCodonTableBase = aryArgs[1]

        if option in ('-a', '--author'):
            Globals.strAuthor = value

        if option in ('-q', '--quiet'):
            Common.Globals.fQuiet = True

        if option in ('-h', '--help'):
            raise Usage('')

    if not Globals.cmd:
        raise Usage('create, validate, or translate are required')

    Globals.urlGenomeBase = Common.pathToURL(Globals.urlGenomeBase,
                                             Common.Constants.schemeFile)
    if Globals.urlGenomeBase[len(Globals.urlGenomeBase) -
                             1] <> Common.Constants.urlSeparator:
        Globals.urlGenomeBase += Common.Constants.urlSeparator

    Globals.urlCodonTableBase = Common.pathToURL(Globals.urlCodonTableBase,
                                                 Common.Constants.schemeFile)
    if Globals.urlCodonTableBase[len(Globals.urlCodonTableBase) -
                                 1] <> Common.Constants.urlSeparator:
        Globals.urlCodonTableBase += Common.Constants.urlSeparator

    if Globals.cmd <> Constants.cmdTranslate and Globals.strGenome and Globals.strCodonTable:
        raise Usage(
            '%s takes either the genome or codon table as its source - not both'
            % (Globals.cmd == Constants.cmdCreate and 'create' or 'validate'))
    if Globals.cmd == Constants.cmdValidate and not Globals.strGenome and not Globals.strCodonTable:
Example #7
0
            if len(aryArgs) > 1 and aryArgs[1]:
                Globals.urlCodonTableBase = aryArgs[1]
        
        if option in ('-a', '--author'):
            Globals.strAuthor = value

        if option in ('-q', '--quiet'):
            Common.Globals.fQuiet = True

        if option in ('-h', '--help'):
            raise Usage('')

    if not Globals.cmd:
        raise Usage('create, validate, or translate are required')

    Globals.urlGenomeBase = Common.pathToURL(Globals.urlGenomeBase, Common.Constants.schemeFile)
    if Globals.urlGenomeBase[len(Globals.urlGenomeBase)-1] <> Common.Constants.urlSeparator:
        Globals.urlGenomeBase += Common.Constants.urlSeparator

    Globals.urlCodonTableBase = Common.pathToURL(Globals.urlCodonTableBase, Common.Constants.schemeFile)
    if Globals.urlCodonTableBase[len(Globals.urlCodonTableBase)-1] <> Common.Constants.urlSeparator:
        Globals.urlCodonTableBase += Common.Constants.urlSeparator

    if Globals.cmd <> Constants.cmdTranslate and Globals.strGenome and Globals.strCodonTable:
        raise Usage('%s takes either the genome or codon table as its source - not both' % (Globals.cmd == Constants.cmdCreate and 'create' or 'validate'))
    if Globals.cmd == Constants.cmdValidate and not Globals.strGenome and not Globals.strCodonTable:
        raise Usage('validate takes either the genome or codon table as its source')
    if Globals.cmd == Constants.cmdTranslate and (not Globals.strGenome or not Globals.strCodonTable):
        raise Usage('translate requires both the genome to translate and the codon table to use')
        
    if Globals.cmd <> Constants.cmdValidate: