Add spikein to contact matrix.

FreeSpikeIn(
  contactBackground,
  contactSpikeInSignal,
  kernelSmooth = TRUE,
  bandwidth = 500000L
)

Arguments

contactBackground

The contact matrix. It can be

  • matrixA matrix with columns (x, y, counts).

  • data.frameA data.frame with columns (chr1, x, y, chr2, counts).

  • listA list of matrix, where the matrix has columns (x, y, counts).

where x stands for the first chromosome location, y stands for the second chromosome location and counts is the interaction counts.

contactSpikeInSignal

The spikein signal. It should has the exact same format as contactBackground

kernelSmooth

TRUE or FALSE. Whether to perform kernel smoothing.

bandwidth

The bandwidth used in the kernel smooth.

Value

A same format as contactBackground

Details

Spikein will add signals to the background. Also use Gaussian kernel smooth with bandwidth.

Examples

library(FreeHiCLite) N <- 2000 Ns <- 200 maxBinX <- maxBinY <- 2000000L maxCounts <- 10 binX <- sample(1:maxBinX, N, replace=TRUE) binY <- sample(1:maxBinY, N, replace=TRUE) counts <- sample(1:10, N, replace=TRUE) kernelSmooth = TRUE bandwidth = 50000L ## Matrix version ## matrix layout as x, y, counts contacts <- matrix(0, N, 3) contacts[,1] <- binX contacts[,2] <- binY contacts[,3] <- counts spikeIn <- contacts[sample(1:N, Ns),] hist(spikeIn[,3])
spikeIn[,3] <- spikeIn[,3] * sample(seq(0, 10, 0.5), Ns, replace=TRUE) hist(spikeIn[,3])
res <- FreeSpikeIn(contacts, spikeIn, kernelSmooth = kernelSmooth, bandwidth = bandwidth) head(res)
#> x y counts #> [1,] 463789 1895 8 #> [2,] 524004 3068 5 #> [3,] 414539 3484 11 #> [4,] 1322176 3904 7 #> [5,] 694618 5505 6 #> [6,] 985692 6096 14
## List version N2 = 3000 Ns2 = 300 binX2 <- sample(1:maxBinX, N2, replace=TRUE) binY2 <- sample(1:maxBinY, N2, replace=TRUE) counts2 <- sample(1:10, N2, replace=TRUE) contacts2 <- matrix(0, N2, 3) contacts2[,1] <- binX2 contacts2[,2] <- binY2 contacts2[,3] <- counts2 spikeIn2 <- contacts2[sample(1:N2, Ns2),] spikeIn2[,3] <- spikeIn2[,3] * sample(seq(0, 10, 0.5), Ns2, replace=TRUE) contactsBackgroup <- list('1_1' = contacts, '2_2' = contacts2) spikeInlist <- list('1_1' = spikeIn, '2_2' = spikeIn2) res <- FreeSpikeIn(contactsBackgroup, spikeInlist, kernelSmooth = kernelSmooth, bandwidth = bandwidth) str(res)
#> List of 2 #> $ 1_1: int [1:2000, 1:3] 463789 524004 414539 1322176 694618 985692 1762793 547605 1975355 1684675 ... #> ..- attr(*, "dimnames")=List of 2 #> .. ..$ : NULL #> .. ..$ : chr [1:3] "x" "y" "counts" #> $ 2_2: int [1:3000, 1:3] 1254932 394790 1227661 1510126 1185085 1984565 1779963 118297 10647 1443158 ... #> ..- attr(*, "dimnames")=List of 2 #> .. ..$ : NULL #> .. ..$ : chr [1:3] "x" "y" "counts"
## Dataframe version chr1 <- c(rep('1', N), rep('2', N2)) chr2 <- c(rep('1', N), rep('2', N2)) schr1 <- c(rep('1', Ns), rep('2', Ns2)) schr2 <- c(rep('1', Ns), rep('2', Ns2)) contactsAll <- rbind(contacts, contacts2) spikeInAll <- rbind(spikeIn, spikeIn2) contactsDf <- data.frame(chr1 = chr1, x = contactsAll[,1], chr2 = chr2, y = contactsAll[,2], counts = contactsAll[,3]) spikeInDf <- data.frame(chr1 = schr1, x = spikeInAll[,1], chr2 = schr2, y = spikeInAll[,2], counts = spikeInAll[,3]) res <- FreeSpikeIn(contactsDf, spikeInDf, kernelSmooth = kernelSmooth, bandwidth = bandwidth) head(res)
#> chr1 x chr2 y counts #> 1 1 463789 1 1895 8 #> 2 1 524004 1 3068 5 #> 3 1 414539 1 3484 11 #> 4 1 1322176 1 3904 7 #> 5 1 694618 1 5505 23 #> 6 1 985692 1 6096 14