Commit 07158c8d authored by Nicolas  MAILLET's avatar Nicolas MAILLET
Browse files

Modify output of __repr__ for a rule

parent 4e349d3d
......@@ -60,13 +60,13 @@ class Rule:
ret += "index=" + str(self.index) + "\n"
for _ in range(lvl):
ret += "\t"
ret += "letter=" + str(self.letter) + "\n"
ret += "amino_acid=" + str(self.letter) + "\n"
for _ in range(lvl):
ret += "\t"
ret += "cut=" + str(self.cut) + "\n"
ret += "cleavage=" + str(self.cut) + "\n"
for _ in range(lvl):
ret += "\t"
ret += "pos=" + str(self.pos) + "\n"
ret += "position=" + str(self.pos) + "\n"
# Sub-rules
for i in self.rules:
ret += str(i.__repr__(lvl + 1))
......
......@@ -64,21 +64,24 @@ def test_create_enzymes_to_use(capsys):
enzymes = [23, 31, 29]
miscleavage = [1.1, 20]
res = RapidPeptidesGenerator.create_enzymes_to_use(enzymes, miscleavage)
assert res.__repr__() == "[Id: 23\nName: Glu-C\nRatio Miscleavage: 1.1"\
"0%\nRules: [index=0\nletter=D\ncut=True\npos=1\n,"\
" index=0\nletter=E\ncut=True\npos=1\n]\n, Id: 31"\
"\nName: NTCB\nRatio Miscleavage: 20.00%\nRules"\
": [index=0\nletter=C\ncut=True\npos=0\n]\n, Id: "\
"29\nName: Lys-N\nRatio Miscleavage: 0.00%\nRul"\
"es: [index=0\nletter=K\ncut=True\npos=0\n]\n]"
assert res.__repr__() == "[Id: 23\nName: Glu-C\nRatio Miscleavage: 1.10%"\
"\nRules: [index=0\namino_acid=D\ncleavage=True"\
"\nposition=1\n, index=0\namino_acid=E\ncleavage"\
"=True\nposition=1\n]\n, Id: 31\nName: NTCB\nRat"\
"io Miscleavage: 20.00%\nRules: [index=0\namino_"\
"acid=C\ncleavage=True\nposition=0\n]\n, Id: 29"\
"\nName: Lys-N\nRatio Miscleavage: 0.00%\nRules:"\
" [index=0\namino_acid=K\ncleavage=True\npositio"\
"n=0\n]\n]"
enzymes = [23, 31]
miscleavage = [1.1, 20, 40]
res = RapidPeptidesGenerator.create_enzymes_to_use(enzymes, miscleavage)
_, err = capsys.readouterr()
assert err == "Warning: Too much miscleavage values. Last values will "\
"be ignored.\n"
assert res.__repr__() == "[Id: 23\nName: Glu-C\nRatio Miscleavage: 1.1"\
"0%\nRules: [index=0\nletter=D\ncut=True\npos=1\n,"\
" index=0\nletter=E\ncut=True\npos=1\n]\n, Id: 31"\
"\nName: NTCB\nRatio Miscleavage: 20.00%\nRules"\
": [index=0\nletter=C\ncut=True\npos=0\n]\n]"
assert res.__repr__() == "[Id: 23\nName: Glu-C\nRatio Miscleavage: 1.10%"\
"\nRules: [index=0\namino_acid=D\ncleavage=True"\
"\nposition=1\n, index=0\namino_acid=E\ncleavage"\
"=True\nposition=1\n]\n, Id: 31\nName: NTCB\nRat"\
"io Miscleavage: 20.00%\nRules: [index=0\namino_"\
"acid=C\ncleavage=True\nposition=0\n]\n]"
......@@ -17,9 +17,10 @@ def test_enzyme(tmpdir):
# Test function '__repr__()'
res = enz0.__repr__()
assert res == "Id: -1\nName: fake_enzyme1\nRatio Miscleavage: 0.00%\nR"\
"ules: [index=0\nletter=D\ncut=True\npos=1\n\tindex=-1\n\tl"\
"etter=S\n\tcut=False\n\tpos=-1\n]\n"
assert res == "Id: -1\nName: fake_enzyme1\nRatio Miscleavage: 0.00%\nRule"\
"s: [index=0\namino_acid=D\ncleavage=True\nposition=1\n\tin"\
"dex=-1\n\tamino_acid=S\n\tcleavage=False\n\tposition=-1\n]"\
"\n"
dict_rule = {}
rule_txt = "(D,)"
......
......@@ -15,7 +15,7 @@ def test_rule():
# Test function '__repr__()'
print_res = rule0.__repr__()
assert print_res == "index=0\nletter=D\ncut=True\npos=0\n"
assert print_res == "index=0\namino_acid=D\ncleavage=True\nposition=0\n"
# Simple rule1
index = 2
......@@ -24,7 +24,7 @@ def test_rule():
pos = 1
rule1 = rule.Rule(index, letter, cut, pos)
print_res = rule1.__repr__()
assert print_res == "index=2\nletter=Q\ncut=False\npos=1\n"
assert print_res == "index=2\namino_acid=Q\ncleavage=False\nposition=1\n"
# Simple rule2 identical to 1
index = 0
......@@ -40,8 +40,9 @@ def test_rule():
# Test __repr__
print_res = rule2.__repr__()
assert print_res == "index=0\nletter=D\ncut=True\npos=0\n\tindex=2"\
"\n\tletter=Q\n\tcut=False\n\tpos=1\n"
assert print_res == "index=0\namino_acid=D\ncleavage=True\nposition=0\n\t"\
"index=2\n\tamino_acid=Q\n\tcleavage=False\n\tpositio"\
"n=1\n"
# Test function '__ne__()'
assert rule0 != rule2
......@@ -72,19 +73,19 @@ def test_rule():
# Test function 'format_a_rule(prev_name, prev_com)'
res = rule2.format_a_rule(prev_name, prev_com)
assert res == ['D_0', ' # Always cleaves before D, except...',
'D_0 = rule.Rule(0, "D", True, 0) # Always cleaves before D, '
'except...']
'D_0 = rule.Rule(0, "D", True, 0) # Always cleaves before D'
', except...']
res = rule1.format_a_rule(prev_name, prev_com)
assert res == ['1Q2', ' # Never cleaves after Q, except...',
'1Q2 = rule.Rule(2, "Q", False, 1) # Never cleaves after Q, '
'except...']
'1Q2 = rule.Rule(2, "Q", False, 1) # Never cleaves after Q,'
' except...']
# Test function 'format_rule()'
res = rule2.format_rule()
assert res == 'D_0 = rule.Rule(0, "D", True, 0) # Always cleaves before D, ex'\
'cept...\nD_0Q2 = rule.Rule(2, "Q", False, 1) # Never cleaves b'\
'efore D, followed by Q, except...\nD_0.rules.append(D_0Q2)'\
'\nENZ.append(D_0)\n\n'
assert res == 'D_0 = rule.Rule(0, "D", True, 0) # Always cleaves before D'\
', except...\nD_0Q2 = rule.Rule(2, "Q", False, 1) # Never c'\
'leaves before D, followed by Q, except...\nD_0.rules.appen'\
'd(D_0Q2)\nENZ.append(D_0)\n\n'
def test_check_rule():
"""Test function 'check_rule(exprule)'."""
......@@ -374,7 +375,7 @@ def test_create_rules():
assert len(res) == 7
# Double comma and 'or'
# Cleaves after I or J, except if a K is after, but cleaves if a L is before
# Cleaves after I or J, except if K is after, but cleaves if a L is before
all_rules = {}
rule6 = "(,I or J,)"
all_rules[rule6] = True
......
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