def bar_graph(nominal_length, trans, untrans, fuzzy, obsolete):
    """Format the given four counts into a bar graph string in which the
    total length of the bars representing the TRANS, UNTRANS and FUZZY
    counts is NOMINAL_LENGTH characters, and the bar representing the
    OBSOLETE count extends beyond that."""

    total_count = trans + untrans + fuzzy  # don't include 'obsolete'
    accum_bar = 0
    accum_count = 0
    s = ''
    for count, letter in [(trans, '+'), (untrans, 'U'), (fuzzy, '~'),
                          (obsolete, 'o')]:
        accum_count += count
        new_bar_end = nominal_length * accum_count / total_count
        s += letter * (new_bar_end - accum_bar)
        accum_bar = new_bar_end
    return s