def testNumberDef(self): NumDef = Enumeration("NumDef", (("neg", None, None, -2), ("zero", None, None, 0), ("pos", None, None, 2), ("big", None, None, 3))) values = [(str(v), int(v)) for v in NumDef.values] self.failUnlessEqual(values, [('neg', -2), ('zero', 0), ('pos', 2), ('big', 3)]) self.failUnlessEqual(NumDef.getByNumValue(2), NumDef.pos)
def testBitSetValues(self): Stat = Enumeration("Stat", ["okay", ("notConserved","notConserved", ("no_alignment",)), "bad_3_splice", "bad_5_splice"], bitSetValues=True) self.failUnlessEqual(Stat.okay, 1) self.failUnlessEqual(Stat.notConserved, 2) self.failUnlessEqual(Stat.bad_5_splice, 8) self.failUnlessEqual(int(Stat.bad_5_splice), 8) self.failUnlessEqual(Stat.maxNumValue, 8) vals = Stat.getValues(9) self.failUnlessEqual(len(vals), 2) self.failUnless(vals[0] is Stat.okay) self.failUnless(vals[1] is Stat.bad_5_splice)
def testAliases(self): Name = Enumeration("Name", ["Fred", ("Rick", "Richard", ("Dick", "HeyYou")), ("Bill", "Willian")]) self.failUnlessEqual(Name.lookup("Richard"), Name.Rick) self.failUnless(Name.lookup("Richard") is Name.Rick) self.failUnlessEqual(Name.lookup("Dick"), Name.Rick) self.failUnless(Name.lookup("Dick") is Name.Rick) self.failUnless(Name.lookup("Rick") == Name.Rick) self.failUnless(Name.lookup("HeyYou") == Name.Rick) self.failUnless(Name.lookup("Fred") == Name.Fred) self.failUnless(Name.lookup("Fred") is Name.Fred) self.failUnless(str(Name.Rick) == "Richard")
def testAliasesBug1(self): "forgot comma in one-element tuple" try: Stat = Enumeration("Stat", ["okay", ("notConserved","notConserved", ("no_alignment")), "bad_3_splice", "bad_5_splice"]) if __debug__: self.fail("should have raised exception") except TypeError: pass
# Copyright 2006-2012 Mark Diekhans import copy from pycbio.sys import fileOps, dbOps from pycbio.hgdata.AutoSql import intArraySplit, intArrayJoin from pycbio.sys.Enumeration import Enumeration CdsStat = Enumeration( "CdsStat", [ ("none", "none"), # No CDS (non-coding) ("unknown", "unk"), # CDS is unknown (coding, but not known) ("incomplete", "incmpl"), # CDS is not complete at this end ("complete", "cmpl") ]) # CDS is complete at this end genePredColumns = ("name", "chrom", "strand", "txStart", "txEnd", "cdsStart", "cdsEnd", "exonCount", "exonStarts", "exonEnds", "score", "name2", "cdsStartStat", "cdsEndStat", "exonFrames") genePredExtColumns = ("name", "chrom", "strand", "txStart", "txEnd", "cdsStart", "cdsEnd", "exonCount", "exonStarts", "exonEnds") class Range(object): "start and end coordinates" __slots__ = ("start", "end") def __init__(self, start, end): self.start = start self.end = end
def __getColors(self): return Enumeration("Colors", ["red", "green", "blue"])
class CycleException(ExRunException): "Exception indicating a cycle has occured" def __init__(self, cycle): desc = [] for n in cycle: desc.append(" " + str(n) + " ->") ExRunException.__init__(self, "cycle detected:\n" + "\n".join(desc)) # state of a Production and valid transitions # - bad - doesn't exist and no rule to create # - failed - rule to create failed # - blocked - blocked because some requirement can't be built ProdState = Enumeration( "ProdState", ("unknown", "outdated", "current", "failed", "blocked", "bad")) _prodStateTbl = {} _prodStateTbl[ProdState.unknown] = frozenset( [ProdState.outdated, ProdState.current, ProdState.blocked, ProdState.bad]) _prodStateTbl[ProdState.outdated] = frozenset( [ProdState.current, ProdState.blocked, ProdState.failed, ProdState.bad]) _prodStateTbl[ProdState.current] = _emptySet _prodStateTbl[ProdState.failed] = _emptySet _prodStateTbl[ProdState.blocked] = _emptySet _prodStateTbl[ProdState.bad] = _emptySet # state of a Rule and valid transitions # - failed - rule failed # - blocked - blocked because some requirement can't be built RuleState = Enumeration(
else: raise ValueError("invalid nmd column value: \"" + val + "\"") def nmdFmt(val): "format value of the NMD column (ok or nmd)" if val: return "ok" else: return "nmd" nmdType = (nmdParse, nmdFmt) # frame status Frame = Enumeration("FrameStat", ["ok", "bad", "mismatch", "discontig", "noCDS"]) #acc chr chrStart chrEnd strand stat frame start stop orfStop cdsGap cdsMult3Gap utrGap cdsUnknownSplice utrUnknownSplice cdsNonCanonSplice utrNonCanonSplice numExons numCds numUtr5 numUtr3 numCdsIntrons numUtrIntrons nmd causes typeMap = { "acc": intern, "chrStart": int, "chrEnd": int, "strand": intern, "stat": statType, "frame": Frame, "start": startStopType, "stop": startStopType, "orfStop": int, "cdsGap": int, "cdsMult3Gap": int, "utrGap": int,