import re


def findReadPosition(fullAssembly, read, label=''):
    """Finds the index of a given target (read) inside the context (fullAssembly)

        ========================================= context
                  --------------                  target
                  ^            ^
            startIndex       endIndex

    Args:
        fullAssembly (string): String of context
        read (string): String target
        label (string, optional): Label of string target (for logging)

    Returns:
        :obj:`tuple` of (
            startIndex (int): The start index of the target in the context
            endIndex (int): The end index of the target in the context
        )

    Raises:
        AssertionError: When the target is not found in the context
    """
    matchIndices = [
        (match.start(), match.end())
        for match in re.finditer(read, fullAssembly)
    ]

    try:
        assert(len(matchIndices) > 0)
    except AssertionError:
        raise Exception('\033[41mERROR\033[0m: Found NO match for read (\033[94m%s\033[0m) in assembled result.' % label)

    return matchIndices