From 7b3367c4cdcec9df280239aa0741b54aeba96621 Mon Sep 17 00:00:00 2001 From: John Lees Date: Thu, 13 Apr 2023 16:35:22 +0100 Subject: [PATCH 1/2] Fix for using visualise with indiv refine ref-db --- PopPUNK/utils.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/PopPUNK/utils.py b/PopPUNK/utils.py index cae085cc..0eb4b95a 100644 --- a/PopPUNK/utils.py +++ b/PopPUNK/utils.py @@ -329,14 +329,23 @@ def joinClusterDicts(d1, d2): d1 (dict of dicts) d1 with d2 appended """ - if d1.keys() != d2.keys(): + matching_cols = set(d1.keys()).intersection(d2.keys()) + if len(matching_cols) == 0: sys.stderr.write("Cluster columns not compatible\n") + sys.stderr.write(f"{d1.keys()} {d2.keys()}\n") sys.exit(1) + missing_cols = [] for column in d1.keys(): - # Combine dicts: https://stackoverflow.com/a/15936211 - d1[column] = \ - dict(chain.from_iterable(d.items() for d in (d1[column], d2[column]))) + if column in matching_cols: + # Combine dicts: https://stackoverflow.com/a/15936211 + d1[column] = \ + dict(chain.from_iterable(d.items() for d in (d1[column], d2[column]))) + else: + missing_cols.append(column) + + for missing in missing_cols: + del d1[missing] return d1 From 02474e33e2f49e4c4bd75affe0e9045fd5684675 Mon Sep 17 00:00:00 2001 From: John Lees Date: Wed, 19 Apr 2023 11:07:58 +0100 Subject: [PATCH 2/2] Update PopPUNK/utils.py Co-authored-by: nickjcroucher --- PopPUNK/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PopPUNK/utils.py b/PopPUNK/utils.py index 0eb4b95a..647d0203 100644 --- a/PopPUNK/utils.py +++ b/PopPUNK/utils.py @@ -331,7 +331,7 @@ def joinClusterDicts(d1, d2): """ matching_cols = set(d1.keys()).intersection(d2.keys()) if len(matching_cols) == 0: - sys.stderr.write("Cluster columns not compatible\n") + sys.stderr.write("Cluster columns do not match between sets being combined\n") sys.stderr.write(f"{d1.keys()} {d2.keys()}\n") sys.exit(1)