def get_open_func(fn, return_fmt=False):
    """Get the opening function.

    Args:
        fn (str): the name of the file.
        return_fmt (bool): if the file format needs to be returned.

    Returns:
        tuple: either a tuple containing two elements: a boolean telling if the
        format is bgzip, and the opening function.

    """
    # The file might be compressed using bgzip
    bgzip = None
    with open(fn, "rb") as i_file:
        bgzip = i_file.read(3) == b"\x1f\x8b\x08"

    if bgzip and not HAS_BIOPYTHON:
        raise ValueError("needs BioPython to index a bgzip file")

    open_func = open
    if bgzip:
        open_func = BgzfReader

    # Trying to read
    try:
        with open_func(fn, "r") as i_file:
            if bgzip:
                if not i_file.seekable():
                    raise ValueError
            pass

    except ValueError:
        raise ValueError("{}: use bgzip for compression...".format(fn))

    if return_fmt:
        return bgzip, open_func

    return open_func
Get the opening function.

    Args:
        fn (str): the name of the file.
        return_fmt (bool): if the file format needs to be returned.

    Returns:
        tuple: either a tuple containing two elements: a boolean telling if the
        format is bgzip, and the opening function.