View source: R/addAnnotation.R
addAnnotation | R Documentation |
This function takes a ggplot2
object generated using plotMiro
function and adds extra annotation on top of query
or target coordinates. These ranges are specified in 'annot.gr' object and are visualized either as arrowheads or rectangles.
addAnnotation(
ggplot.obj = NULL,
annot.gr = NULL,
shape = "arrowhead",
fill.by = NULL,
label.by = NULL,
color.palette = NULL,
max.colors = 20,
coordinate.space = "target",
annotation.group = NULL,
annotation.level = 0.05,
offset.annotation = FALSE,
annotation.label = NULL,
y.label.id = NULL
)
ggplot.obj |
A |
annot.gr |
A |
shape |
A user defined shape ranges in 'annot.gr' are visualized, either 'arrowhead' or 'rectangle'. |
fill.by |
A name of an extra field present in 'annot.gr' to be used to define color scheme. |
label.by |
A name of an extra field present in 'annot.gr' to be used as a label over each annotation range. |
color.palette |
A discrete color palette defined as named character vector (elements = colors, names = discrete levels). |
max.colors |
A maximum number of discrete color levels for which legend will be reported. If more than that legend will be removed. |
coordinate.space |
A coordinate space ranges in 'annot.gr' are reported, either 'target', 'query' or 'self'. |
annotation.group |
A name of an extra field present in 'annot.gr' to be used to connect set of ranges of the same group by a straight black line (Useful to plot exons from one or multiple genes). |
annotation.level |
A |
offset.annotation |
Set to |
annotation.label |
A |
y.label.id |
A user defined metadata column id within 'annot.gr' that for each annotation range contains corresponding y-axis label. |
A ggplot2
object.
David Porubsky
## Get PAF to plot
paf.file <- system.file("extdata", "test1.paf", package = "SVbyEye")
## Read in PAF
paf.table <- readPaf(paf.file = paf.file, include.paf.tags = TRUE, restrict.paf.tags = "cg")
## Make a plot
plt <- plotMiro(paf.table = paf.table)
## Load target annotation file
target.annot <- system.file("extdata", "test1_target_annot.txt", package = "SVbyEye")
target.annot.df <- read.table(target.annot, header = TRUE, sep = "\t", stringsAsFactors = FALSE)
target.annot.gr <- GenomicRanges::makeGRangesFromDataFrame(target.annot.df)
## Add target annotation as arrowhead
plt <- addAnnotation(ggplot.obj = plt, annot.gr = target.annot.gr, coordinate.space = "target")
## Load query annotation file
query.annot <- system.file("extdata", "test1_query_annot.txt", package = "SVbyEye")
query.annot.df <- read.table(query.annot, header = TRUE, sep = "\t", stringsAsFactors = FALSE)
query.annot.gr <- GenomicRanges::makeGRangesFromDataFrame(query.annot.df)
## Add query annotation as rectangle
addAnnotation(
ggplot.obj = plt, annot.gr = query.annot.gr, shape = "rectangle",
coordinate.space = "query"
)
## Add segmental duplication annotation
plt <- plotMiro(paf.table = paf.table)
sd.annot <- system.file("extdata", "test1.sd.annot.RData", package = "SVbyEye")
sd.annot.gr <- get(load(sd.annot))
## Create a custom discrete levels
sd.categ <- findInterval(sd.annot.gr$fracMatch, vec = c(0.95, 0.98, 0.99))
sd.categ <- dplyr::recode(sd.categ, "0" = "<95%", "1" = "95-98%", "2" = "98-99%", "3" = ">=99%")
sd.categ <- factor(sd.categ, levels = c("<95%", "95-98%", "98-99%", ">=99%"))
sd.annot.gr$sd.categ <- sd.categ
## Create a custom color palette
color.palette <- c(
"<95%" = "gray72", "95-98%" = "gray47", "98-99%" = "#cccc00",
">=99%" = "#ff6700"
)
## Add annotation to the plot
addAnnotation(
ggplot.obj = plt, annot.gr = sd.annot.gr, fill.by = "sd.categ",
color.palette = color.palette, coordinate.space = "target"
)
## Offset annotation ranges
addAnnotation(
ggplot.obj = plt, annot.gr = sd.annot.gr, fill.by = "sd.categ",
color.palette = color.palette, coordinate.space = "target", offset.annotation = TRUE
)
## Add label to the added annotation
addAnnotation(
ggplot.obj = plt, annot.gr = sd.annot.gr, fill.by = "sd.categ",
color.palette = color.palette, coordinate.space = "target", annotation.label = "SD"
)
## Add gene-like annotation
test.gr <- GenomicRanges::GRanges(
seqnames = "target.region",
ranges = IRanges::IRanges(
start = c(19000000, 19030000, 19070000),
end = c(19010000, 19050000, 19090000)
),
ID = "gene1"
)
addAnnotation(
ggplot.obj = plt, annot.gr = test.gr, coordinate.space = "target",
shape = "rectangle", annotation.group = "ID", offset.annotation = TRUE,
fill.by = "ID"
)
## Add gene names
addAnnotation(
ggplot.obj = plt, annot.gr = test.gr, coordinate.space = "target",
shape = "rectangle", annotation.group = "ID", offset.annotation = TRUE,
fill.by = "ID", label.by = "ID"
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.