def merge_key(record):
    """
    Sort records by all fields that records_match will use to check for duplicates, in sequence, 
    so that all identical records according to records_match will be adjacent
    """
    chr2 = record.info['CHR2'] if 'CHR2' in record.info else None
    end2 = record.info['END2'] if 'END2' in record.info else None
    return (record.pos, record.stop, record.info['SVTYPE'], record.info['SVLEN'], chr2, end2, record.info['STRANDS'], record.id)