def truncate_barcode(seq,length):
    """Return barcode sequence truncated to requested length

    'seq' is a barcode sequence (note that dual index sequences
    are of the form e.g. 'AGGTAC-GGCCTT' i.e. the name includes
    a hyphen) and 'length' is the desired length (i.e. number of
    bases to keep).

    """
    try:
        i = seq.index('-')
        # Dual index barcode
        if i >= length:
            return seq[:length]
        else:
            return seq[:length+1]
    except ValueError:
        # No hyphen: single index barcode
        return seq[:length]