Skip to content

Commit

Permalink
updates trace colors, logging message
Browse files Browse the repository at this point in the history
  • Loading branch information
brwnj committed Jan 24, 2020
1 parent f862ec0 commit eeeaf06
Showing 1 changed file with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions covviz/bed.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import numpy as np
import pandas as pd

from .utils import gzopen, merge_intervals
from .utils import COLORS, gzopen, merge_intervals

try:
from itertools import ifilterfalse as filterfalse
Expand Down Expand Up @@ -254,18 +254,8 @@ def parse_bed(
# chromosomes, in order of appearance
chroms = list()
samples = list()
plotly_colors = [
"#1f77b4", # muted blue
"#ff7f0e", # safety orange
"#2ca02c", # cooked asparagus green
"#d62728", # brick red
"#9467bd", # muted purple
"#8c564b", # chestnut brown
"#e377c2", # raspberry yogurt pink
"#7f7f7f", # middle gray
"#bcbd22", # curry yellow-green
"#17becf", # blue-teal
]
sample_trace_color = dict()

sex_chroms = [i.strip("chr") for i in sex_chroms.split(",")]

groups = None
Expand Down Expand Up @@ -298,6 +288,9 @@ def parse_bed(
for x_index, row in enumerate(entries):
if not samples:
samples = [i for i in sorted(row.keys()) if i not in header[:3]]
# plot outlier traces across chromosomes with the same color for a given sample
for sample_index, sample in enumerate(samples):
sample_trace_color[sample] = COLORS[sample_index % len(COLORS)]
if groups:
valid = validate_samples(samples, groups)
if not valid:
Expand Down Expand Up @@ -384,7 +377,8 @@ def parse_bed(
trace["fillcolor"] = fill_color
json_output.append(trace)
# add the sample traces for the outlier plots atop area traces
for trace_index, (sample, trace_data) in enumerate(traces.items()):
len_traces = 0
for sample, trace_data in traces.items():
trace = dict(
x=trace_data["x"],
y=trace_data["y"],
Expand All @@ -394,18 +388,14 @@ def parse_bed(
mode="lines",
name="significant",
# include color as primary colors occupied by area traces
marker={
"width": 1,
"color": plotly_colors[trace_index % len(plotly_colors)],
},
marker={"width": 1, "color": sample_trace_color[sample]},
)
if trace_data["x"]:
len_traces += 1
json_output.append(trace)

bed_traces[chrom] = json_output
logger.info(
"highlighted points on %s: %d"
% (chr, sum([len(j["x"]) for i, j in traces.items()]))
)
logger.info("plotting %d traces on chrom %s" % (len_traces, chr))

bed_traces["chromosomes"] = chroms
bed_traces["sex_chroms"] = sex_chroms
Expand Down

0 comments on commit eeeaf06

Please sign in to comment.