Skip to content

Commit

Permalink
bed annotation supports positive base shift
Browse files Browse the repository at this point in the history
  • Loading branch information
hiruna72 committed Jan 30, 2024
1 parent 7d1ec0f commit 7ae881c
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 7 deletions.
34 changes: 31 additions & 3 deletions src/bed_annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,37 @@ def draw_bed_annotation(p, bed_content, sig_algn_data, draw_data, base_limit, tr
annotation_box_details = {'left': [], 'right': [], 'fill_color': []}
annotation_label = []
annotation_label_x = []
location_plot = 0
x_coordinate = 0
initial_x_coordinate = x_coordinate

initial_location_plot = 0
if draw_data["base_shift"] > 0:
abs_base_shift = abs(draw_data["base_shift"])
count_bases = 0
for i in moves:
if 'D' in i:
i = re.sub('D', '', i)
if count_bases + int(i) > abs_base_shift:
initial_location_plot += (abs_base_shift - count_bases) * draw_data["fixed_base_width"]
break
initial_location_plot += int(i) * draw_data["fixed_base_width"]
count_bases += int(i)
elif 'I' in i:
i = re.sub('I', '', i)
if draw_data['fixed_width']:
pass
else:
initial_location_plot += int(i)
else:
if draw_data['fixed_width']:
initial_location_plot += draw_data["fixed_base_width"]
else:
initial_location_plot += int(i)
count_bases += 1
if count_bases == abs_base_shift:
break

initial_x_coordinate = 0
x_coordinate = initial_x_coordinate
location_plot = initial_location_plot
flag_base_index_bound = 0

bed_index = 0
Expand Down
4 changes: 3 additions & 1 deletion src/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ def get_metric(args, fout, metric_record, read_id, signal_tuple, sig_algn_data,
break
if x_coordinate - initial_x_coordinate > draw_data["sig_plot_limit"]:
break
signal_start = abs(draw_data["base_shift"]) * draw_data["fixed_base_width"]
signal_start = initial_x_coordinate
if draw_data["base_shift"] < 0:
signal_start = abs(draw_data["base_shift"]) * draw_data["fixed_base_width"]
if sig_algn_data["data_is_rna"] == 1:
ref_region = "{}:{}-{}".format(sig_algn_data["ref_name"], sig_algn_data["ref_end"], sig_algn_data["ref_end"] - base_index+1)
signal_region = "{}-{}".format(x_real[signal_start], x_real[x_coordinate - 1])
Expand Down
8 changes: 6 additions & 2 deletions src/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@ def plot_function(p, read_id, signal_tuple, sig_algn_data, fasta_sequence, base_
hover.mode = 'mouse'

indt = "\t\t\t\t\t\t\t\t"
signal_start = abs(draw_data["base_shift"]) * draw_data["fixed_base_width"]
signal_start = initial_x_coordinate
if draw_data["base_shift"] < 0:
signal_start = abs(draw_data["base_shift"]) * draw_data["fixed_base_width"]
if sig_algn_data["data_is_rna"] == 1:
plot_title = f'{sig_algn_data["tag_name"]}[{sig_algn_data["ref_end"]:,}-{sig_algn_data["ref_end"] - base_index+1:,}]{indt}signal: [{int(x_real[signal_start])}-{int(x_real[x_coordinate - 1])}]{indt}deletions(bases): {num_Ds} insertions(samples): {num_Is}{indt}{read_id}{indt}signal dir:{draw_data["sig_dir"]}'
else:
Expand Down Expand Up @@ -407,7 +409,9 @@ def plot_function_fixed_width(p, read_id, signal_tuple, sig_algn_data, fasta_seq
hover.tooltips = [("x", "@x_real"), ("y", "@y")]
hover.mode = 'mouse'
indt = "\t\t\t\t\t\t\t\t"
signal_start = abs(draw_data["base_shift"]) * draw_data["fixed_base_width"]
signal_start = initial_x_coordinate
if draw_data["base_shift"] < 0:
signal_start = abs(draw_data["base_shift"]) * draw_data["fixed_base_width"]
if sig_algn_data["data_is_rna"] == 1:
plot_title = f'{sig_algn_data["tag_name"]}[{sig_algn_data["ref_end"]:,}-{sig_algn_data["ref_end"] - base_index+1:,}]{indt}signal: [{int(x_real[signal_start])}-{int(x_real[x_coordinate - 1])}]{indt}deletions(bases): {num_Ds} insertions(samples): {num_Is}{indt}{read_id}{indt}signal dir:{draw_data["sig_dir"]}'
else:
Expand Down
4 changes: 3 additions & 1 deletion src/plot_pileup.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,9 @@ def plot_function_fixed_width_pileup(read_id, signal_tuple, sig_algn_data, fasta

signal_region = ""
indels = f'deletions(bases): {num_Ds} insertions(samples): {num_Is}'
signal_start = abs(draw_data["base_shift"]) * draw_data["fixed_base_width"]
signal_start = initial_x_coordinate
if draw_data["base_shift"] < 0:
signal_start = abs(draw_data["base_shift"]) * draw_data["fixed_base_width"]
signal_region = f'[{int(x_real[signal_start])}-{int(x_real[x_coordinate - 1])}]'
y_plot = y[:x_coordinate]+y_shift
y_median = np.nanmedian(y_plot)
Expand Down
4 changes: 4 additions & 0 deletions src/plot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ def adjust_before_plotting(ref_seq_len, signal_tuple, region_tuple, sig_algn_dat
moves_prefix = [str(draw_data["fixed_base_width"])] * abs_base_shift
sig_algn_data['ss'] = moves_prefix + sig_algn_data['ss']

base_shift_seq = 'N' * draw_data['base_shift']
if draw_data["base_shift"] > 0:
fasta_seq = base_shift_seq + fasta_seq[:-1*draw_data["base_shift"]]

return signal_tuple, region_tuple, sig_algn_data, fasta_seq
def create_figure(args, plot_mode):
p_defualt = None
Expand Down

0 comments on commit 7ae881c

Please sign in to comment.