pkg <- read.dcf("../DESCRIPTION", fields = "Package")[1]
library(pkg, character.only = TRUE)
library(`r pkg`)

Plotting loci with echoplot

echoplot contains various functions that can be used separately
from the comprehensive echolocatoR::finemap_loci() pipeline.

Generate a multi-view plot of a given locus using echoplot::plot_locus().

The plot is centered on the lead/index SNP. If a list is supplied to zoom * plot_locus() returns a series of ggplot objects bound together with patchwork. One can further modify this object using ggplot2 functions like + theme(). + The modifications will be applied to all tracks at once.

Load example data

Load example dataset of the results from fine-mapping the BST1 locus with finemap_loci(). Original data comes from the recent Nalls et al. (2019) Parkinson's disease GWAS (see ?BST1 for details).

library(ggplot2)
library(patchwork)

root.dir <- tempdir()
locus_dir <- file.path(root.dir,echodata::locus_dir)
dat <- echodata::BST1  
LD_matrix <- echodata::BST1_LD_matrix
LD_reference <- "UKB" # Used for naming saved plots
zoom = "10x"
show_plot <- FALSE

Full window

trk_plot <- echoplot::plot_locus(dat=dat, 
                                 LD_matrix=LD_matrix, 
                                 LD_reference=LD_reference,
                                 locus_dir=locus_dir,  
                                 save_plot=FALSE,
                                 show_plot=show_plot,
                                 zoom=zoom) 
methods::show(trk_plot)

At multiple zooms

trk_zooms <- echoplot::plot_locus(dat=dat, 
                                  LD_matrix=LD_matrix, 
                                  LD_reference=LD_reference,
                                  locus_dir=locus_dir,  
                                  save_plot=FALSE,
                                  show_plot=show_plot,
                                  zoom = c("1x","5x","10x")) 
names(trk_zooms) # Get zoom view names
methods::show(trk_zooms)

Return as list

trk_plot_list <- echoplot::plot_locus(dat=dat, 
                                       LD_matrix=LD_matrix, 
                                       LD_reference=LD_reference,
                                       locus_dir=locus_dir,  
                                       save_plot=FALSE,
                                       show_plot=show_plot,
                                       zoom=zoom,
                                       return_list=TRUE)  
view1_list <- trk_plot_list[[zoom]]
names(view1_list) # Get track names from a particular zoom view

Modify a specific tracks within a view.

# Modify your selected track
modified_track <- view1_list$GWAS + 
                      ggplot2::labs(title = "Modified GWAS") + 
                      ggplot2::theme_dark() +
                      ggplot2::theme(title = ggplot2::element_text(hjust = .5))
# Put it back into your track list
view1_list[["GWAS"]] <- modified_track
# Remove a plot you don't want
view1_list[["Genes"]] <- NULL
# Specify the relative heights of each track (make sure it matches your new # of plots!)
track_heights <- c(.3,.1,.3,1)

# Bind them together and plot
fused_plot <- patchwork::wrap_plots(view1_list, 
                                    heights = track_heights,
                                    ncol = 1)
methods::show(fused_plot)

Using XGR annotations

trk_plot.xgr <- echoplot::plot_locus(dat=dat, 
                                     LD_matrix=LD_matrix, 
                                     LD_reference=LD_reference,
                                     locus_dir=locus_dir, 
                               xgr_libnames=c("ENCODE_TFBS_ClusteredV3_CellTypes"), 
                               save_plot=FALSE,
                               show_plot=show_plot,
                               zoom=zoom)
methods::show(trk_plot.xgr)

Using Roadmap annotations

NOTE: Querying remote genomic data sources (e.g. Roadmap bigwigs) is not currently supported on Windows due to known bugs in rtracklayer.

if(.Platform!="windows"){
    trk_plot.roadmap <- echoplot::plot_locus(dat=dat, 
                                         LD_matrix=LD_matrix, 
                                         LD_reference=LD_reference,
                                         locus_dir=locus_dir,  

                                         roadmap=TRUE, 
                                         roadmap_query="monocyte", 

                                         save_plot=FALSE, 
                                         show_plot=show_plot,
                                         zoom="5x")
}
methods::show(trk_plot.roadmap)

Using Nott_2019 annotations

trk_plot.nott_2019 <- echoplot::plot_locus(dat=dat,  
                                           LD_matrix=LD_matrix, 
                                           LD_reference=LD_reference,
                                           locus_dir=locus_dir, 

                                           nott_epigenome=TRUE,  
                                           nott_binwidth = 200,
                                           nott_regulatory_rects = TRUE, 
                                           nott_show_placseq = TRUE,

                                           save_plot=FALSE,
                                           show_plot=show_plot,
                                           zoom=zoom) 
methods::show(trk_plot.nott_2019)

Using QTL datasets

dat1 <- data.table::copy(dat)
dat2 <- data.table::copy(dat)
# Make fake QTL P-values for the sake a demonstration
dat1$P <- abs(jitter(dat1$P, amount = 1e-15))
dat2$P <- abs(jitter(dat2$P, amount = 1e-16))
dat_ls <- list("fake_eQTL"=dat1, 
               "fake_sQTL"=dat2)

trk_plot.qtl <- echoplot::plot_locus_multi(dat_ls = dat_ls, 
                                           LD_ls = list(LD_matrix,LD_matrix),  
                                           locus_dir = locus_dir,
                                           show_plot = show_plot,
                                           zoom = "10x")
methods::show(trk_plot.qtl)

Session info

utils::sessionInfo()




bschilder/echoplot documentation built on Oct. 26, 2023, 6:55 p.m.