import re
import gzip


def open_input(filename, mode='r'):
    """Transparently open input files, whether plain text or gzip"""
    if re.match(r'.*\.gz$', filename) is None:
        # no .gz extension, assume a plain text file
        return open(filename, mode)
    else:
        # got a gzipped file
        return gzip.open(filename, mode + 'b')