<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def coverage_interval_from_bed(bed_file, per_chrom=True):
 """Calculate a coverage interval for the current region BED. This helps correctly work with cases of uneven coverage across an analysis genome. strelka2 and other model based callers have flags for targeted and non which depend on the local context. Checks coverage per chromosome, avoiding non-standard chromosomes, if per_chrom is set. Otherwise does a global check over all regions. The global check performs better for strelka2 but not for DeepVariant: https://github.com/bcbio/bcbio_validations/tree/master/deepvariant#deepvariant-v06-release-strelka2-stratification-and-initial-gatk-cnn """

    total_starts = {}
    total_ends = {}
    bed_bases = collections.defaultdict(int)
    with utils.open_gzipsafe(bed_file) as in_handle:
        for line in in_handle:
            parts = line.split()
            if len(parts) >= 3:
                chrom, start, end = parts[:3]
                if chromhacks.is_autosomal(chrom):
                    start = int(start)
                    end = int(end)
                    bed_bases[chrom] += (end - start)
                    total_starts[chrom] = min([start, total_starts.get(chrom, sys.maxsize)])
                    total_ends[chrom] = max([end, total_ends.get(chrom, 0)])
    # can check per chromosome -- any one chromosome with larger, or over all regions
    if per_chrom:
        freqs = [float(bed_bases[c]) / float(total_ends[c] - total_starts[c]) for c in sorted(bed_bases.keys())]
    elif len(bed_bases) > 0:
        freqs = [sum([bed_bases[c] for c in sorted(bed_bases.keys())]) /
                 sum([float(total_ends[c] - total_starts[c]) for c in sorted(bed_bases.keys())])]
    else:
        freqs = []
    # Should be importing GENOME_COV_THRESH but get circular imports
    if any([f >= 0.40 for f in freqs]):
        return "genome"
    else:
        return "targeted"