<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _identify_heterogeneity_blocks_hmm(in_file, params, work_dir, somatic_info):
 """Use a HMM to identify blocks of heterogeneity to use for calculating allele frequencies. The goal is to subset the genome to a more reasonable section that contains potential loss of heterogeneity or other allele frequency adjustment based on selection. """

    def _segment_by_hmm(chrom, freqs, coords):
        cur_coords = []
        for j, state in enumerate(_predict_states(freqs)):
            if state == 0:  # heterozygote region
                if len(cur_coords) == 0:
                    num_misses = 0
                cur_coords.append(coords[j])
            else:
                num_misses += 1
            if num_misses > params["hetblock"]["allowed_misses"]:
                if len(cur_coords) >= params["hetblock"]["min_alleles"]:
                    yield min(cur_coords), max(cur_coords)
                cur_coords = []
        if len(cur_coords) >= params["hetblock"]["min_alleles"]:
            yield min(cur_coords), max(cur_coords)
    return _identify_heterogeneity_blocks_shared(in_file, _segment_by_hmm, params, work_dir, somatic_info)