6e08c5d3dfde95b99a84ce9ddf74756b95b41dfb mmaddren Mon Apr 2 10:53:13 2012 -0700 bugfixes for ra and mdb to fix an ordering issue for mdb file values. Also added new changes to cv validation diff --git python/lib/ucscgenomics/ra.py python/lib/ucscgenomics/ra.py index 75386fe..79b99e6 100644 --- python/lib/ucscgenomics/ra.py +++ python/lib/ucscgenomics/ra.py @@ -62,41 +62,45 @@ We don't always have to just return the stanza in the second parameter however. If we wanted to, for each stanza, return the file associated with that stanza, we could easily do that as well. This would return a simple list of the string filenames in a ra file: files = rafile.filter(lambda s: 1, lambda s: s['fileName']) Note that once again, we don't have to ensure 'fileName' exists. Also note that lambda s: 1 means always return true. Lambda expressions are always preferable to functions unless the expression would need to be reused multiple times. It is also best to reduce the set of stanzas as much as possible before operating over them. Filtering allows you to eliminate a lot of code. ''' + @property + def filename(self): + return self._filename + def __init__(self, filePath=None, key=None): OrderedDict.__init__(self) if filePath != None: self.read(filePath, key) def read(self, filePath, key=None): ''' Reads an rafile stanza by stanza, and internalizes it. Don't override this for derived types, instead override readStanza. ''' - + self._filename = filePath file = open(filePath, 'r') #entry = None stanza = list() keyValue = '' reading = 1 while reading: line = file.readline() if line == '': reading = 0 line = line.strip() if len(stanza) == 0 and (line.startswith('#') or (line == '' and reading)): @@ -133,30 +137,34 @@ key: optional key for selective key filtering. Don't worry about it OUT namekey: the key of the stanza's name nameval: the value of the stanza's name entry: the stanza itself ''' entry = RaStanza() if entry.readStanza(stanza, key) == None: return None, None, None entry = RaStanza() val1, val2 = entry.readStanza(stanza, key) return val1, val2, entry + def write(self, filename): + file = open(filename, 'w') + file.write(str(self)) + def iter(self): pass def iterkeys(self): for item in self._OrderedDict__ordering: if not(item.startswith('#') or item == ''): yield item def itervalues(self): for item in self._OrderedDict__ordering: if not (item.startswith('#') or item == ''): yield self[item]