R/qtl2ggplot Vignette

Brian S. Yandell

2022-01-24

Whole Genome Allele Scan

Load example DO data from web. For convenience, we attach package ‘ggplot2’ for the autoplot function. Functions from ‘qtl2’ are explicitly referenced with prefix qtl2::.

library(qtl2ggplot)
library(ggplot2)

Download ‘qtl2’ cross2 object.

DOex <- 
  qtl2::read_cross2(
    file.path(
      "https://raw.githubusercontent.com/rqtl",
       "qtl2data/master/DOex",
       "DOex.zip"))

With multiple alleles, it is useful to examine an additive allele model. Download pre-calculated allele probabilities (~5 MB) as follows:

tmpfile <- tempfile()
file <- paste0("https://raw.githubusercontent.com/rqtl/",
               "qtl2data/master/DOex/DOex_alleleprobs.rds")
download.file(file, tmpfile)
apr <- readRDS(tmpfile)
unlink(tmpfile)

Alternatively, calculate these directly.

pr <- qtl2::calc_genoprob(DOex, error_prob=0.002)
apr <- qtl2::genoprob_to_alleleprob(pr)

Genome allele scan.

scan_apr <- qtl2::scan1(apr, DOex$pheno)

Summary of peaks.

qtl2::find_peaks(scan_apr, DOex$pmap)
##   lodindex       lodcolumn chr      pos       lod
## 1        1 OF_immobile_pct   2 96.84223 10.173313
## 2        1 OF_immobile_pct   3 15.02006  5.971503
## 3        1 OF_immobile_pct   X 74.57257  6.939151

New summary method:

summary(scan_apr, DOex$pmap)
## # A tibble: 3 × 5
##   pheno           chr     pos   lod marker            
##   <chr>           <fct> <dbl> <dbl> <chr>             
## 1 OF_immobile_pct 2      96.8 10.2  backupUNC020000070
## 2 OF_immobile_pct 3      15.0  5.97 backupUNC030729939
## 3 OF_immobile_pct X      74.6  6.94 UNC200000454

The basic plot of genome scan,

plot(scan_apr, DOex$pmap)

and the grammar of graphics (ggplot2) version.

autoplot(scan_apr, DOex$pmap)

Genome Allele Scan for Chr 2

Subset to chr 2.

DOex <- DOex[,"2"]
apr <- subset(apr, chr = "2")

Scan chromosome and summarize peak

scan_apr <- qtl2::scan1(apr, DOex$pheno)
qtl2::find_peaks(scan_apr, DOex$pmap)
##   lodindex       lodcolumn chr      pos      lod
## 1        1 OF_immobile_pct   2 96.84223 10.17331
plot(scan_apr, DOex$pmap)

autoplot(scan_apr, DOex$pmap)

Examine coefficients for the 8 alleles

coefs <- qtl2::scan1coef(apr, DOex$pheno)

New summary method:

summary(coefs, scan_apr, DOex$pmap)
## # A tibble: 1 × 14
##   pheno    chr     pos   lod marker        A     B     C     D     E     F     G
##   <chr>    <fct> <dbl> <dbl> <chr>     <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 OF_immo… 2      96.8  10.2 backupUN… -6.93 -3.80 -6.27 -5.97 -30.1 -14.3 -3.87
## # … with 2 more variables: H <dbl>, intercept <dbl>
plot(coefs, DOex$pmap, 1:8, col = qtl2::CCcolors)

autoplot(coefs, DOex$pmap)

Plot allele effects over LOD scan.

plot(coefs, DOex$pmap, 1:8, col = qtl2::CCcolors, scan1_output = scan_apr)

autoplot(coefs, DOex$pmap, scan1_output = scan_apr,
         legend.position = "none")

Examine just some of the founder effects, without centering.

plot(coefs, DOex$pmap, c(5,8), col = qtl2::CCcolors[c(5,8)])

autoplot(coefs, DOex$pmap, c(5,8))

autoplot(coefs, DOex$pmap, c(5,8), facet = "geno")

plot(coefs, DOex$pmap, 4:5, col = qtl2::CCcolors[4:5], scan1_output = scan_apr)