Example #1
0
def main(argv=None):
    try:
        getArguments()

        if Globals.urlGenome:
            Common.say('Genome     : %s' % Globals.urlGenome)
        if Globals.urlCodonTable:
            Common.say('Codon Table: %s' % Globals.urlCodonTable)
        if Globals.pathOutput:
            Common.say('Output File: %s' % Globals.pathOutput)

        if Globals.urlGenome:
            Globals.genome = Genome.Genome(Globals.urlGenome)

        if Globals.urlCodonTable:
            Globals.codonTable = Genome.CodonTable(Globals.urlCodonTable)
        elif Globals.urlGenome and Globals.cmd <> Constants.cmdTranslate:
            Globals.codonTable = Globals.genome.codonTable

        if Globals.cmd == Constants.cmdCreate:
            createTable()

        elif Globals.cmd == Constants.cmdValidate:
            validateTable()

        elif Globals.cmd == Constants.cmdTranslate:
            translateGenome()

        return 0

    except Usage, err:
        Common.sayError(err)
        return 0
Example #2
0
def main(argv=None):
    try:
        getArguments()

        if Globals.urlGenome:
            Common.say('Genome     : %s' % Globals.urlGenome)
        if Globals.urlCodonTable:
            Common.say('Codon Table: %s' % Globals.urlCodonTable)
        if Globals.pathOutput:
            Common.say('Output File: %s' % Globals.pathOutput)

        if Globals.urlGenome:
            Globals.genome = Genome.Genome(Globals.urlGenome)
        
        if Globals.urlCodonTable:
            Globals.codonTable = Genome.CodonTable(Globals.urlCodonTable)
        elif Globals.urlGenome and Globals.cmd <> Constants.cmdTranslate:
            Globals.codonTable = Globals.genome.codonTable

        if Globals.cmd == Constants.cmdCreate:
            createTable()
            
        elif Globals.cmd == Constants.cmdValidate:
            validateTable()
            
        elif Globals.cmd == Constants.cmdTranslate:
            translateGenome()

        return 0
        
    except Usage, err:
        Common.sayError(err)
        return 0
Example #3
0
def main(argv=None):
    try:
        getArguments()
        doBackup()
        
    except Common.BiologicError, err:
        Common.sayError(str(err))
        return 2
Example #4
0
def main(argv=None):
    try:
        getArguments()
        doBackup()

    except Common.BiologicError, err:
        Common.sayError(str(err))
        return 2
Example #5
0
def validateCoherence(arySegments):
    # Collapse all segments into a single list and measure coherence
    aryVectors = [ i for f, ary in arySegments for i in ary ]
    aryCoherence = [ 0 for i in xrange(len(aryVectors)) ]
    for i in xrange(2, len(aryVectors)):
        if Codons.isCoherent([ aryVectors[i-2], aryVectors[i-1], aryVectors[i-0] ]):
            aryCoherence[i-2] += 1
            aryCoherence[i-1] += 1
            aryCoherence[i-0] += 1
            
    # Divide measured coherence into lists matching the original segments
    for i in xrange(len(arySegments)):
        aryCoherence[i:i] = [ aryCoherence[i:i+len(arySegments[i][1]) ] ]
        aryCoherence[i+1:i+1+len(arySegments[i][1])] = []

    # Check the expected coherence of each segment against that measured
    for i in xrange(len(arySegments)):
        fCoherent, aryVectors = arySegments[i]
        if (fCoherent and aryCoherence[i].count(0)) or (not fCoherent and (aryCoherence[i].count(0) != len(aryCoherence[i]))):
            if i > 0:
                fC, aryV = arySegments[i-1]
                Common.sayError('Coherent(%c) %d - %s' % (fC and 'T' or 'F', len(aryV), ' '.join([ Codons.Vectors.toName(id) for id in aryV ])))
            Common.sayError('Coherent(%c) %d - %s' % (fCoherent and 'T' or 'F', len(aryVectors), ' '.join([ Codons.Vectors.toName(id) for id in aryVectors ])))
            Common.sayError('                - %s' % ' '.join([ ' %d ' % j for j in aryCoherence[i] ]))
            if i < len(arySegments)-1:
                fC, aryV = arySegments[i+1]
                Common.sayError('Coherent(%c) %d - %s' % (fC and 'T' or 'F', len(aryV), ' '.join([ Codons.Vectors.toName(id) for id in aryV ])))
            raise Common.BiologicError('Failed to create a gene with proper coherence - segment %d should be %s but has %s vectors' % (i+1,
                                                                                                                                fCoherent and 'Coherent' or 'Incoherent',
                                                                                                                                fCoherent and 'Incoherent' or 'Coherent'))
