<reponame>ilaydabozan/biofx_python<filename>08_subs/solution4_kmers_imperative.py
#!/usr/bin/env python3
""" Find subsequences """

import argparse
from typing import NamedTuple


class Args(NamedTuple):
    """ Command-line arguments """
    seq: str
    subseq: str


# --------------------------------------------------
def get_args() -> Args:
    """ Get command-line arguments """

    parser = argparse.ArgumentParser(
        description='Find subsequences',
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument('seq', metavar='seq', help='Sequence')

    parser.add_argument('subseq', metavar='subseq', help='Sub-sequence')

    args = parser.parse_args()

    return Args(args.seq, args.subseq)


# --------------------------------------------------
def main() -> None:
    """ Make a jazz noise here """

    args = get_args()
    seq, subseq = args.seq, args.subseq
    k = len(subseq)
    kmers = [seq[i:i + k] for i in range(len(seq) - k + 1)]
    found = [i + 1 for i, kmer in enumerate(kmers) if kmer == subseq]
    print(*found)


# --------------------------------------------------
if __name__ == '__main__':
    main()

#!/usr/bin/env python3
""" Find subsequences """

import argparse
from typing import NamedTuple


class Args(NamedTuple):
    """ Command-line arguments """
    seq: str
    subseq: str


# --------------------------------------------------
def get_args() -> Args:
    """ Get command-line arguments """

    parser = argparse.ArgumentParser(
        description='Find subsequences',
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument('seq', metavar='seq', help='Sequence')

    parser.add_argument('subseq', metavar='subseq', help='Sub-sequence')

    args = parser.parse_args()

    return Args(args.seq, args.subseq)


# --------------------------------------------------
def main() -> None:
    """ Make a jazz noise here """

    args = get_args()
    seq, subseq = args.seq, args.subseq
    k = len(subseq)
    kmers = [seq[i:i + k] for i in range(len(seq) - k + 1)]
    found = [i + 1 for i, kmer in enumerate(kmers) if kmer == subseq]
    print(*found)


# --------------------------------------------------
if __name__ == '__main__':
    main()
#!/usr/bin/env python3 Find subsequences Command-line arguments # -------------------------------------------------- Get command-line arguments # -------------------------------------------------- Make a jazz noise here # --------------------------------------------------