Scripts/Flag_placer.py
def place_flags(reads):
    """ The place_flags function gets the coordinates of interesting regions and returns the coordinates of the flags
    with their information.

    :param reads: Pysam object containing read information
    :return all_flags: A 2d list containing the coordinates of the flags and additional information.
    :return read_data: A list with the number of total reads, unmapped reads and reads with 0 mapped positions.
    """
    all_flags = []
    read_data = [0, 0, 0]  # [0] is number of reads. [1] is unmapped reads. [2] is reads with 0 mapped positions

    isbuildingflags = [False, False, False, False]
    flags = [[None, None, None, {'type': 'same_orientation', 'count': 0, 'total': 0}],
             [None, None, None, {'type': 'high_insert_size', 'count': 0, 'total': 0, 'lengths': []}],
             [None, None, None, {'type': 'unmapped_mate', 'count': 0, 'total': 0}],
             [None, None, None, {'type': 'ultra_high_insert_size', 'count': 0, 'total': 0, 'lengths': []}]]

    for read in reads:
        if not read.is_unmapped and read.positions:
            start, end = true_position(read)
            chromosome = read.reference_name
            # place flag if read and its mate have the same orientation.
            flags, isbuildingflags, all_flags = flag_sameorientation(read, flags, isbuildingflags, all_flags,
                                                                     chromosome, start)

            # place flag if read has high insert size.
            flags, isbuildingflags, all_flags = flag_high_isize(read, flags, isbuildingflags, all_flags, chromosome,
                                                                start)
            # place flag if read has unmapped mate.
            flags, isbuildingflags, all_flags = flag_unmapped_mate(read, flags, isbuildingflags, all_flags, chromosome,
                                                                   start)

            # place flag if read has ultra high insert size.
            flags, isbuildingflags, all_flags = flag_ultra_high_isize(read, flags, isbuildingflags, all_flags,
                                                                      chromosome,  start)

            flags = update_total(flags, isbuildingflags)

        elif read.is_unmapped:
            read_data[1] += 1
        elif len(read.positions) == 0:
            read_data[2] += 1
        read_data[0] += 1

    return all_flags, read_data
 The place_flags function gets the coordinates of interesting regions and returns the coordinates of the flags
    with their information.

    :param reads: Pysam object containing read information
    :return all_flags: A 2d list containing the coordinates of the flags and additional information.
    :return read_data: A list with the number of total reads, unmapped reads and reads with 0 mapped positions.
    
The place_flags function gets the coordinates of interesting regions and returns the coordinates of the flags
with their information.
The place_flags function gets the coordinates of interesting regions and returns the coordinates of the flags with their information .
def place_flags(reads):
    all_flags = []
    read_data = [0, 0, 0]  
    isbuildingflags = [False, False, False, False]
    flags = [[None, None, None, {'type': 'same_orientation', 'count': 0, 'total': 0}],
             [None, None, None, {'type': 'high_insert_size', 'count': 0, 'total': 0, 'lengths': []}],
             [None, None, None, {'type': 'unmapped_mate', 'count': 0, 'total': 0}],
             [None, None, None, {'type': 'ultra_high_insert_size', 'count': 0, 'total': 0, 'lengths': []}]]
    for read in reads:
        if not read.is_unmapped and read.positions:
            start, end = true_position(read)
            chromosome = read.reference_name
            flags, isbuildingflags, all_flags = flag_sameorientation(read, flags, isbuildingflags, all_flags,
                                                                     chromosome, start)
            flags, isbuildingflags, all_flags = flag_high_isize(read, flags, isbuildingflags, all_flags, chromosome,
                                                                start)
            flags, isbuildingflags, all_flags = flag_unmapped_mate(read, flags, isbuildingflags, all_flags, chromosome,
                                                                   start)
            flags, isbuildingflags, all_flags = flag_ultra_high_isize(read, flags, isbuildingflags, all_flags,
                                                                      chromosome,  start)
            flags = update_total(flags, isbuildingflags)
        elif read.is_unmapped:
            read_data[1] += 1
        elif len(read.positions) == 0:
            read_data[2] += 1
        read_data[0] += 1
    return all_flags, read_data
def place_flags ( reads ) : all_flags = [ ] read_data = [ 0 , 0 , 0 ] isbuildingflags = [ False , False , False , False ] flags = [ [ None , None , None , { 'type' : 'same_orientation' , 'count' : 0 , 'total' : 0 } ] , [ None , None , None , { 'type' : 'high_insert_size' , 'count' : 0 , 'total' : 0 , 'lengths' : [ ] } ] , [ None , None , None , { 'type' : 'unmapped_mate' , 'count' : 0 , 'total' : 0 } ] , [ None , None , None , { 'type' : 'ultra_high_insert_size' , 'count' : 0 , 'total' : 0 , 'lengths' : [ ] } ] ] for read in reads : if not read . is_unmapped and read . positions : start , end = true_position ( read ) chromosome = read . reference_name flags , isbuildingflags , all_flags = flag_sameorientation ( read , flags , isbuildingflags , all_flags , chromosome , start ) flags , isbuildingflags , all_flags = flag_high_isize ( read , flags , isbuildingflags , all_flags , chromosome , start ) flags , isbuildingflags , all_flags = flag_unmapped_mate ( read , flags , isbuildingflags , all_flags , chromosome , start ) flags , isbuildingflags , all_flags = flag_ultra_high_isize ( read , flags , isbuildingflags , all_flags , chromosome , start ) flags = update_total ( flags , isbuildingflags ) elif read . is_unmapped : read_data [ 1 ] += 1 elif len ( read . positions ) == 0 : read_data [ 2 ] += 1 read_data [ 0 ] += 1 return all_flags , read_data
The place_flags function gets the coordinates of interesting regions and returns the coordinates of the flags
with their information.
The place_flags function gets the coordinates of interesting regions and returns the coordinates of the flags with their information .
""" The place_flags function gets the coordinates of interesting regions and returns the coordinates of the flags
    with their information.

    :param reads: Pysam object containing read information
    :return all_flags: A 2d list containing the coordinates of the flags and additional information.
    :return read_data: A list with the number of total reads, unmapped reads and reads with 0 mapped positions.
    """ # [0] is number of reads. [1] is unmapped reads. [2] is reads with 0 mapped positions # place flag if read and its mate have the same orientation. # place flag if read has high insert size. # place flag if read has unmapped mate. # place flag if read has ultra high insert size.
A 2d list containing the coordinates of the flags and additional information.
A 2d list containing the coordinates of the flags and additional information .
all_flags
A list with the number of total reads, unmapped reads and reads with 0 mapped positions.
A list with the number of total reads unmapped reads and reads with 0 mapped positions .
read_data
reads
Pysam object containing read information
Pysam object containing read information