Here we demonstrate how to use the zoom browser to interactively browse whole genome GWAS or eQTL data within an R session. Via a shiny/plotly interface, users can click on peaks in a whole genome manhattan plot to zoom in and out of regions and pan left or right using the interactive browser.
Example whole genome summary statistics from an SLE GWAS study can be downloaded from EBI here and loaded as follows. The main locuszoomr vignette shows how this data is formatted.
# FTP download full summary statistics (308 MB) from SLE GWAS from
# https://www.ebi.ac.uk/gwas/studies/GCST003156
library(data.table)
SLE_gwas <- fread('../bentham_2015_26502338_sle_efo0002690_1_gwas.sumstats.tsv')
The zoom browser is started using zoom(). Like the
locus() function, zoom() tries to autodetect
the columns for SNP id, chromosome, position and p-value. If you have
complex or ambiguous column names, then the arguments
chrom, pos, p and
labs can be used to specify the appropriate columns in your
dataset.
An appropriate hg19 or hg38 (or other species) ensembl database of genome information must be specified. In the example below, the GWAS data is hg19.
library(locuszoomr)
library(EnsDb.Hsapiens.v75)
zoom(SLE_gwas, ens_db = "EnsDb.Hsapiens.v75")
Recombination rate can be shown on a secondary y axis. Whole recombination rate track data file (around 30 MB) should be downloaded from UCSC genome browser (documented here).
The download site can be accessed at https://hgdownload.soe.ucsc.edu/gbdb/hg38/recombRate/.
For hg38, download recomb1000GAvg.bw.
For hg19, the link is https://hgdownload.soe.ucsc.edu/gbdb/hg19/decode/ and
the default track we use is
hapMapRelease24CombinedRecombMap.bw.
The .bw track file can then be loaded into R as a
GRanges object using import.bw(), and then
used directly by zoom().
library(rtracklayer)
recomb.hg19 <- import.bw("/../hapMapRelease24CombinedRecombMap.bw")
zoom(SLE_gwas, ens_db = "EnsDb.Hsapiens.v75", recomb = recomb.hg19)
The LDlink API can be queried from within the zoom browser. This
requires an LDlink API access token, which can be obtained from the LDlink website. The token is
then supplied via the ld_token argument when calling
zoom().
zoom(SLE_gwas, ens_db = "EnsDb.Hsapiens.v75", recomb = recomb.hg19, ld_token = "my_token")
This enables extra buttons for LD, eQTL and
GWAS Catalog in the navigation bar. LD API requests are
cached and retained during an R session, so subsequent requests for the
same SNP are much faster. At each locus, the SNP with the lowest p-value
is presumed to be the index SNP for LD requests. But clicking on other
points can re-base the LD to alternative SNPs.
The LDlink API can also be queried for eQTL data which can be
overlaid on the GWAS plots by clicking on the eQTL button.
The plot below shows how the top GWAS SNPs in the IRF5 locus
are linked to an IRF5 eQTL.
Each SNP may have an eQTL which drives gene expression across multiple tissues and some SNPs have eQTL with multiple genes. So by default the overlay plots show the eQTL at each SNP with the lowest p-value. eQTL genes and tissues can be filtered using picker menus which become available in the Settings menu.
Instead of querying LDlink for GWAS Catalog associations SNP by SNP,
the whole GWAS Catalog can be
downloaded once and shown at every locus.
download_gwas_catalog() downloads the Catalog associations
(about 90 MB), the Catalog trait mappings (for trait categories) and the
UCSC hg38ToHg19 liftOver chain (for GRCh37 positions). It then prepares
them and saves a copy of about 25 MB in the locuszoomr cache directory
(see tools::R_user_dir()). It asks before downloading and
needs the data.table package. The Catalog is updated
weekly; run download_gwas_catalog() again to update the
cached copy.
download_gwas_catalog()
zoom(SLE_gwas, ens_db = "EnsDb.Hsapiens.v75", recomb = recomb.hg19,
gwas_catalog = TRUE, ld_token = "my_token")
With gwas_catalog = TRUE, every Catalog association in
the window is shown in the GWAS Catalog track below the GWAS plot,
coloured by trait, at each locus as you browse. No API requests are
made, so this also works without an LDlink token. A
show GWAS Catalog checkbox in the
settings menu turns the track off. Picker menus can be used to filter
the track by trait and trait category. A table of associations is also
available in the GWAS Catalog table tab at the top of the page.
With an LDlink token, when LD is fetched by pressing the
LD button, the Catalog associations at SNPs in the GWAS
data are coloured by their LD with the index SNP, using the same colours
as the GWAS plot.
The prepared Catalog can also be loaded and used outside the browser:
gcat <- load_gwas_catalog()
loc <- locus(SLE_gwas, gene = "IRF5", flank = 5e5, ens_db = "EnsDb.Hsapiens.v75")
loc <- link_gwas_catalog(loc, gcat)
locus_plotly(loc)
A Catalog prepared with prep_gwas_catalog() from your
own downloaded files can be passed to zoom() directly,
either as the object or as the path of a saved .rds file.
The Open Targets button in the navigation bar queries
the Open Targets
Platform for fine-mapped molecular QTL credible sets (eQTL, pQTL,
sQTL and others) containing the index SNP. They are shown in an extra
track, with picker menus to filter by QTL type and gene and a table of
the credible sets. The button appears alongside the LDlink tools, or
with a local GWAS Catalog; Open Targets itself needs no token.
Using the data2 argument, users can browse 2 GWAS at the
same time. Shown below, eQTL data from synovial tissue1 is
compared to data from a rheumatoid arthritis GWAS.2 eQTL data
is best placed first, so that the eqtl_gene argument can be
used to show which gene a SNP drives, as each SNP sometimes drives
multiple genes. The beta argument is used to show up/down
triangles for positive/ negative beta values. It points to the relevant
column of beta values and can be applied to either dataset. But here
NA is used to indicate that beta is not being applied to
the 2nd GWAS dataset.
The display now has 2 whole genome manhattan plots followed by 2 optional chromosome plots for the current locus, followed by the dual layered locus plot. LD information can also be overlaid and either locus plot can be clicked to rebase the LD information.
# load ensembl Homo sapiens database v113
library(AnnotationHub)
ah <- AnnotationHub()
query(ah, c("EnsDb", "Homo sapiens")) # shows latest versions
ensDb_v113 <- ah[["AH119325"]]
# load hg38 recombination rate data downloaded from UCSC
recomb1000G <- import.bw("/../recomb1000GAvg.bw")
# double GWAS, eQTL first
zoom(eqtlres, data2 = RA_gwas, ens_db = ensDb_v113,
eqtl_gene = "gene", beta = c("beta", NA),
recomb = recomb1000G, ld_token = "my_token")
There are 3 methods for saving plots. The easiest is to click the camera icon in the plotly modebar. This exports the plotly as an svg based on the current screen dimensions.
The 2nd method is to click the save icon. This exports the current plot to a pdf using base graphics (note: the formatting will be different).
In the settings dropdown the export filetype can be changed from pdf to plotly. This exports the current plotly locus object as an .rds file. Once loaded back into R, this can be viewed as a standard plotly by calling the object (which generates the html). This also allows the plotly to be embedded in markdown documents as the plotly object will output html when called. The plotly features which don’t rely on shiny for updates are preserved, e.g. hover information. However shiny dependent features such as gene track reordering based on display width won’t function.
The
button next to the save icon produces R code which redraws the current
view as a static base graphics figure, ready to copy into a script and
adjust. The code repeats what the app did: the same window and data
columns, the same LD, eQTL, GWAS Catalog or Open Targets data (fetched
again when the code is run, with the LDlink token read from the
LDLINK_TOKEN environment variable), and the same trait,
category, QTL and gene filters. The extra tracks are drawn by
trait_plot(), qtl_plot() and
overlay_scatter(), which stack with
scatter_plot() and genetracks() using
set_layers(). For example, at IRF5 with LD and the local
GWAS Catalog filtered to r2 >= 0.5:
library(locuszoomr)
library(EnsDb.Hsapiens.v75)
loc <- locus(SLE_gwas, seqname = "7", xrange = c(128083877, 129083877),
ens_db = "EnsDb.Hsapiens.v75", chrom = "chrom", pos = "pos",
p = "p", labs = "rsid", index_snp = "rs35000415")
loc <- link_LD(loc, token = Sys.getenv("LDLINK_TOKEN"), pop = "EUR")
gcat <- load_gwas_catalog()
loc <- link_gwas_catalog(loc, gcat)
oldpar <- set_layers(2)
scatter_plot(loc, xticks = FALSE, r2_min = 0.5)
trait_plot(loc, r2_min = 0.5,
size_by_r2 = FALSE)
genetracks(loc, maxrows = 8)
par(oldpar)
If you use this package please cite as:
Lewis MJ, Wang S. (2025) locuszoomr: an R package for visualising publication-ready regional gene locus plots. Bioinformatics Advances 2025; vbaf006, doi:10.1093/bioadv/vbaf006