c3e58a91c785782b6d81cc2225b53ad19b438511 wong Thu Jan 12 15:08:49 2012 -0800 rewrote some of updatediff to take out the metaDb special case, it now does it ra-type agnostically diff --git python/lib/ucscgenomics/ra.py python/lib/ucscgenomics/ra.py index 7f5031b..550afba 100644 --- python/lib/ucscgenomics/ra.py +++ python/lib/ucscgenomics/ra.py @@ -363,66 +363,59 @@ RetThis[stanza.name] = stanza elif thisSelectDict[stanza.name] != thatSelectDict[stanza.name]: RetThis[stanza.name] = stanza return RetThis def updateDiffFilter(self, term, other): ''' Replicates updateMetadata. Input: Term Other raFile Output: Merged RaFile Stanzas found in 'self' and 'other' that have the 'Term' in 'other' - are overwritten (or inserted if not found) into 'self'. Final merged - dictionary is returned. + are overwritten (or inserted if not found) into 'self'. + Final merged dictionary is returned. ''' ret = self common = set(self.iterkeys()) & set(other.iterkeys()) for stanza in common: if term not in self[stanza] and term not in other[stanza]: continue if term in self[stanza] and term not in other[stanza]: del ret[stanza][term] continue - if term in other[stanza]: #Remake stanza to keep order of terms tempStanza = RaStanza() tempStanza._name = stanza - try: - tempStanza['metaObject'] = self[stanza]['metaObject'] - tempStanza['objType'] = self[stanza]['objType'] - termList = self[stanza].keys() - termList.remove('metaObject') - termList.remove('objType') - except KeyError: - termList = self[stanza].keys() - if term not in termList: - termList.append(term) - for t in sorted(termList, key=str.lower): - if t == term: - if t not in self[stanza]: - tempStanza[t] = other[stanza][t] - elif self[stanza][t] != other[stanza][t]: - tempStanza[t] = other[stanza][t] + selfListItor = list(self[stanza].iterkeys()) + otherListItor = list(other[stanza].iterkeys()) + newOther = list() + for i in otherListItor: + if not i in selfListItor and i != term: + continue else: - tempStanza[t] = self[stanza][t] + newOther.append(i) + masterList = ucscUtils.mergeList(newOther, selfListItor) + for i in masterList: + if i == term: + tempStanza[i] = other[stanza][i] else: - tempStanza[t] = self[stanza][t] + tempStanza[i] = self[stanza][i] ret[stanza] = tempStanza return ret 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):