<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def collapse(in_file):
 """collapse identical sequences and keep Q"""

    keep = Counter()
    with open_fastq(in_file) as handle:
        for line in handle:
            if line.startswith("@"):
                if line.find("UMI") > -1:
                    logger.info("Find UMI tags in read names, collapsing by UMI.")
                    return collapse_umi(in_file)
                seq = handle.next().strip()
                handle.next()
                qual = handle.next().strip()
                if seq in keep:
                    keep[seq].update(qual)
                else:
                    keep[seq] = quality(qual)
    logger.info("Sequences loaded: %s" % len(keep))
    return keep