def find_seq_rec(block, name, case_sensitive=True):
    """Given part of a sequence ID, find the first matching record."""
    if case_sensitive:
        def test(name, rec):
            return name in rec['id']
    else:
        def test(name, rec):
            return name.upper() in rec['id'].upper()

    for rec in block['sequences']:
        if test(name, rec):
            return rec
    raise ValueError("No sequence ID matches %s" % repr(name))