def _read_count_byRead(bins, read_sets):
    """
Utility function to be called by "read_count".

"""
    sample_number = len(read_sets)
    cnts = []
    for bs in bins.values():
        for b in bs:
            cnts.append([0] * sample_number)
    within = [0] * sample_number
    for j, read_set in enumerate(read_sets):
        for ch in read_set:
            if ch not in bins:
                continue
            reads = read_set[ch]
            if len(reads) == 0:
                continue
            rmax = reads[-1]
            bs = bins[ch]
            bi = 0
            for locus in reads:
                while bi < len(bs) and bs[bi][1] <= locus:
                    bi += 1
                if bi == len(bs) or bs[bi][0] > rmax:
                    break
                temp = bi
                flag = False
                while temp < len(bs):
                    b = bs[temp]
                    if b[0] > locus:
                        break
                    flag = True
                    cnts[b[-1] - 1][j] = cnts[b[-1] - 1][j] + 1
                    temp += 1
                if flag:
                    within[j] = within[j] + 1
    return cnts, within
