def METHOD_NAME(options):
    """
    process gam json made with vg view -a my.gam | jq -s -c 'sort_by(.name)[]'
    """
    in_file = sys.stdin if options.input == '-' else open(options.input, 'r')
    prev_name = None
    first_record = None
    num_written = 0
    num_read = 0    
    for line in in_file:
        num_read += 1
        gam = json.loads(line)
        if 'is_secondary' in gam and gam['is_secondary']:
            continue
        if 'fragment_next' in gam:
            first_record = gam
        elif 'fragment_prev' in gam and first_record and gam['fragment_prev']['name'] == first_record['name']:
            assert first_record['fragment_next']['name'] == gam['name']
            print(json.dumps(first_record))
            print(json.dumps(gam))
            num_written += 2
        elif 'fragment_next' not in gam and 'fragment_prev' not in gam:
            raise RuntimeError('fragment_prev/next not set for record: {}'.format(json.dumps(gam)))
        if prev_name and gam['name'] < prev_name:
            raise RuntimeError('Records not sorted by name: {} {}\n'.format(prev_name, gam['name']) + 
                               'Use vg view -a {} | jq -s -c \'sort_by(.name)[]\''.format(options.input))
        prev_name = gam['name']
    in_file.close()
    sys.stderr.write('Filtered {} / {} lines\n'.format(num_read - num_written, num_read))