def make_errline(line, bad_fields=[]):
    """Return an 'error line' indicating problem fields in a string

    Given a tab-delimited line and a list of integer indices
    indicating which fields in the line have problems, this function
    returns a tab-delimited string where the original fields are
    replaced by either spaces or '^' characters.

    When printed beneath the original line, the '^'s indicate which
    fields are 'bad' according to the supplied indices, e.g.

    Input line: 'good    good    bad    bad    good'
    Error line: '                ^^^    ^^^        '

    Arguments:
      line: string where tabs delimit fields
      bad_fields: list of integer indices corresponding to 'bad'
        values in 'line'

    Returns:
      Tab-delimited 'error line' to be printed beneath the original
      line, to indicate which fields are 'bad'.
    """
    errline = []
    items = line.rstrip().split('\t')
    for i in range(len(items)):
        if i in bad_fields:
            errline.append('^' * len(items[i]))
        else:
            errline.append(' ' * len(items[i]))
    return '\t'.join(errline)
