8
8
import numpy as np
9
9
import pandas as pd
10
10
11
- from .utils import gzopen , merge_intervals
11
+ from .utils import COLORS , gzopen , merge_intervals
12
12
13
13
try :
14
14
from itertools import ifilterfalse as filterfalse
@@ -254,18 +254,8 @@ def parse_bed(
254
254
# chromosomes, in order of appearance
255
255
chroms = list ()
256
256
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
+
269
259
sex_chroms = [i .strip ("chr" ) for i in sex_chroms .split ("," )]
270
260
271
261
groups = None
@@ -298,6 +288,9 @@ def parse_bed(
298
288
for x_index , row in enumerate (entries ):
299
289
if not samples :
300
290
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 )]
301
294
if groups :
302
295
valid = validate_samples (samples , groups )
303
296
if not valid :
@@ -384,7 +377,8 @@ def parse_bed(
384
377
trace ["fillcolor" ] = fill_color
385
378
json_output .append (trace )
386
379
# 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 ():
388
382
trace = dict (
389
383
x = trace_data ["x" ],
390
384
y = trace_data ["y" ],
@@ -394,18 +388,14 @@ def parse_bed(
394
388
mode = "lines" ,
395
389
name = "significant" ,
396
390
# 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 ]},
401
392
)
393
+ if trace_data ["x" ]:
394
+ len_traces += 1
402
395
json_output .append (trace )
403
396
404
397
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 ))
409
399
410
400
bed_traces ["chromosomes" ] = chroms
411
401
bed_traces ["sex_chroms" ] = sex_chroms
0 commit comments