import json


def parse_desc(rec):
    """
    Parses annotations from a sequence description
    """
    ann = {}

    desc = rec.description

    # Nothing to parse.
    if rec.id == desc:
        return ann, ''

    # Attempts to split the description for parsing into JSON
    payload = rec.description.split(" ", maxsplit=1)

    if len(payload) == 2:
        try:
            data = payload[1]
            ann = json.loads(data)
        except Exception as exc:
            # Not a valid
            #print (exc, data)
            pass
    else:
        desc = dict(desc=rec.description)

    return ann, desc