Example #6
0
def main(argv=None):
    try:
        getArguments()
        
        if Globals.aryXgridJob:
            queryXgrid()
        
        if Globals.fRunExec:
            os.environ['STYLUS_EXECARGS'] = Common.readEnvironment('$STYLUS_EXECARGS') + ' ' + ' '.join(Globals.aryArgs)
            spawnStylus(_SCRIPT_EXEC, os.environ)
            
        if Globals.fRunReport:
            os.environ['STYLUS_RPTARGS'] = Common.readEnvironment('$STYLUS_RPTARGS') + ' ' + ' '.join(Globals.aryArgs)
            spawnStylus(_SCRIPT_REPORT, os.environ)

    except Common.BiologicError, err:
        Common.sayError(str(err))
        return 2
Example #7
0
def main(argv=None):
    try:
        getArguments()

        if Globals.aryXgridJob:
            queryXgrid()

        if Globals.fRunExec:
            os.environ['STYLUS_EXECARGS'] = Common.readEnvironment(
                '$STYLUS_EXECARGS') + ' ' + ' '.join(Globals.aryArgs)
            spawnStylus(_SCRIPT_EXEC, os.environ)

        if Globals.fRunReport:
            os.environ['STYLUS_RPTARGS'] = Common.readEnvironment(
                '$STYLUS_RPTARGS') + ' ' + ' '.join(Globals.aryArgs)
            spawnStylus(_SCRIPT_REPORT, os.environ)

    except Common.BiologicError, err:
        Common.sayError(str(err))
        return 2
Example #8
0
def main(argv=None):
    try:
        Globals.fInteractive = True
        Common.Globals.fQuiet = False

        setGlobals(sys.argv[1:])

        if Globals.fBuildArchetype:
            Common.say('Archetypes Directory: %s' % Globals.strArchetypePath)
        if len(Globals.aryGenes) > 0:
            Common.say('Gene Directory      : %s' % Globals.strGenePath)
        Common.say('Han URL             : %s' % Globals.urlHan)
    
        if Globals.fBuildArchetype:
            buildHan(Globals.uchHan)

        if Globals.aryGenes:
            buildGenes(Globals.uchHan, Globals.aryGenes)

        return 0

    except Common.BiologicError, err:
        Common.sayError(err.msg)
        return 2
