From: Diane Trout Date: Fri, 6 Jul 2012 23:03:51 +0000 (-0700) Subject: Switch to regular dictionary instead of ordered dictionary. X-Git-Url: http://woldlab.caltech.edu/gitweb/?p=htsworkflow.git;a=commitdiff_plain;h=b1985bef54d67e8a5e1c9bca9e63af77e3d38230 Switch to regular dictionary instead of ordered dictionary. python 2.6 doesn't have ordered dictionary. So I switched to using a regular dictionary and just sorting the returned keys. --- diff --git a/htsworkflow/pipelines/eland.py b/htsworkflow/pipelines/eland.py index 87c6fb7..873dbef 100644 --- a/htsworkflow/pipelines/eland.py +++ b/htsworkflow/pipelines/eland.py @@ -639,7 +639,7 @@ class ELAND(collections.MutableMapping): def __init__(self, xml=None): # we need information from the gerald config.xml - self.results = collections.OrderedDict() + self.results = {} if xml is not None: self.set_elements(xml) @@ -658,7 +658,9 @@ class ELAND(collections.MutableMapping): del self.result[key] def __iter__(self): - return self.results.iterkeys() + keys = self.results.iterkeys() + for k in sorted(keys): + yield k def __len__(self): return len(self.results) diff --git a/htsworkflow/pipelines/test/test_eland.py b/htsworkflow/pipelines/test/test_eland.py index 9c61269..688d00e 100644 --- a/htsworkflow/pipelines/test/test_eland.py +++ b/htsworkflow/pipelines/test/test_eland.py @@ -229,6 +229,21 @@ class ElandTests(unittest.TestCase): self.assertEqual(len(match_reads), 0) self.assertEqual(reads, 1) + def test_ordering(self): + e = ELAND() + sl3 = SampleKey(lane=3, read=1, sample='33333') + sl1 = SampleKey(lane=1, read=1, sample='11111') + sl5 = SampleKey(lane=5, read=1, sample='55555') + e.results[sl5] = 'Lane5' + e.results[sl3] = 'Lane3' + e.results[sl1] = 'Lane1' + + e_list = e.values() + print e.items() + self.assertEqual(e_list[0], 'Lane1') + self.assertEqual(e_list[1], 'Lane3') + self.assertEqual(e_list[2], 'Lane5') + class TestElandMatches(unittest.TestCase): def test_eland_replacing(self): key = SampleKey(1, 1, 's')