1a6d3d1533b065856ec5061633ab0cc07a9eb528
mmaddren
  Thu Jan 20 14:30:18 2011 -0800
added rafile python scripts
diff --git python/ucscgenomics/rafile/radict.py python/ucscgenomics/rafile/radict.py
new file mode 100644
index 0000000..a14f3a1
--- /dev/null
+++ python/ucscgenomics/rafile/radict.py
@@ -0,0 +1,63 @@
+#
+# rafile/radict.py
+#
+# Holds raDict class which is an internal representation of
+# the data held in the RA file. Essentially just a dict that
+# also has a list to preserve the computationally arbitrary
+# order we want an RA entry to be in.
+#
+
+import sys
+
+class _OrderedDict:
+
+    def __init__(self):
+        self._dictionary = dict()
+        self._ordering = list()
+
+    def add(self, key, value):
+        key = key.strip()
+
+        if (key in self._dictionary):
+            print 'ERROR: RaDict.add() - Key <' + key + '> already exists'
+            sys.exit(1)
+
+        if (key == None or key == ''):
+            return
+        
+        self._dictionary[key] = value
+        self._ordering.append(key)
+        
+    def remove(self, key):
+        key = key.strip()
+
+        if (key not in self._dictionary):
+            print 'ERROR: RaDict.remove() - Key <' + key + '> does not exist'
+            sys.exit(1)
+
+        if (key == None or key == ''):
+            return
+
+        del self._dictionary[key]
+        self._ordering.remove(key)
+
+    def getValue(self, key):
+        if (key not in self._dictionary):
+            print 'ERROR: RaDict.getValue() - KEY <' + key + '> does not exist'
+            sys.exit(1) 
+
+        return self._dictionary[key]
+
+class RaDict(_OrderedDict):
+
+    def __str__(self):
+        for key in self._ordering:
+            print self._dictionary[key]
+        return ''
+
+class EntryDict(_OrderedDict):
+
+    def __str__(self):
+        for key in self._ordering:
+            print key + ' ' + self._dictionary[key]
+        return ''