コード例 #1
0
    def __init__(self, nodeIndex, itsHMM):

        self.itsHMM = itsHMM

        self.index = nodeIndex  # The node index in the underlying graph

        self.id = ValidatingString("%s" % nodeIndex)
        self.state_class = PopupableInt()
        self.state_class.setPopup(itsHMM.hmmClass.name,
                                  itsHMM.hmmClass.name2code, 10)

        self.label = ValidatingString("<none>")

        self.order = DefaultedInt()
        self.order.setDefault(1, 0)

        self.emissions = []

        self.initial = Probability("0.0")
        self.tiedto = DefaultedString()
        self.tiedto.setDefault(1, '')
        self.desc = self.id

        self.reading_frame = PopupableInt(-1)
        code2name = {-1: 'None', 0: '0', 1: '1', 2: '2'}
        name2code = {'None': -1, '0': 0, '1': 1, '2': 2}
        self.reading_frame.setPopup(code2name, name2code, 4)

        self.duration = DefaultedInt()
        self.duration.setDefault(1, 0)

        self.background = PopupableInt(-1)
        self.background.setPopup(self.itsHMM.backgroundDistributions.code2name,
                                 self.itsHMM.backgroundDistributions.name2code,
                                 10)
コード例 #2
0
    def symbolsFromDom(self, XMLNode):
        symbols = XMLNode.getElementsByTagName("symbol")

        for symbol in symbols:
            symbolCode = ValidatingInt(int(symbol.getAttribute("code")))
            symbolName = ValidatingString(symbol.firstChild.nodeValue)
            symbolDesc = symbol.getAttribute("desc")
            if symbolDesc != None:
                self.addCode(symbolCode, symbolName,
                             ValidatingString(symbolDesc))
            else:
                self.addCode(symbolCode, symbolName)
コード例 #3
0
    def __init__(self, XMLFileName=None, G=None):
        # self.itsEditor = itsEditor
        if (G is None):
            self.G = Graph()
        else:
            self.G = G

        self.G.directed = 1
        self.G.euclidian = 0
        self.G.simple = 0
        self.Pi = {}
        self.id2index = {}

        # self.hmmAlphabet = DiscreteHMMAlphabet()
        self.hmmClass = HMMClass()

        # in the case of pair HMMs we have several
        self.hmmAlphabets = {}
        self.transitionFunctions = {}

        self.editableAttr = {}
        self.editableAttr['HMM'] = ['desc']
        self.desc = ValidatingString()

        self.state = {}

        self.modelType = 0
        self.name = "NoName"

        self.backgroundDistributions = NamedDistributions(self)

        self.DocumentName = "graphml"
        if XMLFileName != None:
            self.OpenXML(XMLFileName)
コード例 #4
0
    def Clear(self):
        self.G.Clear()
        self.Pi = {}
        self.id2index = {}

        # self.hmmAlphabet = DiscreteHMMAlphabet()
        self.hmmAlphabets = {}
        self.hmmClass = HMMClass()
        self.backgroundDistributions = NamedDistributions(self)

        self.editableAttr = {}
        self.editableAttr['HMM'] = ['desc']
        self.desc = ValidatingString()
        self.state = {}
        self.DocumentName = "graphml"
コード例 #5
0
    def __init__(self, nodeIndex, itsHMM):

        self.initial = Probability("0.0")
        self.label = ValidatingString("None")
        self.itsHMM = itsHMM
        # print type(self.label)

        self.index = nodeIndex  # The node index in the underlying graph
        self.id = DefaultedInt(
        )  # identification by the canvas, not always the same
        self.state_class = PopupableInt(-1)
        self.state_class.setPopup(itsHMM.hmmClass.code2name,
                                  itsHMM.hmmClass.name2code, 10)
        # XXX self.state_class.setPopup(itsHMM.hmmClass.name, itsHMM.hmmClass.name2code, 10)

        self.order = DefaultedInt()
        self.order.setDefault(1, 0)  # the default state order is 0

        self.emissions = []

        self.tiedto = DefaultedString()
        self.tiedto.setDefault(1, '')
        self.desc = self.id

        self.reading_frame = PopupableInt(-1)
        code2name = {-1: 'None', 0: '0', 1: '1', 2: '2'}
        name2code = {'None': -1, '0': 0, '1': 1, '2': 2}
        self.reading_frame.setPopup(code2name, name2code, 4)

        self.duration = DefaultedInt()
        self.duration.setDefault(1, 0)

        self.background = PopupableInt(-1)
        self.background.setPopup(self.itsHMM.backgroundDistributions.code2name,
                                 self.itsHMM.backgroundDistributions.name2code,
                                 10)

        self.editableAttr = [
            'label', 'state_class', 'initial', 'order', 'background',
            'offsetX', 'offsetY', 'alphabet_id'
        ]
        self.xmlAttr = self.editableAttr + ['ngeom', 'emissions']
        # pair HMM stuff
        self.alphabet_id = ValidatingInt(0)
        self.offsetX = ValidatingInt(1)
        self.offsetY = ValidatingInt(0)
        self.kclasses = ValidatingInt(1)
        self.transitionFunction = ValidatingInt(-1)
