def __flush_cur_reads(cur_reads, outbam, inbam, countfile=None):
    if cur_reads:
        for k in cur_reads:
            count = 0

            for i, (mapq, idx, r) in enumerate(sorted(cur_reads[k])[::-1]):
                count += 1
                if i > 0:
                    r.is_duplicate = True
                if outbam:
                    outbam.write(r)

            if countfile:
                countfile.write('%s\t%s\t%s\t%s\n' % (inbam.references[k[0]], k[1], k[2], count))
dataset/ETHPy150Open ngsutils/ngsutils/ngsutils/bam/pcrdup.py/__flush_cur_reads/original