Skip to content

Commit

Permalink
Add main entry to find_maximum_overlap script
Browse files Browse the repository at this point in the history
  • Loading branch information
Donaim committed Dec 24, 2024
1 parent a063ac6 commit 4708aab
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 11 deletions.
1 change: 1 addition & 0 deletions micall/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"micall/monitor/update_qai.py",
"micall/monitor/micall_watcher.py",
"micall/tcr/igblast.py",
"micall/utils/find_maximum_overlap.py",
]


Expand Down
24 changes: 13 additions & 11 deletions micall/tests/test_find_maximum_overlap.py
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
27 changes: 27 additions & 0 deletions micall/utils/find_maximum_overlap.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#! /usr/bin/env python

import argparse
import sys
import numpy as np
from typing import Sequence
from itertools import chain
Expand Down Expand Up @@ -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:]))

0 comments on commit 4708aab

Please sign in to comment.