Scripts/Flag_placer.py
def write_bedfile(flags):
    """ The write_bedfile function writes a file in BED format that can be loaded in igv and visualises the read data.

    :param flags: a 2d list containing all the flag information.
    """
    with open(args.output + f'/{args.name}.bed', 'w') as bedfile:
        bedfile.write('track name=Flags description="Flags regions of interest." db=hg19 gffTags=on itemRGB="On"\n')

    for flag in flags:
        percentage = round(flag[3]['count'] / flag[3]['total'], 2)

        region = f"{flag[0]}\t{flag[1]}\t{flag[2]}"
        description = f"Name={flag[3]['type']};Readcount={flag[3]['count']};Total_reads={flag[3]['total']};" \
                      f"Percentage={percentage}"

        if flag[3]['type'] == 'high_insert_size' or flag[3]['type'] == 'ultra_high_insert_size':
            lengths = flag[3]['lengths']
            description += f";Avg_insert_size={round(mean(lengths))};Med_insert_size={median(lengths)};" \
                           f"Lower_limit={min(lengths)};Upper_limit={max(lengths)}"

        if flag[3]['type'] == 'same_orientation':
            rgb = f"0,192,199"

        elif flag[3]['type'] == 'high_insert_size':
            rgb = f"232,135,26"

        elif flag[3]['type'] == 'unmapped_mate':
            rgb = f"218,52,144"

        elif flag[3]['type'] == 'ultra_high_insert_size':
            rgb = '71,226,111'

        with open(args.output + f'/{args.name}.bed', 'a') as bedfile:
            bedfile.write(f"{region}\t{description}\t0\t.\t{flag[1]}\t{flag[2]}\t{rgb}\n")
 The write_bedfile function writes a file in BED format that can be loaded in igv and visualises the read data.

    :param flags: a 2d list containing all the flag information.
    
The write_bedfile function writes a file in BED format that can be loaded in igv and visualises the read data.
The write_bedfile function writes a file in BED format that can be loaded in igv and visualises the read data .
def write_bedfile(flags):
    with open(args.output + f'/{args.name}.bed', 'w') as bedfile:
        bedfile.write('track name=Flags description="Flags regions of interest." db=hg19 gffTags=on itemRGB="On"\n')
    for flag in flags:
        percentage = round(flag[3]['count'] / flag[3]['total'], 2)
        region = f"{flag[0]}\t{flag[1]}\t{flag[2]}"
        description = f"Name={flag[3]['type']};Readcount={flag[3]['count']};Total_reads={flag[3]['total']};" \
                      f"Percentage={percentage}"
        if flag[3]['type'] == 'high_insert_size' or flag[3]['type'] == 'ultra_high_insert_size':
            lengths = flag[3]['lengths']
            description += f";Avg_insert_size={round(mean(lengths))};Med_insert_size={median(lengths)};" \
                           f"Lower_limit={min(lengths)};Upper_limit={max(lengths)}"
        if flag[3]['type'] == 'same_orientation':
            rgb = f"0,192,199"
        elif flag[3]['type'] == 'high_insert_size':
            rgb = f"232,135,26"
        elif flag[3]['type'] == 'unmapped_mate':
            rgb = f"218,52,144"
        elif flag[3]['type'] == 'ultra_high_insert_size':
            rgb = '71,226,111'
        with open(args.output + f'/{args.name}.bed', 'a') as bedfile:
            bedfile.write(f"{region}\t{description}\t0\t.\t{flag[1]}\t{flag[2]}\t{rgb}\n")
def write_bedfile ( flags ) : with open ( args . output + f'/{args.name}.bed' , 'w' ) as bedfile : bedfile . write ( 'track name=Flags description="Flags regions of interest." db=hg19 gffTags=on itemRGB="On"\n' ) for flag in flags : percentage = round ( flag [ 3 ] [ 'count' ] / flag [ 3 ] [ 'total' ] , 2 ) region = f"{flag[0]}\t{flag[1]}\t{flag[2]}" description = f"Name={flag[3]['type']};Readcount={flag[3]['count']};Total_reads={flag[3]['total']};" f"Percentage={percentage}" if flag [ 3 ] [ 'type' ] == 'high_insert_size' or flag [ 3 ] [ 'type' ] == 'ultra_high_insert_size' : lengths = flag [ 3 ] [ 'lengths' ] description += f";Avg_insert_size={round(mean(lengths))};Med_insert_size={median(lengths)};" f"Lower_limit={min(lengths)};Upper_limit={max(lengths)}" if flag [ 3 ] [ 'type' ] == 'same_orientation' : rgb = f"0,192,199" elif flag [ 3 ] [ 'type' ] == 'high_insert_size' : rgb = f"232,135,26" elif flag [ 3 ] [ 'type' ] == 'unmapped_mate' : rgb = f"218,52,144" elif flag [ 3 ] [ 'type' ] == 'ultra_high_insert_size' : rgb = '71,226,111' with open ( args . output + f'/{args.name}.bed' , 'a' ) as bedfile : bedfile . write ( f"{region}\t{description}\t0\t.\t{flag[1]}\t{flag[2]}\t{rgb}\n" )
The write_bedfile function writes a file in BED format that can be loaded in igv and visualises the read data.
The write_bedfile function writes a file in BED format that can be loaded in igv and visualises the read data .
""" The write_bedfile function writes a file in BED format that can be loaded in igv and visualises the read data.

    :param flags: a 2d list containing all the flag information.
    """
flags
a 2d list containing all the flag information.
a 2d list containing all the flag information .