def parse_bigg_response(res, ms, bi, log):
    """
    Parse the BiGG API response text. Text is all plain text in JSON format.
    The fields of interest are the KEGG Reaction ID or the EC number.

    :param res: API JSON response
    :type res: dict
    :param ms: ModelSEED reaction ID
    :type ms: str
    :param bi: BiGG reaction ID
    :type bi: str
    :param log: Log output file handle
    :type log: File
    :return: KO IDs and EC numbers
    :rtype: dict
    """
    data = {'KO': set(), 'EC': set()}  # Data to return

    # Check if any database info exists
    db_info = res['database_links']
    if len(db_info) == 0:
        log.write('No database info for BiGG ' + bi + '\n')

    # Check for KEGG
    elif 'KEGG Reaction' in db_info:
        # May have multiple KO identfiers
        for item in db_info['KEGG Reaction']:
            if 'id' not in item:
                log.write('KEGG reaction found but no ID for BiGG '
                          + bi + ' and ModelSEED ' + ms + ' \n')
            data['KO'].add(item['id'])

    # Check for EC number of KEGG does not exist
    elif 'EC Number' in db_info:
        # May have multiple EC numbers
        for item in db_info['EC Number']:
            if 'id' not in item:
                log.write('EC number found but no ID for BiGG '
                          + bi + ' and ModelSEED ' + ms + ' \n')
            data['EC'].add(item['id'])

    # No KEGG or EC
    else:
        log.write('No KEGG Reaction or EC Number for BiGG '
                  + bi + ' and ModelSEED ' + ms + ' \n')

    return data