Regional Association Plots in CanvasXpress

You run a GWAS, you get a hit, and the next figure is always the same one: zoom into the locus, plot -log10(p) against genomic position, colour the points by how tightly they're linked to the lead SNP, and draw the genes underneath so a reader can see what the signal is sitting on. The regional association plot — the LocusZoom figure — is how an association becomes a biological claim.

It's also a figure that has historically lived apart from the rest of your analysis. You either upload summary statistics to a web tool, or you produce it in a dedicated R package that draws base graphics. Either way it leaves your stack: it isn't the same chart engine as the rest of your report, it isn't interactive, and the figure that lands in the manuscript carries no record of what produced it.

CanvasXpress now draws this figure natively — in JavaScript, R and Python, from one engine and one portable specification.

It's two tracks, not a new chart type

The interesting part of building this was how little of it turned out to be new.

A regional association plot is a genome browser with two tracks. The top one is a scatter of association strength against position, with a second value axis on the right for the recombination rate. The bottom one is a set of gene models — exon boxes on an intron backbone, with the strand marked on each name.

CanvasXpress's Genome graph type already had the hard parts: a shared genomic window across stacked tracks, independent left and right value axes per track, gene models with exons and strand, greedy row packing that accounts for how wide each gene's label renders, and live pan/zoom. A prototype built from parameters that already shipped produced a recognisable LocusZoom plot before a line of new rendering code was written.

So the work became a short list of things the figure needed and the genome browser didn't yet have — and each of those turned out to be useful well beyond this one plot.

Annotations on genome charts

Genome charts can now carry the same annotation vocabulary every other CanvasXpress chart type uses: reference lines, text, labels and markers. That's what draws the dashed genome-wide significance line at 5e-8, and what labels a SNP with a leader line back to its point.

Because a genome chart has a shared x window but a separate value scale for each track, an annotation says which track it belongs to with scope, and which of that track's two scales to use with side:

decorations: {
  line: [
    { y: 7.30103, type: "dashed", color: "rgb(169,169,169)" },  // 5e-8, left scale
    { y: 50, side: "right", color: "green" }                    // recombination scale
  ],
  marker: [
    { type: "text", text: "rs1011063", x: 21963869, y: 21.99,
      offsetX: 28, offsetY: 24 }                                // labelled with a leader line
  ]
}

A genomic axis that reads like one

Genomic coordinates are long numbers, and 21900000 is not how anyone discusses a locus. The axis now speaks megabases, kilobases, or plain base pairs — genomeTicksUnit: "Mb" | "kb" | "bp" | "auto" — with auto choosing from the width of the window. It carries a title (Chromosome 22 (Mb)), and genomeTicksPosition can place it directly under the association panel instead of beneath every annotation track, which is where a regional plot usually wants it.

Axis lines are drawable too, per side, using the same xAxisLine* / yAxisLine* settings as every other chart type — so you can have an L-shaped frame, a full box, or nothing at all.

The gene you're plotting keeps its row

Gene tracks get crowded. A window around a gene of interest can easily hold twenty transcripts, and when there are more rows than the track height allows, something has to go.

Previously the rows filled in coordinate order, which meant the gene the plot is about could be the one that dropped off. featurePriority fixes that: list the names you care about, or whole classes of them, and they take the first rows.

featurePriority: ["UBE2L3", "protein_coding"]

It matches a feature's name or its class — so that single line means "my gene first, then the protein-coding ones, then whatever fits." In a window capped at three rows, the difference is literally whether UBE2L3 appears in its own locus plot.

There's also genomeTrackPadding, which lifts the lowest points clear of the axis line rather than letting them sit on it.

One figure, three languages

This is the part that matters if you work across a team. The same figure is one call in each language.

In R:

cx_locus(gwas, genes = transcripts, recomb = recombination,
         ld = "r2", highlight = "UBE2L3")

In Python:

from canvasxpress.genomics import locus_plot

locus_plot(gwas, genes=transcripts, recomb=recombination,
           ld="r2", highlight=["UBE2L3"])

Both infer your column names the way you'd expect — a chromosome column, a position column, a p-value column, an rsid column, an r² column — or let you name them. Both pick the lead SNP as the smallest p-value unless you name one. Both bin r² into the five familiar linkage classes and draw the lead SNP as a diamond on top. And both produce the same portable specification the JavaScript engine renders, so a figure built in R is the same object as one built in Python.

If you don't have LD for your variants, you don't need a different function: points fall back to being coloured by whether they clear the significance threshold, and you can shape them by the direction of effect instead.

Ask for it in plain English

The CanvasXpress MCP server gained a create_locus_config tool, so an AI agent connected to it can build this figure from a table and a sentence — "plot the association signal around TYK2" — and get back a validated specification rather than a guess. The vocabulary routes properly too: asking for a "locuszoom plot" or a "regional association plot" reaches the tool that can actually build one.

A live one, on real data

The GENCODE Explorer dashboard now has a regional association view alongside its genome browser. Search a gene and you get its transcript models with the GWAS Catalog associations in that window plotted as -log10(p) above them — drawn from the reference databases the dashboards already ship, with no new data source.

Why it being the same engine matters

Because this is an ordinary CanvasXpress chart, it inherits everything else. You can zoom and pan the locus live. You can save it as a PNG that carries its own specification inside the file — drag that PNG back onto a canvas and the chart comes back, data and all. You can drop it into a dashboard beside the expression and survival panels for the same gene, and have them filter together. And the figure in your manuscript can be traced back to exactly the specification that produced it.

The regional association plot has spent a long time as a special-case figure made by a special-case tool. It doesn't have to be.