def verify(joined):
    """
    Checks that the passed otu and sequences constitute valid Virtool records and can be included in a otu
    index. Error fields are:
    * emtpy_otu - otu has no isolates associated with it.
    * empty_isolate - isolates that have no sequences associated with them.
    * empty_sequence - sequences that have a zero length sequence field.
    * isolate_inconsistency - otu has isolates containing different numbers of sequences.

    :param joined: a joined otu
    :type joined: dict

    :return: return any errors or False if there are no errors.
    :rtype: Union[dict, None]

    """
    errors = {
        "empty_otu": len(joined["isolates"]) == 0,
        "empty_isolate": list(),
        "empty_sequence": list(),
        "isolate_inconsistency": False
    }

    isolate_sequence_counts = list()

    # Append the isolate_ids of any isolates without sequences to empty_isolate. Append the isolate_id and sequence
    # id of any sequences that have an empty sequence.
    for isolate in joined["isolates"]:
        isolate_sequences = isolate["sequences"]
        isolate_sequence_count = len(isolate_sequences)

        # If there are no sequences attached to the isolate it gets an empty_isolate error.
        if isolate_sequence_count == 0:
            errors["empty_isolate"].append(isolate["id"])

        isolate_sequence_counts.append(isolate_sequence_count)

        errors["empty_sequence"] += filter(lambda sequence: len(sequence["sequence"]) == 0, isolate_sequences)

    # Give an isolate_inconsistency error the number of sequences is not the same for every isolate. Only give the
    # error if the otu is not also emtpy (empty_otu error).
    errors["isolate_inconsistency"] = (
            len(set(isolate_sequence_counts)) != 1 and not
    (errors["empty_otu"] or errors["empty_isolate"])
    )

    # If there is an error in the otu, return the errors object. Otherwise return False.
    has_errors = False

    for key, value in errors.items():
        if value:
            has_errors = True
        else:
            errors[key] = False

    if has_errors:
        return errors

    return None