diff --git a/micall/main.py b/micall/main.py index d1c86f6a8..38f3ae176 100644 --- a/micall/main.py +++ b/micall/main.py @@ -88,6 +88,7 @@ "micall/monitor/update_qai.py", "micall/monitor/micall_watcher.py", "micall/tcr/igblast.py", + "micall/utils/find_maximum_overlap.py", ] diff --git a/micall/tests/test_find_maximum_overlap.py b/micall/tests/test_find_maximum_overlap.py index e96ceae7e..73b724e49 100644 --- a/micall/tests/test_find_maximum_overlap.py +++ b/micall/tests/test_find_maximum_overlap.py @@ -1,5 +1,5 @@ import pytest -from micall.utils.find_maximum_overlap import find_maximum_overlap, show_maximum_overlap +from micall.utils.find_maximum_overlap import find_maximum_overlap, show_maximum_overlap, cli_main @pytest.mark.parametrize( @@ -27,8 +27,7 @@ def test_maximum_overlap_cases(left, right, expected): find_maximum_overlap(left, right) -@pytest.mark.parametrize( - "left, right, expected", +print_cases = \ [ ('tttttxxxxx', 'uuuuuxxx', '''\ tttttxxxxx @@ -67,15 +66,18 @@ def test_maximum_overlap_cases(left, right, expected): tttttxxxxpppppppppppppppppppp----------- ------xxxuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu '''), - ], -) +] + + +@pytest.mark.parametrize("left, right, expected", print_cases) def test_print(left, right, expected): shift = find_maximum_overlap(left, right) ret = show_maximum_overlap(left, right, shift) - if ret != expected: - print() - print() - print(ret) - print() - print() + assert ret == expected + + +@pytest.mark.parametrize("left, right, expected", print_cases) +def test_main(left, right, expected, capsys): + cli_main([left, right]) + ret = capsys.readouterr().out assert ret == expected diff --git a/micall/utils/find_maximum_overlap.py b/micall/utils/find_maximum_overlap.py index eeb271dbc..14ec227bd 100644 --- a/micall/utils/find_maximum_overlap.py +++ b/micall/utils/find_maximum_overlap.py @@ -1,4 +1,7 @@ +#! /usr/bin/env python +import argparse +import sys import numpy as np from typing import Sequence from itertools import chain @@ -85,3 +88,27 @@ def show_maximum_overlap(arr1: Sequence[object], for x in [arr1_line, arr2_line]) return '\n'.join(chain(lines, [''])) + + +def main(seq1: str, seq2: str) -> int: + shift = find_maximum_overlap(seq1, seq2) + ret = show_maximum_overlap(seq1, seq2, shift) + print(ret, end='') + return 0 + + +def get_parser() -> argparse.ArgumentParser: + parser = argparse.ArgumentParser("Find maximum overlap between two sequences.") + parser.add_argument('seq1') + parser.add_argument('seq2') + return parser + + +def cli_main(argv: Sequence[str]) -> int: + parser = get_parser() + args = parser.parse_args(argv) + return main(args.seq1, args.seq2) + + +if __name__ == '__main__': + sys.exit(cli_main(sys.argv[1:]))