def calculate_ani(dna_fragment_matches):
    """Calculate ANI value for a set of DNA fragment matches.

    :param dna_fragment_matches: A dict comprising matches of DNA fragments.

    :rtype: ANI value.
    """
    ani_matches = 0
    ni_sum = 0.0
    for fm in dna_fragment_matches:
        if float(fm['alignment_length'] - fm['no_non_identities']) / float(fm
            ['length']) > 0.3 and float(fm['alignment_length']) / float(fm[
            'length']) >= 0.7:
            ni_sum += float(fm['alignment_length'] - fm['no_non_identities']
                ) / float(fm['alignment_length'])
            ani_matches += 1
    return ni_sum / float(ani_matches) if ani_matches > 0 else 0
