def read_removeclipping(read):
    if read.is_unmapped:
        return 1

    newcigar = []
    clip_5 = 0
    clip_3 = 0

    changed = False
    inseq = False
    for op, length in read.cigar:
        if op == 5:  # H
            changed = True
        elif op == 4:  # S
            changed = True
            if not inseq:
                clip_5 = length
            else:
                clip_3 = length
        else:
            inseq = True
            newcigar.append((op, length))

    if not changed:
        return 0

    read.cigar = newcigar
    orig_length = len(read.seq)

    s = read.seq
    q = read.qual

    if clip_3:
        read.seq = s[clip_5:-clip_3]
        if q:
            read.qual = q[clip_5:-clip_3]
    else:
        read.seq = s[clip_5:]
        if q:
            read.qual = q[clip_5:]

    newtags = []
    if clip_5:
        newtags.append(('ZA', clip_5))
    if clip_3:
        newtags.append(('ZB', clip_3))

    newtags.append(('ZC', orig_length / float(clip_5 + clip_3)))

    read.tags = read.tags + newtags

    return 2
dataset/ETHPy150Open ngsutils/ngsutils/ngsutils/bam/removeclipping.py/read_removeclipping/swapped operands of `/`