Working with indels#

Both AlphaGenome 1 and AlphaGenome 2 support insertions and deletions (indels) using indel stitching based on Korsakova et al., bioRxiv 2025: on the server, shifted forward passes are stitched across the indel boundary so downstream bases stay in the same convolutional and pooling bin phase as the reference allele, removing bin-phase artifacts.

If you only need variant effect scores, score_variant() handles indel alignment automatically for every recommended scorer, so you do not need to align tracks manually.

When you call predict_variant() to inspect or plot raw tracks directly, each allele’s predictions remain in that allele’s own coordinate frame, so downstream coordinates are still shifted by len(alt) - len(ref) base pairs relative to the reference. This tutorial shows how to work with indels in predict_variant() and score_variant(), how to align 1-bp alternate tracks back to reference coordinates with TrackData.align_alternate(), how to subtract splice junctions directly, and when to keep tracks unaligned.

Key activities:

  • Represent insertions and deletions as left-aligned anchored genome.Variant objects.

  • Inspect why raw REF and ALT TrackData outputs share the same shape (interval.width, num_tracks) yet are shifted downstream of an indel.

  • Use TrackData.align_alternate() to remove coordinate-shift artifacts on a 15-bp APOL4 deletion.

  • Quantify gained and lost splice junctions on an indel with alt.splice_junctions - ref.splice_junctions.

  • Contrast coordinate-aligned tracks against unaligned center-window aggregation on a 12-bp TAL1 oncogenic insertion that creates a de novo TF binding site and chromatin peak.

  • Run dna_model.score_variant() to use server-side indel handling automatically.

Set up#

# @title Install AlphaGenome

# @markdown Run this cell to install AlphaGenome.
from IPython.display import clear_output
! pip install alphagenome
clear_output()
# @title Imports
from alphagenome import colab_utils
from alphagenome.data import gene_annotation
from alphagenome.data import genome
from alphagenome.data import transcript as transcript_utils
from alphagenome.models.v2 import dna_client
from alphagenome.models.v2 import variant_scorers
from alphagenome.visualization import plot_components
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

Store your API key in Colab Secrets for persistent access across sessions (see Installation), then initialize the client:

dna_model = dna_client.create(colab_utils.get_api_key())

Load GENCODE v46 annotations and build a TranscriptExtractor for protein-coding transcripts:

gtf = pd.read_feather(
    'https://storage.googleapis.com/alphagenome/reference/gencode/'
    'hg38/gencode.v46.annotation.gtf.gz.feather'
)
gtf_protein = gene_annotation.filter_protein_coding(gtf)
transcript_extractor = transcript_utils.TranscriptExtractor(gtf_protein)

How predict_variant() represents indels#

AlphaGenome represents indels using standard left-aligned VCF anchoring: both reference_bases and alternate_bases are non-empty and share the base immediately preceding the indel (for example, CGGACTCACCCGACGC -> C for a 15-bp deletion, or C -> CCGTTTCCTAACC for a 12-bp insertion).

Unlike a sequence alignment with gaps, predict_variant() always returns fixed-length (interval.width, num_tracks) arrays for both REF and ALT by adjusting the right boundary of the alternate DNA input:

Indel type

Alternate DNA input (length = interval.width)

Effect on downstream ALT positions

Deletion (\(d\) bp)

Removes \(d\) bases and extends \(d\) real genomic bases past interval.end

Shifted left by \(d\) bp

Insertion (\(k\) bp)

Inserts \(k\) bases and crops the last \(k\) reference bases off the right edge

Shifted right by \(k\) bp

Because both arrays have identical shapes, output.alternate.rna_seq - output.reference.rna_seq does not raise a shape error—it subtracts misaligned bases downstream of the indel.

Deletion example: aligning downstream 1-bp tracks#

To see the coordinate shift in practice, consider a 15-bp deletion (chr22:36201691:CGGACTCACCCGACGC>C) spanning the APOL4 splice region in sigmoid colon (UBERON:0001159). We predict RNA_SEQ, SPLICE_SITES, and SPLICE_JUNCTIONS over a 1 Mb window and compare raw vs. aligned ALT - REF across a downstream interval ~20 kb away (chr22:36,220,000-36,260,000) where the deletion has little true biological effect:

