def get_delim(fn):
    """
    Get the expected delimiter for a data file based on the extension of the filename:
        ','   .csv
        '\t'  .tsv .tab
        ' '   otherwise
    The filename may also have a .gz or .bz2 extension which will be ignored.
    """
    fn = fn.lower()
    if   fn.endswith('.gz'): fn = fn[:-3]
    elif fn.endswith('.bz2'): fn = fn[:-4]
    if fn.endswith('.csv'): return ','
    if fn.endswith('.tsv') or fn.endswith('.tab'): return '\t'
    return ' '