Skip to content

Commit

Permalink
signal to read changes
Browse files Browse the repository at this point in the history
  • Loading branch information
hiruna72 committed Mar 5, 2024
1 parent f2b5283 commit d2d97ca
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 66 deletions.
11 changes: 9 additions & 2 deletions src/calculate_offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ def run(args):
model_ = obj[header_line_count:]
for line in model_:
values_ = line.split('\t')
values_[0] = values_[0].replace('U', 'T')
model[values_[0]] = float(values_[1])
test_array = []
for base_offset in range(0, kmer_length):
Expand All @@ -217,11 +218,17 @@ def run(args):
max_offset, max_dist = calculate_distance(kmer_length, test_array)
forward_shift = -1 * max_offset
reverse_shift = -1 * (kmer_length - max_offset - 1)
print("kmer length: {}\nbest base shift (offset) for forward mapped reads: {}\nbest base shift (offset) for reverse mapped reads: {}\ndifference between highest and lowest medians of the distributions: {}".format(kmer_length, forward_shift, reverse_shift, round(max_dist, 4)))
if args.rna:
print("RNA\nkmer length: {}\nbest base shift (offset) for forward mapped reads: {}\nbest base shift (offset) for reverse mapped reads: {}\ndifference between highest and lowest medians of the distributions: {}".format(kmer_length, reverse_shift, forward_shift, round(max_dist, 4)))
else:
print("DNA\nkmer length: {}\nbest base shift (offset) for forward mapped reads: {}\nbest base shift (offset) for reverse mapped reads: {}\ndifference between highest and lowest medians of the distributions: {}".format(kmer_length, forward_shift, reverse_shift, round(max_dist, 4)))
if args.output != "":
output_pdf = PdfPages(args.output)
print("output file: {}".format(args.output))
plt_title = "{}\nkmer length: {}\ndifference between highest and lowest medians of the distributions: {}\nbest base shift (offset) for forward mapped reads (shown below): {}\nbest base shift (offset) for reverse mapped reads (derived): {}\n".format(args.tag_name, kmer_length, str(round(max_dist, 4)), forward_shift, reverse_shift)
if args.rna:
plt_title = "RNA\n{}\nkmer length: {}\ndifference between highest and lowest medians of the distributions: {}\nbest base shift (offset) for forward mapped reads (derived): {}\nbest base shift (offset) for reverse mapped reads (shown below): {}\n".format(args.tag_name, kmer_length, str(round(max_dist, 4)), reverse_shift, forward_shift)
else:
plt_title = "DNA\n{}\nkmer length: {}\ndifference between highest and lowest medians of the distributions: {}\nbest base shift (offset) for forward mapped reads (shown below): {}\nbest base shift (offset) for reverse mapped reads (derived): {}\n".format(args.tag_name, kmer_length, str(round(max_dist, 4)), forward_shift, reverse_shift)
plot_distributions(kmer_length, test_array, output_pdf, plt_title)
output_pdf.close()
else:
Expand Down
32 changes: 32 additions & 0 deletions src/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,17 @@ def run(args):
if i < len(ref_pos_dic) - 1:
print("\t", end="")
print()
if args.output_current_1:
for i in range(0, len(ref_pos_dic)):
sublist = ref_pos_dic[i]
if not any(np.isnan(x) for x in sublist) and len(sublist) > 0:
rounded_sublist = [round(x, 2) for x in sublist]
print(",".join(map(str, rounded_sublist)), end="")
else:
continue
if i < len(ref_pos_dic) - 1:
print(",", end="")
print()
if args.output_current_column:
for i in range(0, len(ref_pos_dic)):
sublist = ref_pos_dic[i]
Expand Down Expand Up @@ -846,6 +857,26 @@ def run(args):
if i < len(ref_pos_dic) - 1:
print("\t", end="")
print()
if args.output_current_1:
for i in range(0, len(ref_pos_dic)):
sublist = ref_pos_dic[i]
if not any(np.isnan(x) for x in sublist) and len(sublist) > 0:
rounded_sublist = [round(x, 2) for x in sublist]
print(",".join(map(str, rounded_sublist)), end="")
else:
continue
if i < len(ref_pos_dic) - 1:
print(",", end="")
print()
if args.output_current_column:
for i in range(0, len(ref_pos_dic)):
sublist = ref_pos_dic[i]
if not any(np.isnan(x) for x in sublist) and len(sublist) > 0:
rounded_sublist = [round(x, 2) for x in sublist]
if i in column_raw_samples:
column_raw_samples[i] += rounded_sublist
else:
column_raw_samples[i] = rounded_sublist
else:
raise Exception("Error: You should not have ended up here. Please check your arguments")

Expand Down Expand Up @@ -897,6 +928,7 @@ def argparser():
parser.add_argument('--extend_0', required=False, action='store_true', help="print matches, deletions, insertions arrays")
parser.add_argument('--extend_1', required=False, action='store_true', help="print ss string for the given region")
parser.add_argument('--output_current', required=False, action='store_true', help="print signal values")
parser.add_argument('--output_current_1', required=False, action='store_true', help="print signal values without any nans/tabs")
parser.add_argument('--output_current_column', required=False, action='store_true', help="print signal values per column")
return parser

Expand Down
Loading

0 comments on commit d2d97ca

Please sign in to comment.