Commit 0f5fa6f7 authored by Nicolas  MAILLET's avatar Nicolas MAILLET
Browse files

Correct bug when several rules apply at same time

parent d2dda0e8
......@@ -243,13 +243,14 @@ def one_digest(pep, enz):
ret.inc_nb_cleavage()
# current position
previous_pos = pos
# Default: do not cut this position
cut = False
before = True
# Check each rules
for rul in enz.rules:
# Default: do not cut this position
cut = None
# Apply the rule: if we need to cut
if rule.handle_rule(pep.sequence, pos, rul, cut):
cut = rule.handle_rule(pep.sequence, pos, rul, cut)
if cut is True:
# Random to handle miscleavage
tmp_rand = random.random() * 100
# Rand > ratio_miscleavage, no miscleavage occurs
......
......@@ -786,7 +786,7 @@ def handle_rule(seq, pos, a_rule, cut):
:type cut: bool
:return: `True` if sequence must be cutted
:rtype: bool
:rtype: bool or None
"""
# return of the function: should we cut this?
......@@ -799,11 +799,28 @@ def handle_rule(seq, pos, a_rule, cut):
# If the rule applies, i.e. the letter to watch is the good one
if (pos + a_rule.index) >= 0 and \
seq[pos + a_rule.index] == a_rule.letter:
ret = a_rule.cut
# Handle the rules (exceptions)
for rul in a_rule.rules:
# Apply the rule: do we need to cut?
ret = handle_rule(seq, pos, rul, ret)
# If no previous 'False' and this is cutting
if a_rule.cut and ret is not False:
ret = True
# Handle the sub-rules (exceptions)
for rul in a_rule.rules:
# Apply the rule: do we need to cut?
ret = handle_rule(seq, pos, rul, ret)
# Is is not cutting
elif not a_rule.cut:
# Reinit
ret = None
# Handle sub-rules
if a_rule.rules:
# Handle the rules (exceptions)
for rul in a_rule.rules:
# Apply the rule: do we need to cut?
ret = handle_rule(seq, pos, rul, ret)
# No sub-rules and not cutting
else:
# We are at the end a of rule that applies
# and say to NOT cut. So it will never cut.
ret = False
# Doesn't work: begin or end of sequence, don't change cut value
except IndexError:
pass
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment