From fed2b8fecbdde6f3bd64ef9b23513e6c6edab4e7 Mon Sep 17 00:00:00 2001 From: hiruna72 Date: Mon, 12 Feb 2024 23:41:21 +1100 Subject: [PATCH] introduce base index for x-axis when using fixed_width (molecule_scale) --- src/plot.py | 13 ++++++++++++- src/plot_pileup.py | 13 ++++++++++++- src/plot_utils.py | 5 ++++- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/plot.py b/src/plot.py index abaee38..d769463 100644 --- a/src/plot.py +++ b/src/plot.py @@ -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 @@ -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) diff --git a/src/plot_pileup.py b/src/plot_pileup.py index b70a064..4602294 100644 --- a/src/plot_pileup.py +++ b/src/plot_pileup.py @@ -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 @@ -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) diff --git a/src/plot_utils.py b/src/plot_utils.py index a5e6bab..d2a0a9b 100644 --- a/src/plot_utils.py +++ b/src/plot_utils.py @@ -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,