def index_of_nth_base(gappedseq, n):
    """Return the index of the nth non-gapped base in the sequence
    where n=0 is the first."""
    nongapped = 0
    for i, b in enumerate(gappedseq):
        if b == '-':
            continue
        if nongapped == n:
            return i
        nongapped += 1
    raise ValueError(
        "Could not find {0}'th non-gapped base in sequence".format(n))