knitr::opts_chunk$set(
  message = FALSE,
  collapse = TRUE,
  comment = "#>"
  )
library(topr)
library(magrittr)
set.seed(0)

The topr package is a set of functions used to visualize, explore and annotate genetic association results. In particular, using only the chromosome, position and p-value of each variant in results dataframes, topr makes it easy to display gene annotations and multiple traits in a single manhattan plot. Other functionality includes regional plots & locus zoom plots.

Exploration with built-in data

The package comes with 3 sample datasets, namely CD_UKBB, CD_FINNGEN & UC_UKBB.

Let's look at the CD_UKBB dataset:

head(CD_UKBB)

Note that while there are extra columns in the sample data, the only columns required for plotting are CHROM, POS and P.

Single dataset plotting

manhattan(CD_UKBB)
manhattan(CD_UKBB, annotate=5e-9)
regionplot(CD_UKBB, gene="IL23R")

Multiple dataset plotting

In addition to plotting a single dataset, topr can also plot multiple datasets in a single manhattan/region plot.

manhattan(list(CD_UKBB, CD_FINNGEN), legend_labels = c("UKBB", "FinnGen"))
regionplot(list(CD_UKBB, CD_FINNGEN), gene="IL23R", legend_labels = c("UKBB", "FinnGen"))

Other useful functions

Extract lead/index variants from the GWAS dataset (CD_UKBB):

get_lead_snps(CD_UKBB) %>%
  dplyr::arrange(P) %>%
  head()

Annotate the lead/index variants with their nearest gene & biotype:

get_lead_snps(CD_UKBB) %>%
  annotate_with_nearest_gene() %>%
  dplyr::arrange(P) %>%
  head()

Get genomic coordinates for a gene (topr uses genome build GRCh38.p13 by default):

get_gene_coords("IL23R")

Get genomic coordinates for a gene using genome build GRCh37 instead.

get_gene_coords("IL23R", build="37")

Get snps within a region:

get_snps_within_region(CD_UKBB, region="chr1:67138906-67259979") %>%
  head()

Get the top variant on a chromosome:

get_top_snp(CD_UKBB, chr="chr1")

Create a snpset by extracting the top/lead variants from the CD_UKBB dataset and overlapping variants (by position) in the CD_FINNGEN dataset.

get_snpset(CD_UKBB, CD_FINNGEN)


GenuityScience/topr documentation built on Oct. 20, 2024, 10:23 p.m.