74595613d1cd0138897581bbebc164636bd26895 wong Fri Jan 13 12:56:00 2012 -0800 added in willy's ra->trackDb print option diff --git python/lib/ucscgenomics/ra.py python/lib/ucscgenomics/ra.py index e459aab..3294212 100644 --- python/lib/ucscgenomics/ra.py +++ python/lib/ucscgenomics/ra.py @@ -398,30 +398,77 @@ if not i in selfKeys and i != term: continue else: newOther.append(i) #merge self keylist and filtered other list masterList = ucscUtils.mergeList(newOther, selfKeys) for i in masterList: if i == term: tempStanza[i] = other[stanza][i] else: tempStanza[i] = self[stanza][i] ret[stanza] = tempStanza return ret + def printTrackDbFormat(self): + retstring = "" + space = False + tab = False + commentList = [] + for stanza in self: + if stanza == "": + if commentList: + for line in commentList: + if space == True: + retstring += " " + if tab == True: + retstring += " " + retstring += line + "\n" + commentList = [] + retstring += "\n" + continue + if stanza.startswith("#"): + commentList.append(stanza) + continue + if "visibility" in self[stanza].keys(): + tab = False + space = True + if "subGroups" in self[stanza].keys(): + tab = True + space = True + if commentList: + for line in commentList: + if space == True: + retstring += " " + if tab == True: + retstring += " " + retstring += line + "\n" + commentList = [] + for line in self[stanza]: + if space == True: + retstring += " " + if tab == True: + retstring += " " + if line.startswith("#"): + retstring += line + "\n" + else: + retstring += line + " " + self[stanza][line] + "\n" + retstring += "\n" + return retstring + + 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 #.rsplit('\n', 1)[0] class RaStanza(OrderedDict): ''' Holds an individual entry in the RaFile. '''