def genebody_coverage(samfile, chrom, positions, bg_level=0):
    """
	calculate coverage for each nucleotide in *positions*. some times len(cvg) < len(positions)
	because positions where there is no mapped reads were ignored.
	"""
    cvg = []
    start = positions[0] - 1
    end = positions[-1]
    try:
        for pileupcolumn in samfile.pileup(chrom, start, end, truncate=True):
            ref_pos = pileupcolumn.pos + 1
            if ref_pos not in positions:
                continue
            if pileupcolumn.n == 0:
                cvg.append(0.0)
                continue
            cover_read = 0.0
            for pileupread in pileupcolumn.pileups:
                if pileupread.is_del:
                    continue
                if pileupread.alignment.is_qcfail:
                    continue
                if pileupread.alignment.is_secondary:
                    continue
                if pileupread.alignment.is_unmapped:
                    continue
                cover_read += 1.0
            cvg.append(cover_read)
    except:
        cvg = []
    if bg_level <= 0:
        return cvg
    else:
        tmp = []
        for i in cvg:
            subtracted_sig = int(i - bg_level)
            if subtracted_sig > 0:
                tmp.append(subtracted_sig)
            else:
                tmp.append(0)
        return tmp
