0cc4d81c422a64740f75af0dfb43b92f3d4be029 mmaddren Wed Sep 14 17:06:55 2011 -0700 ra file updated diff --git python/lib/ucscgenomics/ra.py python/lib/ucscgenomics/ra.py index 886c187..13b2109 100644 --- python/lib/ucscgenomics/ra.py +++ python/lib/ucscgenomics/ra.py @@ -1,18 +1,18 @@ import sys import re -from ucscgenomics.ordereddict.OrderedDict import * +from ucscgenomics.ordereddict import OrderedDict class RaFile(OrderedDict): """ Stores an Ra file in a set of entries, one for each stanza in the file. """ def __init__(self, filePath=None): OrderedDict.__init__(self) if filePath != None: self.read(filePath) def read(self, filePath): """ Reads an rafile stanza by stanza, and internalizes it. """ @@ -82,30 +82,34 @@ def itervalues(self): for item in self._OrderedDict__ordering: if not (item.startswith('#') or item == ''): yield self[item] def iteritems(self): for item in self._OrderedDict__ordering: if not (item.startswith('#') or item == ''): yield item, self[item] else: yield [item] + def append(self, item): + OrderedDict.append(self, item) + + def filter(self, where, select): """ select useful data from matching criteria where: the conditional function that must be met. Where takes one argument, the stanza and should return true or false select: the data to return. Takes in stanza, should return whatever to be added to the list for that stanza. For each stanza, if where(stanza) holds, it will add select(stanza) to the list of returned entities. Also forces silent failure of key errors, so you don't have to check that a value is or is not in the stanza. """ ret = list() for stanza in self.itervalues(): try: if where(stanza):