def _group_by_barcode( alignments ):
    """Group reads by their barcode"""
    groups = {}
    for alignment in alignments:
        name = alignment.qname
        if name.startswith('Barcode'):
            name = name[7:]
        if name.startswith('_'):
            name = name[1:]
        barcode = name.split('_Cluster')[0]
        try:
            groups[barcode].append( alignment )
        except KeyError:
            groups[barcode] = [ alignment ]
    return groups