Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default clade color #73

Merged
merged 2 commits into from
Nov 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions scripts/modify-lineage-colours-and-order.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
import numpy as np
import colorsys


# Color for clades that lack clade definition, but we don't want to group with 'other'
DEFAULT_CLADE_COLOR = '#474747'


def order_lineages(lineages, aliasor):
"""
Order input lineages by using their full uncompressed lineage & converting to a sortable form
Expand Down Expand Up @@ -40,7 +45,15 @@ def clade_colors(variants, clade_definitions):
except KeyError:
if v!='other':
missing.add(v)
assert len(missing) == 0, f"Missing definitions for the following clades: {', '.join(missing)}"
defs.append([v, DEFAULT_CLADE_COLOR])

# TODO: Emit this to output file so it can be sent thru Slack notifications
if len(missing) > 0:
print(
f"Missing definitions for the following clades: {', '.join(missing)}.",
f"They have been assigned the default color {DEFAULT_CLADE_COLOR!r}"
)

return defs

def clade_display_names(variants, clade_definitions):
Expand All @@ -63,7 +76,7 @@ def colour_range(anchor, n):
lrange = np.linspace(anchor_hls[1]*1.2, anchor_hls[1], n)
srange = np.linspace(anchor_hls[2]*0.7, anchor_hls[2]*1.1, n)
rgb_range = [colorsys.hls_to_rgb(*hls) for hls in zip(hrange, lrange, srange)]
def clamp(x):
def clamp(x):
return int(max(0, min(x, 255)))
return [f"#{clamp(rgb[0]):02x}{clamp(rgb[1]):02x}{clamp(rgb[2]):02x}" for rgb in rgb_range]

Expand All @@ -77,7 +90,7 @@ def colourise(lineages, aliasor, clade_definitions):
"""
clades = {lineage: lineage_to_clade(lineage, aliasor, 'other', clade_definitions)
for lineage in lineages}

colours = []

for clade in list(set(clades.values())):
Expand Down Expand Up @@ -124,4 +137,4 @@ def colourise(lineages, aliasor, clade_definitions):
print(f"Variant classification of {args.variant_classification}: no post-processing of JSON")

with open(args.output, 'w') as fh:
json.dump(data, fh, indent=None)
json.dump(data, fh, indent=None)
Loading