def load(self, dictionary):
     ConfigObject.load(self, dictionary)
     #Detect if user provides the data or not
     start = 0
     if 'start' in dictionary:
         start = float(dictionary['start'])
     if 'data' not in dictionary:
         if 'p' not in dictionary:
             raise ParseException(
                 'Probability is missing in RepeatLengthDistribution'
             )
         p = float(dictionary['p'])
         if 'fractions' not in dictionary:
             raise ParseException(
                 'Fractions are missing in RepeatLengthDistribution'
             )
         fractions = dictionary['fractions']
         self.setParams(p, start, fractions)
     else:
         data = dictionary['data']
         if 'fractionssize' not in dictionary:
             raise ParseException(
                 'Number of fractions is missing in RepeatLengthDistribution'
             )
         self.train(data, int(dictionary['fractionssize']), start)
Beispiel #2
0
 def load(self, dictionary):
     ConfigObject.load(self, dictionary)
     if "emission" not in dictionary:
         raise ParseException("Emission not found in state")
     if "name" not in dictionary:
         raise ParseException("Name not found in state")
     if "startprob" not in dictionary:
         raise ParseException("startprob not found in state")
     if "endprob" not in dictionary:
         raise ParseException("endprob not found in state")
     if "serialize" in dictionary:
         self.serialize = dictionary["serialize"]
     self.stateName = dictionary["name"]
     if "onechar" in dictionary:
         if len(dictionary['onechar']) != 1:
             raise ParseException('onechar has wrong length')
         self.onechar = dictionary["onechar"]
     else:
         if len(self.stateName) > 0:
             self.onechar = self.stateName[0]
         else:
             self.onechar = "?"
     self.startProbability = self.mathType(dictionary["startprob"])
     self.endProbability = self.mathType(dictionary["endprob"])
     self.emissions = dict()
     for [key, prob] in dictionary["emission"]:
         if key.__class__.__name__ == "list":
             key = tuple(key)
         try:
             self.emissions[key] = self.mathType(prob)
         except ValueError:
             self.emissions[key] = prob
Beispiel #3
0
    def load(self, dictionary):
        ConfigObject.load(self, dictionary)
        if "sequences" not in dictionary:
            raise ParseException("Sequences not in AnnotationConfig")

        self.annotations = dictionary['annotations']
        self.sequences = dict()

        for i in dictionary["sequences"]:
            self.sequences[i['name']] = dict()
            for a in i['annotations']:
                if a['id'] in self.annotations:
                    if 'offset' in a:
                        offset = a['offset']
                    else:
                        offset = 0
                    self.sequences[i['name']][a['id']] = (a['file'], offset)
Beispiel #4
0
    def load(self, dictionary):
        ConfigObject.load(self, dictionary)
        if "sequences" not in dictionary:
            raise ParseException("Sequences not in AnnotationConfig")

        self.annotations = dictionary['annotations']
        self.sequences = dict()

        for i in dictionary["sequences"]:
            self.sequences[i['name']] = dict()
            for a in i['annotations']:
                if a['id'] in self.annotations:
                    if 'offset' in a:
                        offset = a['offset']
                    else:
                        offset = 0
                    self.sequences[i['name']][a['id']] = (a['file'], offset)
Beispiel #5
0
 def toJSON(self):
     ret = ConfigObject.toJSON(self)
     ret["annotations"] = self.annotations
     ret["sequences"] = list()
     for key, value in self.sequences.iteritems():
         ann = list()
         for akey, avalue in value.iteritems():
             ann.append({'id': akey, 'file': avalue[0], 'offset': avalue[1]})
         ret["sequences"].append({"name": key, "annotations": ann})
     return ret
Beispiel #6
0
 def toJSON(self):
     ret = ConfigObject.toJSON(self)
     ret["name"] = self.stateName
     ret["onechar"] = self.onechar
     ret["emission"] = list()
     ret["startprob"] = self.startProbability
     ret["endprob"] = self.endProbability
     for (key, prob) in self.emissions.iteritems():
         ret["emission"].append((key, prob))
     return ret
Beispiel #7
0
 def toJSON(self):
     ret = ConfigObject.toJSON(self)
     ret["annotations"] = self.annotations
     ret["sequences"] = list()
     for key, value in self.sequences.iteritems():
         ann = list()
         for akey, avalue in value.iteritems():
             ann.append({
                 'id': akey,
                 'file': avalue[0],
                 'offset': avalue[1]
             })
         ret["sequences"].append({"name": key, "annotations": ann})
     return ret
 def load(self, dictionary):
     ConfigObject.load(self, dictionary)
     #Detect if user provides the data or not
     start = 0
     if 'start' in dictionary:
         start = float(dictionary['start'])
     if 'data' not in dictionary:
         if 'p' not in dictionary:
             raise ParseException(
                 'Probability is missing in RepeatLengthDistribution')
         p = float(dictionary['p'])
         if 'fractions' not in dictionary:
             raise ParseException(
                 'Fractions are missing in RepeatLengthDistribution')
         fractions = dictionary['fractions']
         self.setParams(p, start, fractions)
     else:
         data = dictionary['data']
         if 'fractionssize' not in dictionary:
             raise ParseException(
                 'Number of fractions is missing in RepeatLengthDistribution'
             )
         self.train(data, int(dictionary['fractionssize']), start)
Beispiel #9
0
 def test_configLoadingAndSaving(self):
     input_file = "data/test_data/ConfigFactoryTestData.js"
     a = ConfigFactory()
     a.addObject(ConfigObject)
     X = a.load(input_file)
     self.assertEqual(type(X[1]), type(ConfigObject()),
                      "objectHook does not work")
     X[1] = X[1].toJSON()
     Y = [{
         '1': 2,
         'lol': 1.4
     }, {
         '__name__': 'ConfigObject'
     }, [1, 2, 3, 4, {
         '1': 2
     }]]
     self.assertEqual(X[0], Y[0], "loading of json does not work")
     self.assertEqual(X[2], Y[2], "loading of json does not work")
     self.assertEqual(X[1], Y[1], "saving to \"json\" is not working: " + \
                                  str(X) + " != " + str(Y))
     self.assertEqual(X, Y, "this should not happened")
Beispiel #10
0
 def toJSON(self):
     ret = ConfigObject.toJSON(self)
     ret['val'] = self.value
     return ret
Beispiel #11
0
 def toJSON(self):
     ret = ConfigObject.toJSON(self)
     ret = self.statesToJSON(ret)
     ret = self.transitionsToJSON(ret)
     return ret
 def toJSON(self):
     ret = ConfigObject.toJSON(self)
     ret['p'] = self.p
     ret['start'] = self.start
     ret['fractions'] = self.fractions
     return ret         
Beispiel #13
0
 def toJSON(self):
     ret = ConfigObject.toJSON(self)
     ret['val'] = self.value
     return ret
Beispiel #14
0
 def load(self, dictionary): 
     ConfigObject.load(self, dictionary)
     if 'val' not in dictionary:
         raise ParseException("Value ('val') not found in state")
     self.value = float(dictionary['val']) 
 def toJSON(self):
     ret = ConfigObject.toJSON(self)
     ret['p'] = self.p
     ret['start'] = self.start
     ret['fractions'] = self.fractions
     return ret
Beispiel #16
0
 def load(self, dictionary):
     ConfigObject.load(self, dictionary)
     self.loadStates(dictionary)
     self.loadTransitions(dictionary)
Beispiel #17
0
 def load(self, dictionary):
     ConfigObject.load(self, dictionary)
     if 'val' not in dictionary:
         raise ParseException("Value ('val') not found in state")
     self.value = float(dictionary['val'])