Skip to content

Commit eeeaf06

Browse files
committed
updates trace colors, logging message
1 parent f862ec0 commit eeeaf06

File tree

1 file changed

+12
-22
lines changed

1 file changed

+12
-22
lines changed

covviz/bed.py

+12-22
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import numpy as np
99
import pandas as pd
1010

11-
from .utils import gzopen, merge_intervals
11+
from .utils import COLORS, gzopen, merge_intervals
1212

1313
try:
1414
from itertools import ifilterfalse as filterfalse
@@ -254,18 +254,8 @@ def parse_bed(
254254
# chromosomes, in order of appearance
255255
chroms = list()
256256
samples = list()
257-
plotly_colors = [
258-
"#1f77b4", # muted blue
259-
"#ff7f0e", # safety orange
260-
"#2ca02c", # cooked asparagus green
261-
"#d62728", # brick red
262-
"#9467bd", # muted purple
263-
"#8c564b", # chestnut brown
264-
"#e377c2", # raspberry yogurt pink
265-
"#7f7f7f", # middle gray
266-
"#bcbd22", # curry yellow-green
267-
"#17becf", # blue-teal
268-
]
257+
sample_trace_color = dict()
258+
269259
sex_chroms = [i.strip("chr") for i in sex_chroms.split(",")]
270260

271261
groups = None
@@ -298,6 +288,9 @@ def parse_bed(
298288
for x_index, row in enumerate(entries):
299289
if not samples:
300290
samples = [i for i in sorted(row.keys()) if i not in header[:3]]
291+
# plot outlier traces across chromosomes with the same color for a given sample
292+
for sample_index, sample in enumerate(samples):
293+
sample_trace_color[sample] = COLORS[sample_index % len(COLORS)]
301294
if groups:
302295
valid = validate_samples(samples, groups)
303296
if not valid:
@@ -384,7 +377,8 @@ def parse_bed(
384377
trace["fillcolor"] = fill_color
385378
json_output.append(trace)
386379
# add the sample traces for the outlier plots atop area traces
387-
for trace_index, (sample, trace_data) in enumerate(traces.items()):
380+
len_traces = 0
381+
for sample, trace_data in traces.items():
388382
trace = dict(
389383
x=trace_data["x"],
390384
y=trace_data["y"],
@@ -394,18 +388,14 @@ def parse_bed(
394388
mode="lines",
395389
name="significant",
396390
# include color as primary colors occupied by area traces
397-
marker={
398-
"width": 1,
399-
"color": plotly_colors[trace_index % len(plotly_colors)],
400-
},
391+
marker={"width": 1, "color": sample_trace_color[sample]},
401392
)
393+
if trace_data["x"]:
394+
len_traces += 1
402395
json_output.append(trace)
403396

404397
bed_traces[chrom] = json_output
405-
logger.info(
406-
"highlighted points on %s: %d"
407-
% (chr, sum([len(j["x"]) for i, j in traces.items()]))
408-
)
398+
logger.info("plotting %d traces on chrom %s" % (len_traces, chr))
409399

410400
bed_traces["chromosomes"] = chroms
411401
bed_traces["sex_chroms"] = sex_chroms

0 commit comments

Comments
 (0)