'Make sure that the bar_code about to be assigned to a sample is globally unique.
That is, bar_codes must be unique across requests in Galaxy sample tracking.
Bar codes are not required, but if used, they can only be added to a sample after
the request is submitted.'

def __validate_bar_code(self, trans, sample, bar_code):

    message = ''
    unique = True
    for index in range(len(sample.request.samples)):
        for sample_with_bar_code in trans.sa_session.query(trans.model.Sample).filter((trans.model.Sample.table.c.bar_code == bar_code)):
            if (sample_with_bar_code and (sample_with_bar_code.id != sample.id)):
                message = ('The    bar    code    (%s)    associated    with    the    sample    (%s)    belongs    to    another    sample.\n                                                                                                                                    Bar    codes    must    be    unique    across    all    samples,    so    use    a    different    bar    code\n                                                                                                                                    for    this    sample.' % (bar_code, sample.name))
                unique = False
                break
        if (not unique):
            break
    return message
