plotDomains: Plot multi-resolution segmentation results

View source: R/domainogram.R

plotDomainsR Documentation

Plot multi-resolution segmentation results

Description

Plot multi-resolution domains resulting from the segmentation function.

Usage

plotDomains(
  domains,
  x.s,
  x.e,
  w2y,
  xlim = NULL,
  wlim = NULL,
  xlab = "",
  add = F,
  ...
)

Arguments

domains

data.frame of segmentation results generated by the segmentation function.

x.s

vector of start coordinates (x axis) defining the represented genomic intervals.

x.e

vector of end coordinates (x axis) defining the represented genomic intervals.

w2y

coordinate mapping for window sizes (y axis) produced by the wSize2yAxis function.

xlim

range of the represented genomic region, which must be indicated as c(xmin, xmax).

wlim

range of represented window sizes, which must be indicated as c(wmin, wmax).

xlab

legend of the x axis.

add

logical, when set to TRUE the plot should overlay an existing multi-resolution plot.

...

optional parameters forwarded to the rect function.

Author(s)

Benjamin Leblanc

See Also

visualizationCoordinates, wSize2yAxis, domainogram, segmentation, plotOptimalSegments

Examples

# Simulate enrichment signal
n <- 2000
Mi <- rep(0, n)
Mi <- Mi + dnorm(1:n, 2.5*n/20,  n/40) + dnorm(1:n, 4*n/20,  50)
Mi <- Mi + 4 * dnorm(1:n, 5*n/10, n/10)
Mi <- Mi + dnorm(1:n, 16*n/20,  n/40) + dnorm(1:n, 17.5*n/20,  50)
Mi <- (Mi/max(Mi))^4 + rnorm(n)/4

# Compute enrichment scores
Yi <- enrichmentScore(Mi)

# Multi-resolution segmentation
seg.c <- segmentation(Yi, name="MRA_demo", wmin=20)

# Load segmentation results
opts <- read.delim(seg.c$file.segments, stringsAsFactors=F, skip=1)
doms <- read.delim(seg.c$file.domains, stringsAsFactors=F)
doms.mr <- read.delim(seg.c$file.maxresolution, stringsAsFactors=F)
doms.ms <- read.delim(seg.c$file.maxscale, stringsAsFactors=F)

# Visualization coordinates
x.s <- 1:n - 0.5
x.e <- 1:n + 0.5
w2y <- wSize2yAxis(n, logscale=T)

layout(matrix(1:2, 2, 1), heights=c(3,1)/4)
par(mar=c(3, 4, 1, 2)) # default bottom, left, top, right = c(5, 4, 4, 2)

# Plot domainogram
domainogram(Yi, x.s, x.e, w2y)
plot(Mi, type='l')

# Visualize segmentation results
plotOptimalSegments(opts, x.s, x.e, w2y, col="black")
plot(Mi, type='l')

# Visualize multi-resolution domains
plotDomains(doms, x.s, x.e, w2y, col=rgb(0,0,0,0.5), border=rgb(0,0,0,0))
# Visualize max. resolution and max. scale domains
plotDomains(doms.mr, x.s, x.e, w2y, col=rgb(0,1,0,0.5), border=rgb(0,0,0,0), lwd=2, lty=1, add=T)
plotDomains(doms.ms, x.s, x.e, w2y, col=rgb(1,0,0,0.5), border=rgb(0,0,0,0), lwd=2, lty=1, add=T)
legend("topright", c("Max. resolution", "Max. scale", "Both"), fill=c("green", "red", "chocolate"), bty='n')
plot(Mi, type='l')

benja0x40/MRA.TA documentation built on March 13, 2023, 5:15 a.m.