plotAB: Plots A/B compartment estimates on a per chromosome basis

Description Usage Arguments Value Examples

View source: R/plotAB.R

Description

Plot A/B compartments bins

Usage

1
2
plotAB(x, main = "", ylim = c(-1, 1), unitarize = FALSE,
  reverse = FALSE, top.col = "deeppink4", bot.col = "grey50")

Arguments

x

The matrix obejct returned from getCompartments

main

Title for the plot

ylim

Y-axis limits (default is -1 to 1)

unitarize

Should the data be unitarized? (not explicitly necessary for arrays)

reverse

Reverse the sign of the PC values?

top.col

Top (pos. PC values) chromatin color to be plotted

bot.col

Bottom (neg. PC values) chromatin color to be plotted

Value

invisibly, the compartment estimates from the plot

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
library(GenomicRanges)
library(Homo.sapiens)

#Generate random genomic intervals of 1-1000 bp on chr1-22
#Modified from https://www.biostars.org/p/225520/
random_genomic_int <- data.frame(chr = rep("chr14", 100))
random_genomic_int$start <- apply(random_genomic_int, 1, function(x) { round(runif(1, 0, seqlengths(Homo.sapiens)[x][[1]]), 0) })
random_genomic_int$end <- random_genomic_int$start + runif(1, 1, 1000)
random_genomic_int$strand <- "*"

#Generate random counts
counts <- rnbinom(1000, 1.2, 0.4)

#Build random counts for 10 samples
count.mat <- matrix(sample(counts, nrow(random_genomic_int) * 10, replace = FALSE), ncol = 10)
colnames(count.mat) <- paste0("sample_", seq(1:10))

#Bin counts
bin.counts <- getBinMatrix(count.mat, makeGRangesFromDataFrame(random_genomic_int), chr = "chr14", genome = "hg19")

#Calculate correlations
bin.cor.counts <- getCorMatrix(bin.counts)

#Get A/B signal
absignal <- getABSignal(bin.cor.counts)

#Plot the A/B signal
par(mar=c(1,1,1,1))
par(mfrow=c(1,1))
plotAB(absignal$pc, ylim = c(-0.2, 0.2), unitarize = TRUE)

## Not run: 
#If plotting individual A/B signals using output from getCompartments
#Note: this function currently only supports plotting individual chromosomes from single samples
bin.chr1.ab <- getCompartments(data, "array", chrs = "chr1", genome = "hg19")

#For 7 samples
#Adjust ylim as necessary
par(mar=c(1,1,1,1))
par(mfrow=c(7,1))
plotAB(bin.chr1.ab[,1], ylim = c(-0.2, 0.2), unitarize = TRUE)
plotAB(bin.chr1.ab[,2], ylim = c(-0.2, 0.2), unitarize = TRUE, top.col = "goldenrod")
plotAB(bin.chr1.ab[,3], ylim = c(-0.2, 0.2), unitarize = TRUE, top.col = "darkblue")
plotAB(bin.chr1.ab[,4], ylim = c(-0.2, 0.2), unitarize = TRUE, top.col = "red")
plotAB(bin.chr1.ab[,5], ylim = c(-0.2, 0.2), unitarize = TRUE, top.col = "black")
plotAB(bin.chr1.ab[,6], ylim = c(-0.2, 0.2), unitarize = TRUE, top.col = "cyan")
plotAB(bin.chr1.ab[,7], ylim = c(-0.2, 0.2), unitarize = TRUE, top.col = "seagreen")

## End(Not run)

compartmap documentation built on Nov. 8, 2020, 5:34 p.m.