Example #9
0
def main(argv=None):
    try:
        nCompletionCode = 0

        getArguments()

        Common.say('Data Directory: %s' % Globals.names.pathData)
        if Globals.urlGlobals:
            Common.say('Globals URL   : %s' % Globals.urlGlobals)
        Common.say('Genome URL    : %s' % Globals.names.urlGenome)
        Common.say('Plan URL      : %s' % Globals.names.urlPlan)
        Common.say('Han URL       : %s' % Globals.urls.urlHan)
        Common.say('Schema URL    : %s' % Globals.urls.urlSchema)

        if Globals.aryLog[2] or Globals.aryLog[3] == 'silent':
            os.close(_FD_STDERR)
            if Globals.aryLog[3] != 'silent':
                Common.redirectStderr(Globals.aryLog[2])

        if Globals.fVersion:
            Common.say('Version       : %s' % Stylus.getVersion())

        strGenome = Common.readFile(Globals.names.urlGenome)
        strPlan = Common.readFile(Globals.names.urlPlan)
        strGlobals = Globals.urlGlobals and Common.readFile(
            Globals.urlGlobals) or ''

        if Globals.aryTrace:
            Stylus.setLogLevel(Globals.aryLog[0], 'trace',
                               Globals.aryLog[3] == 'echo', Globals.aryLog[4])
            rc = Stylus.setTrace(Globals.aryTrace[0], Globals.aryTrace[1],
                                 Globals.aryTrace[2], Globals.aryTrace[3],
                                 Globals.aryTrace[4])
            if rc:
                raise StylusError(rc)

        if Globals.aryLog and not Globals.aryTrace:
            rc = Stylus.setLogLevel(Globals.aryLog[0], Globals.aryLog[1],
                                    Globals.aryLog[3] == 'echo',
                                    Globals.aryLog[4])
            if rc:
                raise StylusError(rc)

        rc = Stylus.setScope(Globals.urls.urlHan, Globals.urls.urlSchema)
        if rc:
            raise StylusError(rc)

        rc = Stylus.setRecordRate(Globals.aryRecord[0], Globals.aryRecord[1],
                                  Globals.names.pathData, Globals.aryRecord[2])
        if rc:
            raise StylusError(rc)

        if strGlobals:
            rc = Stylus.setGlobals(strGlobals)
            if rc:
                raise StylusError(rc)

        rc = Stylus.setGenome(strGenome, Globals.strAuthor)
        if rc:
            raise StylusError(rc)

        tStart = time.clock()
        rc = Stylus.executePlan(strPlan, Globals.names.nFirstPlanTrial,
                                Globals.names.cPlanTrialsToExecute)
        tEnd = time.clock()
        if Globals.aryStatistics and Globals.aryStatistics[1]:
            statistics = Stylus.getStatistics()
            Common.say(
                'Plan executed %d trials in %f seconds' %
                ((statistics._iTrialCurrent - statistics._iTrialInitial),
                 (tEnd - tStart)))
        if rc != Stylus.ST_RCSUCCESS:
            if not Stylus.errorIsType(rc, Stylus.ST_INFOTYPE):
                raise StylusError(rc)
            else:
                Common.say('Plan terminated - %s' % stylusError(rc))
                nCompletionCode = 1

        if Globals.aryStatistics and len(
                Globals.aryStatistics
        ) >= 1 and Globals.aryStatistics[0] != "none":
            statistics = Stylus.getStatistics()
            Common.say(
                'Statistics for %d trials (%d to %d)' %
                ((statistics._iTrialCurrent - statistics._iTrialInitial),
                 statistics._iTrialInitial, statistics._iTrialCurrent))
            if Globals.aryStatistics[0] == "summary":
                Common.say(
                    '    Fitness: %0.15f - rollbacks(%d) silent(%d) changes(%d) inserted(%d) deleted(%d)'
                    %
                    (statistics._nFitness, statistics._cTotalRollbacks,
                     statistics._cSilent, statistics._cbBasesChanged,
                     statistics._cbBasesInserted, statistics._cbBasesDeleted))
            else:
                Common.say(
                    '    Fitness: current(%0.15f) max(%0.15f in trial %d) min(%0.15f in trial %d)'
                    % (statistics._nFitness, statistics._tfMax._nValue,
                       statistics._tfMax._iTrial, statistics._tfMin._nValue,
                       statistics._tfMin._iTrial))
                Common.say(
                    '    Score: current(%0.15f) max(%0.15f in trial %d) min(%0.15f in trial %d)'
                    % (statistics._nScore, statistics._tsMax._nValue,
                       statistics._tsMax._iTrial, statistics._tsMin._nValue,
                       statistics._tsMin._iTrial))
                Common.say(
                    '    Size: current(%d) max(%d in trial %d) min(%d in trial  %d)'
                    % (statistics._cbBases, statistics._tzMax._cbBases,
                       statistics._tzMax._iTrial, statistics._tzMin._cbBases,
                       statistics._tzMin._iTrial))
                Common.say(
                    '    Rollbacks: total(%d) current(%d) max(%d in trial %d) min(%d in trial %d)'
                    %
                    (statistics._cTotalRollbacks, statistics._cRollbacks,
                     statistics._trMax._cRollbacks, statistics._trMax._iTrial,
                     statistics._trMin._cRollbacks, statistics._trMin._iTrial))
                Common.say(
                    '    Mutations: silent(%d) attempts(%d) accepted(%d) changed(%d) inserted(%d) deleted(%d)'
                    %
                    (statistics._cSilent, statistics._cAttempted,
                     statistics._cAccepted, statistics._cbBasesChanged,
                     statistics._cbBasesInserted, statistics._cbBasesDeleted))
                if statistics._atChanged._cAttempted:
                    Common.say(
                        '      Changed: attempted(%d) accepted(%d) bases-affected(%d)'
                        % (statistics._atChanged._cAttempted,
                           statistics._atChanged._cAccepted,
                           statistics._atChanged._cbBases))
                if statistics._atCopied._cAttempted:
                    Common.say(
                        '      Copied: attempted(%d) accepted(%d) bases-affected(%d)'
                        % (statistics._atCopied._cAttempted,
                           statistics._atCopied._cAccepted,
                           statistics._atCopied._cbBases))
                if statistics._atDeleted._cAttempted:
                    Common.say(
                        '      Deleted: attempted(%d) accepted(%d) bases-affected(%d)'
                        % (statistics._atDeleted._cAttempted,
                           statistics._atDeleted._cAccepted,
                           statistics._atDeleted._cbBases))
                if statistics._atInserted._cAttempted:
                    Common.say(
                        '      Inserted: attempted(%d) accepted(%d) bases-affected(%d)'
                        % (statistics._atInserted._cAttempted,
                           statistics._atInserted._cAccepted,
                           statistics._atInserted._cbBases))
                if statistics._atTransposed._cAttempted:
                    Common.say(
                        '      Transposed: attempted(%d) accepted(%d) bases-affected(%d)'
                        % (statistics._atTransposed._cAttempted,
                           statistics._atTransposed._cAccepted,
                           statistics._atTransposed._cbBases))

        return nCompletionCode

    except Usage, err:
        Common.sayError(err)
        return 0