deletion = genome.Variant(
    chromosome='chr22',
    position=36201691,
    reference_bases='CGGACTCACCCGACGC',
    alternate_bases='C',
    name='APOL4_15bp_del',
)
del_interval = deletion.reference_interval.resize(
    dna_client.SEQUENCE_LENGTH_1MB
)
colon_condition = 'UBERON:0001159'  # Sigmoid colon.

del_output = dna_model.predict_variant(
    interval=del_interval,
    variant=deletion,
    condition=colon_condition,
    requested_outputs=[
        dna_client.OutputType.RNA_SEQ,
        dna_client.OutputType.SPLICE_SITES,
        dna_client.OutputType.SPLICE_JUNCTIONS,
    ],
)

ref_del = del_output.reference.filter_to_observed()
alt_del = del_output.alternate.filter_to_observed()
aligned_alt_rna = alt_del.rna_seq.align_alternate(deletion)
aligned_alt_ss = alt_del.splice_sites.align_alternate(deletion)

downstream_interval = genome.Interval('chr22', 36_220_000, 36_260_000)
unaligned_rna_diff = (alt_del.rna_seq - ref_del.rna_seq).slice_by_interval(
    downstream_interval
)
aligned_rna_diff = (aligned_alt_rna - ref_del.rna_seq).slice_by_interval(
    downstream_interval
)
unaligned_ss_diff = (
    alt_del.splice_sites - ref_del.splice_sites
).slice_by_interval(downstream_interval)
aligned_ss_diff = (aligned_alt_ss - ref_del.splice_sites).slice_by_interval(
    downstream_interval
)

print(
    f'REF shape: {ref_del.rna_seq.values.shape}, '
    f'ALT shape: {alt_del.rna_seq.values.shape}'
)
print(
    'Downstream [36.22-36.26 Mb] max |ALT - REF| RNA-seq: '
    f'unaligned={np.abs(unaligned_rna_diff.values).max():.4f}, '
    f'aligned={np.abs(aligned_rna_diff.values).max():.4f}'
)
print(
    'Downstream [36.22-36.26 Mb] max |ALT - REF| splice sites: '
    f'unaligned={np.abs(unaligned_ss_diff.values).max():.4f}, '
    f'aligned={np.abs(aligned_ss_diff.values).max():.4f}'
)
REF shape: (1048576, 5), ALT shape: (1048576, 5)
Downstream [36.22-36.26 Mb] max |ALT - REF| RNA-seq: unaligned=1.5655, aligned=0.0394
Downstream [36.22-36.26 Mb] max |ALT - REF| splice sites: unaligned=0.9954, aligned=0.0089

Plot the unaligned vs. aligned ALT - REF differences across a zoomed-in 4 kb slice of that downstream region. Without TrackData.align_alternate(), every shifted splice donor/acceptor produces a fake positive/negative doublet spike (~±1.0), and exon boundaries show spurious coverage spikes; after alignment, those shift artifacts disappear:

# Zoom around the largest unaligned splice-site shift artifact downstream.
unaligned_ss_neg = unaligned_ss_diff.filter_to_negative_strand()
aligned_ss_neg = aligned_ss_diff.filter_to_negative_strand()

peak_offset = int(
    np.argmax(np.abs(unaligned_ss_neg.values).max(axis=1))
)
zoom_center = downstream_interval.start + peak_offset
zoom_interval = genome.Interval(
    'chr22', zoom_center - 2000, zoom_center + 2000
)

rna_track_mask = (
    (ref_del.rna_seq.metadata['Assay title'] == 'polyA plus RNA-seq')
    & (ref_del.rna_seq.metadata['endedness'] == 'paired')
    & (ref_del.rna_seq.metadata['strand'] == '-')
).values

unaligned_ss_zoom = unaligned_ss_neg.slice_by_interval(zoom_interval)
aligned_ss_zoom = aligned_ss_neg.slice_by_interval(zoom_interval)
unaligned_rna_zoom = unaligned_rna_diff.filter_tracks(
    rna_track_mask
).slice_by_interval(zoom_interval)
aligned_rna_zoom = aligned_rna_diff.filter_tracks(
    rna_track_mask
).slice_by_interval(zoom_interval)

