From 7b48512613eb054d49469ff5172be32134252108 Mon Sep 17 00:00:00 2001 From: adamewing Date: Thu, 6 Jul 2023 14:58:48 +1000 Subject: [PATCH] handle cases where the read length is longer than the reference --- methylartist | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/methylartist b/methylartist index 27a4b40..bdf73e1 100755 --- a/methylartist +++ b/methylartist @@ -876,7 +876,13 @@ def parse_methbam(bam_fn, reads, chrom, start, end, motifsize=2, meth_thresh=0.8 genome_pos = None if rec.is_reverse: - genome_pos = ap[len(rec.seq)-base_pos[i]-1] + try: + genome_pos = ap[len(rec.seq)-base_pos[i]-1] + except IndexError: + if i >= len(base_pos): + genome_pos = None + else: + raise IndexError(".bam parsing error: position not in aligned pairs") if genome_pos is None: continue @@ -884,7 +890,14 @@ def parse_methbam(bam_fn, reads, chrom, start, end, motifsize=2, meth_thresh=0.8 genome_pos -= (int(motifsize)-1) else: - genome_pos = ap[base_pos[i]] + try: + genome_pos = ap[base_pos[i]] + + except IndexError: + if i >= len(base_pos): + genome_pos = None + else: + raise IndexError(".bam parsing error: position not in aligned pairs") if genome_pos is None: continue