Example #10
0
                        '      Deleted: attempted(%d) accepted(%d) bases-affected(%d)'
                        % (statistics._atDeleted._cAttempted,
                           statistics._atDeleted._cAccepted,
                           statistics._atDeleted._cbBases))
                if statistics._atInserted._cAttempted:
                    Common.say(
                        '      Inserted: attempted(%d) accepted(%d) bases-affected(%d)'
                        % (statistics._atInserted._cAttempted,
                           statistics._atInserted._cAccepted,
                           statistics._atInserted._cbBases))
                if statistics._atTransposed._cAttempted:
                    Common.say(
                        '      Transposed: attempted(%d) accepted(%d) bases-affected(%d)'
                        % (statistics._atTransposed._cAttempted,
                           statistics._atTransposed._cAccepted,
                           statistics._atTransposed._cbBases))

        return nCompletionCode

    except Usage, err:
        Common.sayError(err)
        return 0

    except Common.BiologicError, err:
        Common.sayError(str(err))
        return 2


if __name__ == "__main__":
    sys.exit(main())
Example #11
0
def main(argv=None):
    try:
        nCompletionCode = 0

        getArguments()
        
        Common.say('Data Directory: %s' % Globals.names.pathData)
        if Globals.urlGlobals:
            Common.say('Globals URL   : %s' % Globals.urlGlobals)
        Common.say('Genome URL    : %s' % Globals.names.urlGenome)
        Common.say('Plan URL      : %s' % Globals.names.urlPlan)
        Common.say('Han URL       : %s' % Globals.urls.urlHan)
        Common.say('Schema URL    : %s' % Globals.urls.urlSchema)
        
        if Globals.aryLog[2] or Globals.aryLog[3] == 'silent':
            os.close(_FD_STDERR)
            if Globals.aryLog[3] != 'silent':
                Common.redirectStderr(Globals.aryLog[2])

        if Globals.fVersion:
            Common.say('Version       : %s' % Stylus.getVersion())

        strGenome = Common.readFile(Globals.names.urlGenome)
        strPlan = Common.readFile(Globals.names.urlPlan)
        strGlobals = Globals.urlGlobals and Common.readFile(Globals.urlGlobals) or ''
    
        if Globals.aryTrace:
            Stylus.setLogLevel(Globals.aryLog[0], 'trace', Globals.aryLog[3] == 'echo', Globals.aryLog[4])
            rc = Stylus.setTrace(Globals.aryTrace[0], Globals.aryTrace[1], Globals.aryTrace[2], Globals.aryTrace[3], Globals.aryTrace[4])
            if rc:
                raise StylusError(rc)

        if Globals.aryLog and not Globals.aryTrace:
            rc = Stylus.setLogLevel(Globals.aryLog[0], Globals.aryLog[1], Globals.aryLog[3] == 'echo', Globals.aryLog[4])
            if rc:
                raise StylusError(rc)

        rc = Stylus.setScope(Globals.urls.urlHan, Globals.urls.urlSchema)
        if rc:
            raise StylusError(rc)
            
        rc = Stylus.setRecordRate(Globals.aryRecord[0], Globals.aryRecord[1], Globals.names.pathData, Globals.aryRecord[2])
        if rc:
            raise StylusError(rc)
            
        if strGlobals:
            rc = Stylus.setGlobals(strGlobals)
            if rc:
                raise StylusError(rc)
            
        rc = Stylus.setGenome(strGenome, Globals.strAuthor)
        if rc:
            raise StylusError(rc)

        tStart = time.clock()
        rc = Stylus.executePlan(strPlan, Globals.names.nFirstPlanTrial, Globals.names.cPlanTrialsToExecute)
        tEnd = time.clock()
        if Globals.aryStatistics and Globals.aryStatistics[1]:
            statistics = Stylus.getStatistics()
            Common.say('Plan executed %d trials in %f seconds' % ((statistics._iTrialCurrent-statistics._iTrialInitial), (tEnd - tStart)))
        if rc != Stylus.ST_RCSUCCESS:
            if not Stylus.errorIsType(rc, Stylus.ST_INFOTYPE):
                raise StylusError(rc)
            else:
                Common.say('Plan terminated - %s' % stylusError(rc))
                nCompletionCode = 1
            
        if Globals.aryStatistics and len(Globals.aryStatistics) >= 1 and Globals.aryStatistics[0] != "none":
            statistics = Stylus.getStatistics()
            Common.say('Statistics for %d trials (%d to %d)' % ((statistics._iTrialCurrent-statistics._iTrialInitial), statistics._iTrialInitial, statistics._iTrialCurrent))
            if Globals.aryStatistics[0] == "summary":
                Common.say('    Fitness: %0.15f - rollbacks(%d) silent(%d) changes(%d) inserted(%d) deleted(%d)' %
                        (statistics._nFitness, statistics._cTotalRollbacks, statistics._cSilent, statistics._cbBasesChanged, statistics._cbBasesInserted, statistics._cbBasesDeleted))
            else:
                Common.say('    Fitness: current(%0.15f) max(%0.15f in trial %d) min(%0.15f in trial %d)' %
                        (statistics._nFitness, statistics._tfMax._nValue, statistics._tfMax._iTrial, statistics._tfMin._nValue, statistics._tfMin._iTrial))
                Common.say('    Score: current(%0.15f) max(%0.15f in trial %d) min(%0.15f in trial %d)' %
                        (statistics._nScore, statistics._tsMax._nValue, statistics._tsMax._iTrial, statistics._tsMin._nValue, statistics._tsMin._iTrial))
                Common.say('    Size: current(%d) max(%d in trial %d) min(%d in trial  %d)' %
                        (statistics._cbBases, statistics._tzMax._cbBases, statistics._tzMax._iTrial, statistics._tzMin._cbBases, statistics._tzMin._iTrial))
                Common.say('    Rollbacks: total(%d) current(%d) max(%d in trial %d) min(%d in trial %d)' %
                        (statistics._cTotalRollbacks, statistics._cRollbacks, statistics._trMax._cRollbacks, statistics._trMax._iTrial, statistics._trMin._cRollbacks, statistics._trMin._iTrial))
                Common.say('    Mutations: silent(%d) attempts(%d) accepted(%d) changed(%d) inserted(%d) deleted(%d)' %
                        (statistics._cSilent, statistics._cAttempted, statistics._cAccepted, statistics._cbBasesChanged, statistics._cbBasesInserted, statistics._cbBasesDeleted))
                if statistics._atChanged._cAttempted:
                    Common.say('      Changed: attempted(%d) accepted(%d) bases-affected(%d)' %
                            (statistics._atChanged._cAttempted, statistics._atChanged._cAccepted, statistics._atChanged._cbBases))
                if statistics._atCopied._cAttempted:
                    Common.say('      Copied: attempted(%d) accepted(%d) bases-affected(%d)' %
                            (statistics._atCopied._cAttempted, statistics._atCopied._cAccepted, statistics._atCopied._cbBases))
                if statistics._atDeleted._cAttempted:
                    Common.say('      Deleted: attempted(%d) accepted(%d) bases-affected(%d)' %
                            (statistics._atDeleted._cAttempted, statistics._atDeleted._cAccepted, statistics._atDeleted._cbBases))
                if statistics._atInserted._cAttempted:
                    Common.say('      Inserted: attempted(%d) accepted(%d) bases-affected(%d)' %
                            (statistics._atInserted._cAttempted, statistics._atInserted._cAccepted, statistics._atInserted._cbBases))
                if statistics._atTransposed._cAttempted:
                    Common.say('      Transposed: attempted(%d) accepted(%d) bases-affected(%d)' %
                            (statistics._atTransposed._cAttempted, statistics._atTransposed._cAccepted, statistics._atTransposed._cbBases))

        return nCompletionCode

    except Usage, err:
        Common.sayError(err)
        return 0
