From ebc17649781d788885774b91edae3fc44042e291 Mon Sep 17 00:00:00 2001 From: Thomas Sibley Date: Tue, 7 Apr 2020 15:40:00 -0700 Subject: [PATCH 1/2] Tests: Failing test for filter priorities regression Fix to follow. --- tests/test_filter.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_filter.py b/tests/test_filter.py index 10a5c6949..0c0d0251d 100644 --- a/tests/test_filter.py +++ b/tests/test_filter.py @@ -44,6 +44,8 @@ def test_read_priority_scores_valid(self, mock_priorities_file_valid): ) assert priorities == {"strain1": 5, "strain2": 6, "strain3": 8} + assert priorities["strain1"] == 5 + assert priorities["strain42"] == 0, "Default priority is 0 for unlisted sequences" def test_read_priority_scores_malformed(self, mock_priorities_file_malformed): with pytest.raises(ValueError): From 8139f32da0abe9edadc6516e286b6d0333d4ff70 Mon Sep 17 00:00:00 2001 From: Thomas Sibley Date: Tue, 7 Apr 2020 15:30:29 -0700 Subject: [PATCH 2/2] filter: Restore default priority of 0 for missing sequences Fixes a regression introduced by "Allow exception to bubble up when priority file is bad." (63d6cb2) which accidentally changed the return type of read_priority_scores() from defaultdict(float) to dict. The calling code looks up sequences unconditionally in the priorities dictionary and thus defaultdict(float) provides an appropriate fallback value when no priority is explicitly given in the provided file. --- augur/filter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/augur/filter.py b/augur/filter.py index 0dabcfb3b..50cc34055 100644 --- a/augur/filter.py +++ b/augur/filter.py @@ -56,10 +56,10 @@ def write_vcf(input_filename, output_filename, dropped_samps): def read_priority_scores(fname): try: with open(fname) as pfile: - return { + return defaultdict(float, { elems[0]: float(elems[1]) for elems in (line.strip().split() for line in pfile.readlines()) - } + }) except Exception as e: print(f"ERROR: missing or malformed priority scores file {fname}", file=sys.stderr) raise e