eafabc2cbec6eb8a8955badf7c01191c1299ac49
mmaddren
  Thu Apr 7 16:47:30 2011 -0700
first push to my new branch
diff --git python/ucscgenomics/rafile/RaFile.py python/ucscgenomics/rafile/RaFile.py
index f12842d..7f54d3b 100644
--- python/ucscgenomics/rafile/RaFile.py
+++ python/ucscgenomics/rafile/RaFile.py
@@ -14,112 +14,158 @@
     def read(self, filePath):
         """
         Reads an rafile stanza by stanza, and internalizes it.
         """
 
         file = open(filePath, 'r')
 
         entry = self.__entryType()
         stanza = list()
         keyValue = ''
 
         for line in file:
  
             line = line.strip()
 
-            if len(stanza) == 0 and line.startswith('#'):
+            if len(stanza) == 0 and (line.startswith('#') or line == ''):
                 self._OrderedDict__ordering.append(line)
                 continue
 
             if line != '':
                 stanza.append(line)
             elif len(stanza) > 0:
                if keyValue == '':
                    keyValue, name = entry.readStanza(stanza)
                else:
                    testKey, name = entry.readStanza(stanza)
                    if keyValue != testKey:
                        raise KeyError('Inconsistent Key ' + testKey)
        
                if name in self:
                    raise KeyError('Duplicate Key ' + name)
 
                self[name] = entry
                entry = self.__entryType()
                stanza = list()
 
         if len(stanza) > 0:
             raise IOError('File is not newline terminated')
 
         file.close()
 
 
+    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 items in self._OrderedDict.__ordering(self):
-            if not item.startswith('#'):
+        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('#'):
+            if not (item.startswith('#') or item == ''):
                 yield item, self[item]
             else:
                 yield [item]
 
 
     def __str__(self):
         str = ''
         for item in self.iteritems():
             if len(item) == 1:
                 str += item[0].__str__() + '\n'
             else:
                 str += item[1].__str__() + '\n'
         return str
 
 
 class RaEntry(OrderedDict.OrderedDict):
     """
     Holds an individual entry in the RaFile.
     """
 
+    def __init__(self):
+        self._name = ''
+        OrderedDict.OrderedDict.__init__(self)
+  
+    @property 
+    def name(self):
+        return self._name
+
+
     def readStanza(self, stanza):
         """
         Populates this entry from a single stanza
         """
 
         for line in stanza:
             self.__readLine(line)
 
         return self.__readName(stanza[0])
 
 
     def __readName(self, line):
         """
         Extracts the Stanza's name from the value of the first line of the
         stanza.
         """
 
         if len(line.split(' ', 1)) != 2:
             raise ValueError()
 
-        return map(str.strip, line.split(' ', 1))
-
+        names = map(str.strip, line.split(' ', 1))
+        self._name = names[1]
+        return names
 
     def __readLine(self, line):
         """
         Reads a single line from the stanza, extracting the key-value pair
         """ 
 
-        if line.startswith('#'):
-            raise KeyError('Comment in the middle of a stanza')
-
+        if line.startswith('#') or line == '':
+            self._OrderedDict__ordering.append(line)
+        else:
         raKey, raVal = map(str, line.split(' ', 1))
         self[raKey] = raVal
 
 
+    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]
+
+
+    def iteritems(self):
+        for item in self._OrderedDict__ordering:
+            if not (item.startswith('#') or item == ''):
+                yield item, self[item]
+
+
     def __str__(self):
         str = ''
         for key in self:
-            str = str + key + ' ' + self[key] + '\n'
+            if key.startswith('#'):
+                str += key + '\n'
+            else:
+                str += key + ' ' + self[key] + '\n'
+
         return str
 
