def read_to_unmapped(read, ref=None):
    '''
    Converts a read from mapped to unmapped.

    Sets the 'ZR' tag to indicate the original ref/pos/cigar (if ref is passed)
    '''

    newread = pysam.AlignedRead()

    if ref:
        tags = [('ZR', '%s:%s:%s' % (ref, read.pos, cigar_tostr(read.cigar)))]

    newread.is_unmapped = True
    newread.mapq = 0
    newread.tlen = 0
    newread.pos = -1
    newread.pnext = -1
    newread.rnext = -1
    newread.tid = -1

    newread.qname = read.qname

    if read.is_paired:
        newread.is_paired = True

    if not read.is_unmapped and read.is_reverse:
        newread.seq = ngsutils.support.revcomp(read.seq)
        newread.qual = read.qual[::-1]
    else:        
        newread.seq = read.seq
        newread.qual = read.qual

    newread.tags = tags

    return newread
dataset/ETHPy150Open ngsutils/ngsutils/ngsutils/bam/__init__.py/read_to_unmapped/original