ss_lim = float(np.abs(unaligned_ss_zoom.values).max()) * 1.1
rna_lim = float(np.abs(unaligned_rna_zoom.values).max()) * 1.1

plot_components.plot(
    [
        plot_components.TranscriptAnnotation(
            transcript_extractor.extract(zoom_interval)
        ),
        plot_components.Tracks(
            unaligned_ss_zoom,
            ylabel_template='Unaligned\nsplice {splice_site_type} ({strand})',
            filled=True,
            shared_y_scale=True,
            global_ylims=(-ss_lim, ss_lim),
            track_colors='#D95F02',
        ),
        plot_components.Tracks(
            aligned_ss_zoom,
            ylabel_template='Aligned\nsplice {splice_site_type} ({strand})',
            filled=True,
            shared_y_scale=True,
            global_ylims=(-ss_lim, ss_lim),
            track_colors='#1F78B4',
        ),
        plot_components.Tracks(
            unaligned_rna_zoom,
            ylabel_template='Unaligned\nRNA-seq ({strand})',
            filled=True,
            shared_y_scale=True,
            global_ylims=(-rna_lim, rna_lim),
            track_colors='#D95F02',
        ),
        plot_components.Tracks(
            aligned_rna_zoom,
            ylabel_template='Aligned\nRNA-seq ({strand})',
            filled=True,
            shared_y_scale=True,
            global_ylims=(-rna_lim, rna_lim),
            track_colors='#1F78B4',
        ),
    ],
    interval=zoom_interval,
    fig_width=14,
    title='Downstream region: unaligned vs. align_alternate() (ALT - REF)',
)
plt.show()
../../_images/dcfc4237ce73eade3b567343bfcc7076c805fa2c3a317c2559b7a0fd52d85033.png

Compare splice junctions directly with -#

Unlike continuous 1-bp tracks, predicted splice junctions (output.alternate.splice_junctions) are already returned in reference coordinates even for indels, so you do not need to align them manually. For example, downstream of our 15-bp deletion at chr22:36,201,691, the junction chr22:36201796-36201992:- appears at those exact same genomic coordinates in both del_output.reference.splice_junctions and del_output.alternate.splice_junctions (rather than shifted 15 bp left to 36201781-36201977). Note that because inserted bases have no reference coordinates of their own, any splice site created inside an insertion is collapsed onto the variant’s anchor coordinate: a new cryptic junction is still reported at the insertion site, but to resolve exact base-by-base positions (or multiple splice sites) inside a long insertion, inspect the unaligned 1-bp output.alternate.splice_sites track directly.

You can subtract splice junctions directly with alt.splice_junctions - ref.splice_junctions (or (output.alternate - output.reference).splice_junctions). For predict_variant() outputs, both alleles are already evaluated on the same union of splice sites in matching order; when comparing separate predict_interval() / predict_sequence() calls or pre-filtered JunctionData objects with differing junction sets, - aligns them over the union sorted by (chromosome, strand, start, end) and treats absent junctions as zero. Because plot_components.Sashimi only renders non-negative junction counts (k >= 0), inspect signed deltas directly from .values (or plot positive gains and negative losses separately). Below we tabulate the largest gained and lost negative-strand junctions in a pd.DataFrame:

delta_junctions = alt_del.splice_junctions - ref_del.splice_junctions
neg_delta = delta_junctions.filter_to_negative_strand()
gtex_col = int(np.flatnonzero(neg_delta.metadata['data_source'] == 'gtex')[0])

top_idx = np.argsort(np.abs(neg_delta.values[:, gtex_col]))[::-1][:8]
pd.DataFrame({
    'junction': [str(neg_delta.junctions[i]) for i in top_idx],
    'delta_gtex_counts': np.round(neg_delta.values[top_idx, gtex_col], 3),
})
junction delta_gtex_counts
0 chr22:36191912-36195310:- -1.142
1 chr22:36195437-36199329:- -0.944
2 chr22:36199376-36201699:- -0.572
3 chr22:36195437-36201699:- 0.050
4 chr22:36199608-36201699:- 0.039
5 chr22:36191912-36201699:- 0.039
6 chr22:36199369-36201699:- 0.038
7 chr22:36199376-36201992:- 0.033

