def _check_delimiter(output_filename, delim=None):
    """Detect delimiter by filename extension if not set"""
    if output_filename and (delim is None):
        delimiters = {"tsv": "\t", "csv": ","}
        delim = delimiters[output_filename.rsplit(".", 1)[-1].lower()]
        assert delim, "File output delimiter not known. Cannot proceed."

    return delim