Example #12
0
                Common.say('    Mutations: silent(%d) attempts(%d) accepted(%d) changed(%d) inserted(%d) deleted(%d)' %
                        (statistics._cSilent, statistics._cAttempted, statistics._cAccepted, statistics._cbBasesChanged, statistics._cbBasesInserted, statistics._cbBasesDeleted))
                if statistics._atChanged._cAttempted:
                    Common.say('      Changed: attempted(%d) accepted(%d) bases-affected(%d)' %
                            (statistics._atChanged._cAttempted, statistics._atChanged._cAccepted, statistics._atChanged._cbBases))
                if statistics._atCopied._cAttempted:
                    Common.say('      Copied: attempted(%d) accepted(%d) bases-affected(%d)' %
                            (statistics._atCopied._cAttempted, statistics._atCopied._cAccepted, statistics._atCopied._cbBases))
                if statistics._atDeleted._cAttempted:
                    Common.say('      Deleted: attempted(%d) accepted(%d) bases-affected(%d)' %
                            (statistics._atDeleted._cAttempted, statistics._atDeleted._cAccepted, statistics._atDeleted._cbBases))
                if statistics._atInserted._cAttempted:
                    Common.say('      Inserted: attempted(%d) accepted(%d) bases-affected(%d)' %
                            (statistics._atInserted._cAttempted, statistics._atInserted._cAccepted, statistics._atInserted._cbBases))
                if statistics._atTransposed._cAttempted:
                    Common.say('      Transposed: attempted(%d) accepted(%d) bases-affected(%d)' %
                            (statistics._atTransposed._cAttempted, statistics._atTransposed._cAccepted, statistics._atTransposed._cbBases))

        return nCompletionCode

    except Usage, err:
        Common.sayError(err)
        return 0

    except Common.BiologicError, err:
        Common.sayError(str(err))
        return 2

