Commit 30fc5fd9 authored by Pauline Pommeret's avatar Pauline Pommeret
Browse files

[trx] local_match works with len(string) == 2|4

parent 867a311d
......@@ -9,25 +9,31 @@ XXX
def local_match(string, TRX):
"""
Tries to match ``string`` (a 4 letter long string) with the patterns in
``TRX`` (TRX scale dictionary).
Tries to match ``string`` (a 2 or 4 letter long string) with the patterns
in ``TRX`` (TRX scale dictionary).
Returns the value associated to ``string`` or raises a NoMatch Exception
"""
potential = []
# Iteration on the keys of the TRX dictionary
for pattern in TRX.keys():
# Test whether the 2 central nucleotides are in the pattern
if re.search(string[1:3], pattern):
# Only one pattern 2 letters long is possible and it must be kept
# in case the tetranucleotides don't match the whole string
if len(pattern) == 2:
potential.append(pattern)
# Only one 4 letters long pattern is possible.
elif re.search(string[0], pattern[1:3]) and re.search(string[-1], pattern[7:9]):
if len(string) == 4:
# Iteration on the keys of the TRX dictionary
for pattern in TRX.keys():
# Test whether the 2 central nucleotides are in the pattern
if re.search(string[1:3], pattern):
# Only one pattern 2 letters long is possible and it must be kept
# in case the tetranucleotides don't match the whole string
if len(pattern) == 2:
potential.append(pattern)
# Only one 4 letters long pattern is possible.
elif re.search(string[0], pattern[1:3]) and re.search(string[-1], pattern[7:9]):
potential.append(pattern)
elif len(string) == 2:
# Iteration on the keys of the TRX dictionary which have a length equal 2
for pattern in [i for i in TRX.keys() if len(i)==2]:
if re.search(string, pattern):
potential.append(pattern)
if not potential:
# If the potential list is empty, clearly something gone wrong
raise NoMatch("No match found, please check your sequence and TRX scale.")
......@@ -37,4 +43,8 @@ def local_match(string, TRX):
return TRX[max(potential)]
def match():
"""
"""
Markdown is supported
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