def write_new_agp(new_agp_lines):
    """
    Writes a new AGP file incorporating the Blat changes
    
    :param new_agp_lines: List containing the new AGP lines
    :type new_agp_lines: list(list(str))
    """
    with open('scaffolds.agp', 'w') as out:
        last_scaffold = ''
        last_position = 0
        last_id = 0
        for line in new_agp_lines:
            if line[0] != last_scaffold:
                last_scaffold = ''
                last_position = 0
                last_id = 0
            if int(line[1]) != last_position + 1:
                line[2] = str(int(line[2]) - (int(line[1]) - last_position))
                line[1] = str(last_position + 1)
            line[3] = str(int(last_id) + 1)
            last_position = int(line[2])
            last_scaffold = line[0]
            last_id = line[3]
            out.write('\t'.join(line))