When not to align: insertions creating a local regulatory feature#

TrackData.align_alternate() replicates the alignment used server-side by coordinate-anchored scorers (GeneMaskLFCScorer, GeneMaskActiveScorer, GeneMaskSplicingScorer, MethylationScorer, PolyadenylationScorer, and SpliceJunctionScorer):

  • Deletions insert zeros at the deleted reference positions and shift downstream bases right.

  • Insertions collapse the anchor + inserted bases into a single position via max, shift downstream bases left, and zero-pad up to len(alt) - len(ref) trailing positions (always align before calling slice_by_interval() so predicted bases just past the zoom window are shifted in rather than zero-padded).

By contrast, server-side variant-centered scorers (CenterMaskScorer, used for DNASE, ATAC, SC_ATAC, CHIP_TF, CHIP_HISTONE, and CAGE in AlphaGenome 2, plus PROCAP in AlphaGenome 1) do not align ALT tracks: they aggregate raw REF and raw ALT over the same fixed-width window centered on variant.start. When an insertion creates a local feature—such as the 12-bp TAL1 5’ MuTE insertion in Jurkat T-ALL cells (chr1:47239296:C>CCGTTTCCTAACC, Mansour et al. 2014) that creates a de novo MYB binding site and chromatin accessibility peak—keeping DNASE unaligned preserves every predicted base inside the insertion and matches CenterMaskScorer exactly:

insertion = genome.Variant(
    chromosome='chr1',
    position=47239296,
    reference_bases='C',
    alternate_bases='CCGTTTCCTAACC',
    name='TAL1_Jurkat_12bp_ins',
)
ins_interval = insertion.reference_interval.resize(
    dna_client.SEQUENCE_LENGTH_1MB
)
cmp_condition = 'UBERON:0002371_CL:0001059'  # CD34+ common myeloid progenitors.

ins_output = dna_model.predict_variant(
    interval=ins_interval,
    variant=insertion,
    condition=cmp_condition,
    requested_outputs=[
        dna_client.OutputType.RNA_SEQ,
        dna_client.OutputType.DNASE,
    ],
)

ref_ins = ins_output.reference.filter_to_observed()
alt_ins = ins_output.alternate.filter_to_observed()
ref_dnase = ref_ins.dnase[:, :1]
alt_dnase = alt_ins.dnase[:, :1]
aligned_alt_dnase = alt_dnase.align_alternate(insertion)

center_window = insertion.reference_interval.resize(501)
ref_sum = float(ref_dnase.slice_by_interval(center_window).values.sum())
raw_alt_sum = float(alt_dnase.slice_by_interval(center_window).values.sum())
aligned_alt_sum = float(
    aligned_alt_dnase.slice_by_interval(center_window).values.sum()
)

raw_l2fc = np.log2((raw_alt_sum + 1.0) / (ref_sum + 1.0))
aligned_l2fc = np.log2((aligned_alt_sum + 1.0) / (ref_sum + 1.0))

dnase_scores = dna_model.score_variant(
    interval=ins_interval,
    variant=insertion,
    condition=cmp_condition,
    variant_scorers=[variant_scorers.RECOMMENDED_VARIANT_SCORERS['DNASE']],
)
dnase_df = variant_scorers.tidy_scores(dnase_scores)
server_score = float(
    dnase_df[
        dnase_df['track_name'] == ref_dnase.metadata['name'].iloc[0]
    ]['raw_score'].iloc[0]
)

print(f'Unaligned 501-bp DNase log2FC : {raw_l2fc:.4f}')
print(f'Server CenterMaskScorer DNASE : {server_score:.4f}')
print(f'Aligned (max-collapsed) log2FC: {aligned_l2fc:.4f}')
Unaligned 501-bp DNase log2FC : 1.3482
Server CenterMaskScorer DNASE : 1.3482
Aligned (max-collapsed) log2FC: 1.3714

