Introduction

knitr::opts_chunk$set(echo = TRUE)

# preload to avoid loading messages
library(NanoMethViz)

To install this package, run

if (!requireNamespace("BiocManager", quietly = TRUE))
    install.packages("BiocManager")

BiocManager::install("NanoMethViz")
library(NanoMethViz)

To generate a methylation plot we need 3 components:

The methylation information has been modified from the output of nanopolish/f5c. It has then been compressed and indexed using bgzip() and indexTabix() from the Rsamtools package.

# methylation data stored in tabix file
methy <- system.file(package = "NanoMethViz", "methy_subset.tsv.bgz")

# tabix is just a special gzipped tab-separated-values file
read.table(gzfile(methy), col.names = methy_col_names(), nrows = 6)

The exon annotation was obtained from the Mus.musculus package, and joined into a single table. It is important that the chromosomes share the same convention as that found in the methylation data.

# helper function extracts exons from Mus.musculus package
exon_tibble <- get_exons_mus_musculus()

head(exon_tibble)

We will defined the sample annotation ourselves. It is important that the sample names match those found in the methylation data.

sample <- c(
  "B6Cast_Prom_1_bl6",
  "B6Cast_Prom_1_cast",
  "B6Cast_Prom_2_bl6",
  "B6Cast_Prom_2_cast",
  "B6Cast_Prom_3_bl6",
  "B6Cast_Prom_3_cast"
)

group <- c(
  "bl6",
  "cast",
  "bl6",
  "cast",
  "bl6",
  "cast"
)

sample_anno <- data.frame(sample, group, stringsAsFactors = FALSE)

sample_anno

For convenience we assemble these three pieces of data into a single object.

nmeth_results <- NanoMethResult(methy, sample_anno, exon_tibble)

The genes we have available are

For demonstrative purposes we will plot Peg3.

plot_gene(nmeth_results, "Peg3")

We can also load in some DMR results to highlight DMR regions.

# loading saved results from previous bsseq analysis
bsseq_dmr <- read.table(
    system.file(package = "NanoMethViz", "dmr_subset.tsv.gz"),
    sep = "\t",
    header = TRUE,
    stringsAsFactors = FALSE
)
plot_gene(nmeth_results, "Peg3", anno_regions = bsseq_dmr)

Individual long reads can be visualised using the spaghetti argument.

# warnings have been turned off in this vignette, but this will generally
# generate many warnings as the smoothing for many reads will fail
plot_gene(nmeth_results, "Peg3", anno_regions = bsseq_dmr, spaghetti = TRUE)


Try the NanoMethViz package in your browser

Any scripts or data that you put into this service are public.

NanoMethViz documentation built on Nov. 8, 2020, 4:51 p.m.