import copy


def apply_is_hotspot_qvalue_filter(codon_level_dict, max_qvalue_cutoff):
    """
    Remove codons with 'is_hotspot' qvalue above specified threshold.

    Notes
    -----
    (1) Also remove codons with missing stats_data's qvalue.
    """

    filtered_codon_level_dict = copy.deepcopy(codon_level_dict)

    for codon_id in codon_level_dict:
        pass_filter = False

        if 'stats_data' in codon_level_dict[codon_id]:
            stats_data = codon_level_dict[codon_id]['stats_data']
            if stats_data['QValue'] <= max_qvalue_cutoff:
                pass_filter = True

        if not pass_filter:
            del filtered_codon_level_dict[codon_id]

    return filtered_codon_level_dict