if __name__ == "__main__":
    sys.exit(main())
Example #13
0
        if Globals.urlGenome:
            Globals.genome = Genome.Genome(Globals.urlGenome)

        if Globals.urlCodonTable:
            Globals.codonTable = Genome.CodonTable(Globals.urlCodonTable)
        elif Globals.urlGenome and Globals.cmd <> Constants.cmdTranslate:
            Globals.codonTable = Globals.genome.codonTable

        if Globals.cmd == Constants.cmdCreate:
            createTable()

        elif Globals.cmd == Constants.cmdValidate:
            validateTable()

        elif Globals.cmd == Constants.cmdTranslate:
            translateGenome()

        return 0

    except Usage, err:
        Common.sayError(err)
        return 0

    except Common.BiologicError, err:
        Common.sayError(err)
        return 2


if __name__ == "__main__":
    sys.exit(main())
Example #14
0
        if Globals.urlGenome:
            Globals.genome = Genome.Genome(Globals.urlGenome)
        
        if Globals.urlCodonTable:
            Globals.codonTable = Genome.CodonTable(Globals.urlCodonTable)
        elif Globals.urlGenome and Globals.cmd <> Constants.cmdTranslate:
            Globals.codonTable = Globals.genome.codonTable

        if Globals.cmd == Constants.cmdCreate:
            createTable()
            
        elif Globals.cmd == Constants.cmdValidate:
            validateTable()
            
        elif Globals.cmd == Constants.cmdTranslate:
            translateGenome()

        return 0
        
    except Usage, err:
        Common.sayError(err)
        return 0

    except Common.BiologicError, err:
        Common.sayError(err)
        return 2

if __name__ == "__main__":
    sys.exit(main())