import gzip


def write_fastq(filename):
    """
    return a handle for FASTQ writing, handling gzipped files
    """
    if filename:
        if filename.endswith('gz'):
            filename_fh = gzip.open(filename, mode='wt')
        else:
            filename_fh = open(filename, mode='w')
    else:
        filename_fh = None
    return filename_fh