def collapse_umi(in_file):
keep = defaultdict(dict)<EOL>with open_fastq(in_file) as handle:<EOL><INDENT>for line in handle:<EOL><INDENT>if line.startswith("<STR_LIT:@>"):<EOL><INDENT>m = re.search('<STR_LIT>', line.strip())<EOL>umis = m.group(<NUM_LIT:0>)<EOL>seq = handle.next().strip()<EOL>handle.next()<EOL>qual = handle.next().strip()<EOL>if (umis, seq) in keep:<EOL><INDENT>keep[(umis, seq)][<NUM_LIT:1>].update(qual)<EOL>keep[(umis, seq)][<NUM_LIT:0>].update(seq)<EOL><DEDENT>else:<EOL><INDENT>keep[(umis, seq)] = [umi(seq), quality(qual)]<EOL><DEDENT><DEDENT><DEDENT><DEDENT>logger.info("<STR_LIT>" % len(keep))<EOL>return keep<EOL>
collapse reads using UMI tags