<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_umi(in_file):
 """collapse reads using UMI tags"""

    keep = defaultdict(dict)
    with open_fastq(in_file) as handle:
        for line in handle:
            if line.startswith("@"):
                m = re.search('UMI_([ATGC]*)', line.strip())
                umis = m.group(0)
                seq = handle.next().strip()
                handle.next()
                qual = handle.next().strip()
                if (umis, seq) in keep:
                    keep[(umis, seq)][1].update(qual)
                    keep[(umis, seq)][0].update(seq)
                else:
                    keep[(umis, seq)] = [umi(seq), quality(qual)]
    logger.info("Sequences loaded: %s" % len(keep))
    return keep