8c79d3736ac42530d220c4b53211aa1524300d50
wong
  Fri Jan 20 15:19:40 2012 -0800
fixed a bug where the 'parent' or 'subTrack' key will be treated as such even with things like >>>>> in front of it
diff --git python/lib/ucscgenomics/ra.py python/lib/ucscgenomics/ra.py
index 344b564..2595548 100644
--- python/lib/ucscgenomics/ra.py
+++ python/lib/ucscgenomics/ra.py
@@ -406,51 +406,54 @@
                         tempStanza[i] = other[stanza][i]
                     else:
                         tempStanza[i] = self[stanza][i]
             ret[stanza] = tempStanza
         return ret
 
     def printTrackDbFormat(self):
         '''
         Converts a .ra file into TrackDb format.
         Returns a printable string.
         '''
         retstring = ""
         parentTrack = ""
         tier = 0
         commentList = []
+        p = re.compile('^.*parent')
+        p2 = re.compile('^.*subTrack')
         for stanza in self:
             if stanza == "":
                 if commentList:
                     for line in commentList:
                         for i in range(tier):
                             retstring += "    "
                         retstring += line + "\n"
                     commentList = []
                     retstring += "\n"
                 continue
             if stanza.startswith("#"):
                 commentList.append(stanza)
                 continue
-            if "subTrack" in self[stanza].keys():
-                if parentTrack not in self[stanza]['subTrack'] or parentTrack == "":
-                    parentTrack = self[stanza]['track']
-                    tier = 1
-                else:
-                    tier = 2
-            if "parent" in self[stanza].keys():
-                if parentTrack not in self[stanza]['parent'] or parentTrack == "":
+            keys = self[stanza].keys()
+            parentKey = "NOKEYFOUND"
+            for key in keys:
+                if p.search(key):
+                    parentKey = key
+                if p2.search(key):
+                    parentKey = key
+            if parentKey in keys:
+                if parentTrack not in self[stanza][parentKey] or parentTrack == "":
                     parentTrack = self[stanza]['track']
                     tier = 1
                 else:
                     tier = 2
             if commentList:
                 for line in commentList:
                     for i in range(tier):
                         retstring += "    "
                     retstring += line + "\n"
                 commentList = []
             for line in self[stanza]:
                 for i in range(tier):
                     retstring += "    "
                 if line.startswith("#"):
                     retstring += line + "\n"