Skip to content

Commit

Permalink
Merge pull request #261 from bacpop/indiv-viz
Browse files Browse the repository at this point in the history
Fix for using visualise with indiv refine ref-db
  • Loading branch information
johnlees authored Apr 19, 2023
2 parents d7ba534 + 02474e3 commit 7cb20a0
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions PopPUNK/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,14 +329,23 @@ def joinClusterDicts(d1, d2):
d1 (dict of dicts)
d1 with d2 appended
"""
if d1.keys() != d2.keys():
sys.stderr.write("Cluster columns not compatible\n")
matching_cols = set(d1.keys()).intersection(d2.keys())
if len(matching_cols) == 0:
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)

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

Expand Down

0 comments on commit 7cb20a0

Please sign in to comment.