コード例 #6
0
ファイル: HMMEd.py プロジェクト: tempbottle/ghmm
    def EditPropertiesUp(self, event):
        if event.widget.find_withtag(CURRENT):
            widget = event.widget.find_withtag(CURRENT)[0]
            tags = self.canvas.gettags(widget)
            if not "edges" in tags:
                v = self.FindVertex(event)
                # print "Found Vertex " + "%s" % v

                #XXX if self.HMM.state[v].state_class != -1: # we have attribute state_class
                #d = EditObjectAttributesDialog(self, self.HMM.state[v], HMMState.editableAttr + ['state_class'])
                #else:
                d = EditObjectAttributesDialog(
                    self, self.HMM.state[v],
                    HMMState.editableAttr + ['state_class'])

                # We only show the label out of the editable items
                self.HMM.G.labeling[v] = ValidatingString(
                    "%s" % (self.HMM.state[v].label))  # XXX Hack Aaaargh!
                self.UpdateVertexLabel(v, 0)
コード例 #7
0
    def __init__(self, XMLFileName=None):

        self.G = Graph()
        self.G.directed = 1
        self.G.euclidian = 0
        self.Pi = {}
        self.id2index = {}

        self.hmmAlphabet = DiscreteHMMAlphabet()
        self.hmmClass = HMMClass()

        self.editableAttr = {}
        self.editableAttr['HMM'] = ['desc']
        self.desc = ValidatingString()

        self.state = {}

        self.backgroundDistributions = NamedDistributions(self)

        if XMLFileName != None:
            self.OpenXML(XMLFileName)
コード例 #8
0
ファイル: HMMEd.py プロジェクト: tempbottle/ghmm
 def set_value(self, value):
     editor.Editor.set_value(self, ValidatingString(value))
コード例 #9
0
    def fromDOM(self, XMLNode):

        self.id = ValidatingString(XMLNode.attributes['id'].nodeValue.encode(
            'ascii', 'replace'))

        self.index = self.itsHMM.G.AddVertex()

        datas = XMLNode.getElementsByTagName("data")
        for data in datas:
            dataKey = data.attributes['key'].nodeValue
            dataValue = data.firstChild.nodeValue

            if dataKey == 'class':
                self.state_class = typed_assign(self.state_class,
                                                int(dataValue))
            elif dataKey == 'label':
                self.label = type(self.label)(dataValue.encode(
                    'ascii', 'replace'))

            elif dataKey == 'order':
                if dataValue == None:  # Use default value
                    self.order = typed_assign(self.order,
                                              self.order.defaultValue)
                    self.order.useDefault = 1
                else:
                    self.order = typed_assign(self.order, int(dataValue))
                    self.order.useDefault = 0

            elif dataKey == 'initial':
                self.initial = typed_assign(self.initial, float(dataValue))

            elif dataKey == 'tiedto':

                if dataValue == None:  # Use default value
                    self.tiedto = typed_assign(self.tiedto,
                                               self.tiedto.defaultValue)
                    self.tiedto.useDefault = 1
                else:
                    self.tiedto = typed_assign(
                        self.tiedto, dataValue.encode('ascii', 'replace'))
                    self.tiedto.useDefault = 0

            elif dataKey == 'reading-frame':
                self.reading_frame = typed_assign(self.reading_frame,
                                                  int(dataValue))

            elif dataKey == 'background':
                self.background = typed_assign(
                    self.background,
                    self.itsHMM.backgroundDistributions.name2code[dataValue])

            elif dataKey == 'duration':
                self.duration = typed_assign(self.duration, int(dataValue))
                self.duration.useDefault = 0

            elif dataKey == 'ngeom':
                # We only use pos
                pos = XMLNode.getElementsByTagName('pos')[
                    0]  # Just one pos ...
                self.pos = Point2D(float(pos.attributes['x'].nodeValue),
                                   float(pos.attributes['y'].nodeValue))

            elif dataKey == 'emissions':
                # collect all strings from childnodes
                dataValue = ""
                for child in data.childNodes:
                    dataValue += child.nodeValue
                self.emissions = listFromCSV(dataValue, types.FloatType)
                #print self.emissions

            else:
                print "HMMState.fromDOM: unknown key %s of value %s" % (
                    dataKey, dataValue)