## Use the algo to compute the solution list.
data("H3K4me3_XJ_immune_chunk1", envir=environment())
by.sample <-
split(H3K4me3_XJ_immune_chunk1, H3K4me3_XJ_immune_chunk1$sample.id)
n.data.vec <- sapply(by.sample, nrow)
one <- by.sample[[1]]
count.vec <- one$coverage
weight.vec <- with(one, chromEnd-chromStart)
max.segments <- 19L
fit <- PeakSegPDPA(count.vec, weight.vec, max.segments)
## Recover the solution in terms of (M,C) variables.
n.segs <- 11L
change.vec <- fit$ends.mat[n.segs, 2:n.segs]
change.sign.vec <- rep(c(1, -1), length(change.vec)/2)
end.vec <- c(change.vec, fit$n.data)
start.vec <- c(1, change.vec+1)
length.vec <- end.vec-start.vec+1
mean.vec <- fit$mean.mat[n.segs, 1:n.segs]
M.vec <- rep(mean.vec, length.vec)
C.vec <- rep(0, fit$n.data-1)
C.vec[change.vec] <- change.sign.vec
diff.vec <- diff(M.vec)
data.frame(
change=c(C.vec, NA),
mean=M.vec,
equality.constraint.active=c(sign(diff.vec) != C.vec, NA))
stopifnot(cumsum(sign(C.vec)) %in% c(0, 1))
## Compute Poisson loss of M.vec and compare to the value reported
## in the fit solution list.
rbind(
PoissonLoss(count.vec, M.vec, weight.vec),
fit$cost.mat[n.segs, fit$n.data])
## Plot the number of intervals stored by the algorithm.
PDPA.intervals <- data.frame(
segments=as.numeric(row(fit$intervals.mat)),
data=as.numeric(col(fit$intervals.mat)),
intervals=as.numeric(fit$intervals.mat))
some.intervals <- subset(PDPA.intervals, segments
Run the code above in your browser using DataLab