Skip to content

Commit

Permalink
introduce base index for x-axis when using fixed_width (molecule_scale)
Browse files Browse the repository at this point in the history
  • Loading branch information
hiruna72 committed Feb 12, 2024
1 parent 80cc9de commit fed2b8f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
13 changes: 12 additions & 1 deletion src/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""
import numpy as np
from bokeh.plotting import figure, show, output_file, save
from bokeh.models import BoxAnnotation, HoverTool, WheelZoomTool, ColumnDataSource, Label, LabelSet, Segment, Toggle, Range1d, FreehandDrawTool, CustomJS
from bokeh.models import BoxAnnotation, HoverTool, WheelZoomTool, ColumnDataSource, Label, LabelSet, Segment, Toggle, Range1d, FreehandDrawTool, CustomJS, FixedTicker
from bokeh.layouts import row
from bokeh.colors import RGB
from bokeh.io import export_svg, export_svgs
Expand Down Expand Up @@ -398,6 +398,17 @@ def plot_function_fixed_width(p, read_id, signal_tuple, sig_algn_data, fasta_seq
p.add_layout(move_annotation_labels)

p.line('x', 'y', name="sig_plot_line", line_width=2, source=source)

xticks = [i*draw_data["fixed_base_width"] for i in range(0, base_index+1, 5)]
mxticks = [i*draw_data["fixed_base_width"] for i in range(0, base_index, 1)]
xticks_dic = {}
j = 0
for i in xticks:
xticks_dic[i] = str(j)
j += 5
p.xaxis.major_label_overrides = xticks_dic
p.xaxis.ticker = FixedTicker(ticks=xticks, minor_ticks=mxticks)

# add a circle renderer with a size, color, and alpha
sample_labels = p.circle(fixed_width_x[:x_coordinate], y[:x_coordinate], radius=draw_data["point_size"], color=sample_label_colors, alpha=0.5, visible=draw_data['no_samples'])
toggle_samples = Toggle(label="samples", button_type="danger", active=True, height=30, width=60)
Expand Down
13 changes: 12 additions & 1 deletion src/plot_pileup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""
import numpy as np
from bokeh.plotting import figure, show, output_file, save
from bokeh.models import HoverTool, WheelZoomTool, ColumnDataSource, Label, LabelSet, Segment, Arrow, NormalHead, FreehandDrawTool, Range1d, CustomJS
from bokeh.models import HoverTool, WheelZoomTool, ColumnDataSource, Label, LabelSet, Segment, Arrow, NormalHead, FreehandDrawTool, Range1d, CustomJS, FixedTicker
from bokeh.layouts import column
from bokeh.colors import RGB
from bokeh.io import export_svg
Expand Down Expand Up @@ -217,6 +217,17 @@ def plot_function_fixed_width_pileup(read_id, signal_tuple, sig_algn_data, fasta
if num_plots == 0:
sample_label_colors_insert[0] = 'purple'
sample_label_colors_match[0] = 'red'

xticks = [i*draw_data["fixed_base_width"] for i in range(0, base_index+1, 5)]
mxticks = [i*draw_data["fixed_base_width"] for i in range(0, base_index, 1)]
xticks_dic = {}
j = 0
for i in xticks:
xticks_dic[i] = str(j)
j += 5
p.xaxis.major_label_overrides = xticks_dic
p.xaxis.ticker = FixedTicker(ticks=xticks, minor_ticks=mxticks)

sample_labels_match = p.circle(fixed_width_x[:x_coordinate], y[:x_coordinate]+y_shift, radius=draw_data["point_size"], color=sample_label_colors_match, alpha=0.5, legend_label='match', visible=False)
sample_labels_insert = p.circle(fixed_width_x[:x_coordinate], y[:x_coordinate]+y_shift, radius=draw_data["point_size"], color=sample_label_colors_insert, alpha=0.5, legend_label='insertion', visible=False)

Expand Down
5 changes: 4 additions & 1 deletion src/plot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,13 @@ def create_figure(args, plot_mode):
p_defualt = None
if plot_mode == 0:
y_axis_label = "signal value (raw)"
x_axis_label = "signal value (raw)"
if args.fixed_width:
x_axis_label = "base index"
if args.no_pa:
y_axis_label = "signal value (pA)"
tools_to_show = 'hover,box_zoom,pan,reset,save,wheel_zoom,zoom_in,zoom_out'
p_default = figure(x_axis_label='signal index',
p_default = figure(x_axis_label=x_axis_label,
y_axis_label=y_axis_label,
sizing_mode="stretch_width",
height=PLOT_HEIGHT,
Expand Down

0 comments on commit fed2b8f

Please sign in to comment.