def apply_hgvs(seq, h):
    """Apply 1-based HGVS mutation to 0-based biopython Sequence"""
    if h.kind == 'c':
        start = h.cdna_start.coord - 1
        end = h.cdna_end.coord - 1
        if h.mutation_type == '>':
            assert seq[start] == h.ref_allele
            new_seq = seq[:start] + h.alt_allele + seq[start + 1:]
        elif h.mutation_type == 'del':
            assert seq[start:end + 1] == h.ref_allele
            new_seq = seq[:start] + seq[end + 1:]
            assert len(seq) == len(new_seq) + len(h.ref_allele)
        elif h.mutation_type == 'ins':
            new_seq = seq[:start + 1] + h.alt_allele + seq[end:]
            assert len(seq) + len(h.alt_allele) == len(new_seq)
        elif h.mutation_type == 'dup':
            assert seq[start:end + 1] == h.ref_allele
            new_seq = seq[:start] + h.alt_allele + seq[end + 1:]
            assert len(seq) - len(h.ref_allele) + len(h.alt_allele) == len(
                new_seq)
        elif h.mutation_type == 'delins':
            assert seq[start:end + 1] == h.ref_allele
            new_seq = seq[:start] + h.alt_allele + seq[end + 1:]
            assert len(seq) - len(h.ref_allele) + len(h.alt_allele) == len(
                new_seq)
        else:
            raise Exception('Unexpected mutation_type {}'.format(h.
                mutation_type))
        return new_seq
    else:
        raise Exception('Only cDNA mutations have been implemented')