Notice that the max-collapsed 501-bp DNase log2FC (1.3714) differs slightly from the unaligned CenterMaskScorer score (1.3482), and is slightly higher here, because collapsing drops 12 interior bases inside the insertion and pulls 12 flanking bases in from just past the right edge of the window.

At the TAL1 locus, you can combine both strategies in one plot: align 1-bp RNA_SEQ with TrackData.align_alternate() so coordinates stay aligned to the reference genome across the interval (here TAL1 lies upstream/left of the insertion at 47,239,296, so its exons are unchanged while any downstream coordinates stay aligned), while keeping DNASE unaligned around the insertion summit:

aligned_alt_tal1_rna = alt_ins.rna_seq.align_alternate(insertion)
tal1_interval = genome.Interval('chr1', 47_215_000, 47_245_000)
ref_alt_colors = {'REF': '#22AAE1', 'ALT': 'red'}

plot_components.plot(
    [
        plot_components.TranscriptAnnotation(
            transcript_extractor.extract(tal1_interval)
        ),
        plot_components.OverlaidTracks(
            {
                'REF': ref_ins.rna_seq,
                'ALT': aligned_alt_tal1_rna,
            },
            colors=ref_alt_colors,
            ylabel_template='RNA-seq (aligned)\n{Assay title}',
        ),
        plot_components.OverlaidTracks(
            {'REF': ref_dnase, 'ALT': alt_dnase},
            colors=ref_alt_colors,
            ylabel_template='DNase (unaligned)\n{Assay title}',
        ),
    ],
    interval=tal1_interval,
    fig_width=14,
    annotations=[plot_components.VariantAnnotation([insertion], alpha=0.8)],
    title='TAL1 12-bp insertion: aligned RNA-seq + unaligned local DNase peak',
)
plt.show()
../../_images/12f3b5c004c78b369f0fbc39aa95f18c7003ec7b73179a9b0d5c4c61f13901ed.png

Server-side indel scoring with score_variant()#

When you only need scalar variant effect scores, prefer dna_model.score_variant(): the server automatically applies the appropriate indel handling for each scorer (coordinate alignment for GeneMaskLFCScorer, GeneMaskActiveScorer, GeneMaskSplicingScorer, MethylationScorer, PolyadenylationScorer, and SpliceJunctionScorer; unaligned center windows for CenterMaskScorer).

Note on score thresholds: Indel effect scores follow a different distribution than SNV scores (typically broader and dependent on indel length), because inserting or deleting multiple bases perturbs sequence context and regulatory spacing more strongly than a single-nucleotide substitution. Avoid applying SNV-calibrated cutoffs directly to indels or mixing SNVs and indels under a single threshold; instead, use separate thresholds for indels or compare them against length-matched control indels (as shown in the TAL1 vignette):

del_scores = dna_model.score_variant(
    interval=del_interval,
    variant=deletion,
    condition=colon_condition,
    variant_scorers=[
        variant_scorers.RECOMMENDED_VARIANT_SCORERS[k]
        for k in ('RNA_SEQ', 'SPLICE_SITES', 'SPLICE_JUNCTIONS')
    ],
)
del_tidy = variant_scorers.tidy_scores(del_scores, match_gene_strand=True)
del_tidy[
    (del_tidy['gene_name'] == 'APOL4')
    & (del_tidy['imputation_mode'] == 'observed')
][['output_type', 'track_name', 'raw_score']]
output_type track_name raw_score
5 RNA_SEQ UBERON:0001159_polyA plus RNA-seq-encode-paired-ended -1.397843
7 RNA_SEQ UBERON:0001159_total RNA-seq-encode-paired-ended -1.879232
9 RNA_SEQ UBERON:0001159_polyA plus RNA-seq-gtex-paired-ended -1.615020
185 SPLICE_SITES UBERON:0001159_donor 0.895985
186 SPLICE_SITES UBERON:0001159_acceptor 0.364272
187 SPLICE_JUNCTIONS UBERON:0001159_polyA plus RNA-seq-encode 4.933594
188 SPLICE_JUNCTIONS UBERON:0001159_polyA plus RNA-seq-gtex 5.261719
189 SPLICE_JUNCTIONS UBERON:0001159_total RNA-seq-encode 4.882812

Next steps#