def count_comments(filename):
    """Count comment lines (those that start with "#") in an optionally
	gzipped file.
	:param filename:  An optionally gzipped file.
	modified from: https://gist.github.com/slowkow/6215557
	"""
    comments = 0

    # fn_open = gzip.open if filename.endswith('.gz') else open
    # with fn_open(filename) as fh:
    for line in filename:
        if line.startswith('#'):
            comments += 1
            #print(line)
        else:

            break

    return comments