Skip to content

Commit

Permalink
Fix issue #69
Browse files Browse the repository at this point in the history
  • Loading branch information
lpantano committed Nov 4, 2021
1 parent e87964c commit 007f7b5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 22 deletions.
53 changes: 31 additions & 22 deletions mirtop/bam/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def tune(seq, precursor, start, cigar):
cigar (str): updated cigar
"""

end = len(seq)
if start < 0:
end = end + start
Expand All @@ -43,41 +44,49 @@ def tune(seq, precursor, start, cigar):
if seq.endswith("-"):
seq = seq[:-1]
logger.debug("TUNE:: %s %s %s" % (cigar, seq, mature))
subs, add = [], []

if seq == mature:
logger.debug("TUNE:: %s %s" % (subs, add))
return subs, "".join(add), make_cigar(seq, mature)

error = set()
for pos in range(0, len(seq)):
if seq[pos] != mature[pos]:
error.add(pos)

subs, add = [], []

prob = 0
add_position = []
for e in range(len(seq) - 1, len(seq) - 6, -1):
if e in error:
prob = 1
if prob == 1:
add.append(seq[e])
add_position.append(e)
if e not in error and prob == 0 and seq[e] in ["A", "T"]:
add.append(seq[e])
add_position.append(e)
continue
if e not in error:
if add:
add.pop()
add_position.pop()
if prob == 0:
add = []
add_position = []
break
positions_to_look = [*range(len(seq) - 1, len(seq) - 6, -1)]
is_overlapped = len([value for value in error if value in positions_to_look])
if is_overlapped:
for e in positions_to_look:
if e in error:
prob = 1
if prob == 1:
add.append(seq[e])
add_position.append(e)
if e not in error and prob == 0 and seq[e] in ["A", "T"]:
add.append(seq[e])
add_position.append(e)
continue
if e not in error:
if add:
add.pop()
add_position.pop()
if prob == 0:
add = []
add_position = []
break

for e in error:
if e not in add_position:
subs.append([e, seq[e], mature[e]])

if not error:
add = []

logger.debug("TUNE:: %s %s" % (subs, add))

return subs, "".join(add), make_cigar(seq, mature)


Expand Down
10 changes: 10 additions & 0 deletions test/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ def test_variant(self):
"iso_5p:+2,iso_3p:-2,iso_add3p:2")
if res:
raise ValueError("Wrong alignment for test 8 %s" % res)


@attr(alignment=True)
def test_alignment(self):
Expand Down Expand Up @@ -528,3 +529,12 @@ def test_update(self):
from mirtop.gff.update import update_file
print("\n")
update_file("data/examples/versions/version1.0.gff", None)

@attr(error69=True)
def test_error69(self):
from mirtop.bam.filter import tune
v = tune("CTTATCAGATTGTATTGTAATT",
"TACATCGGCCATTATAATACAACCTGATAAGTGTTATAGCACTTATCAGATTGTATTGTAATTGTCTGTGTANNNNNNNNNNNN",
41, [(0, 22)])
if v[2] != "22M":
raise ValueError("Issue 69 is back. Variantion not detected correctly.")

0 comments on commit 007f7b5

Please sign in to comment.