def writeNH(outfile, nh, max_hi):

    # need to remove double counting
    # one read matching to 2 positions is only 2

    max_nh = max(nh.keys())
    if max_hi > 0:
        for x in xrange(1, min(max_nh + 1, max_hi)):
            if nh[x] == 0:
                continue
            outfile.write("%i\t%i\n" % (x, nh[x] / x))
        for x in xrange(max_hi, max_nh + 1):
            if nh[x] == 0:
                continue
            outfile.write("%i\t%i\n" % (x, nh[x] / max_hi))
    else:
        for x in xrange(1, max_nh + 1):
            if nh[x] == 0:
                continue
            outfile.write("%i\t%i\n" % (x, nh[x] / x))
output nh array, correcting for max_hi if less than nh
dataset/ETHPy150Open CGATOxford/cgat/scripts/bam2stats.py/writeNH