# Dummying up some data.
set.seed(3423746)
npts <- 100
npairs <- 5000
nlibs <- 4
anchor1 <- sample(npts, npairs, replace=TRUE)
anchor2 <- sample(npts, npairs, replace=TRUE)
data <- InteractionSet(
list(counts=matrix(rpois(npairs*nlibs, runif(npairs, 10, 100)), nrow=npairs)),
GInteractions(anchor1=anchor1, anchor2=anchor2,
regions=GRanges("chrA", IRanges(1:npts, 1:npts)), mode="reverse"),
colData=DataFrame(totals=runif(nlibs, 1e6, 2e6)))
margins <- SummarizedExperiment(matrix(rpois(npts*nlibs, 100), nrow=npts),
colData=DataFrame(totals=data$totals), rowRanges=regions(data))
# Running normalizeCNV.
out <- normalizeCNV(data, margins)
head(out)
head(normalizeCNV(data, margins, prior.count=1))
head(normalizeCNV(data, margins, span=0.5))
# Store offsets as the 'offset' assay for use by, e.g., asDGEList.
assays(data)$offset <- out
data
# Occasionally locfit will complain; increase maxk to compensate.
data <- InteractionSet(matrix(rpois(npairs*nlibs, 20), nrow=npairs),
GInteractions(anchor1=anchor1, anchor2=anchor2,
regions=GRanges("chrA", IRanges(1:npts, 1:npts)), mode="reverse"),
colData=DataFrame(totals=runif(nlibs, 1e6, 2e6)))
tryCatch(head(normalizeCNV(data, margins, maxk=100)), error=function(e) e)
head(normalizeCNV(data, margins, maxk=1000))
# Matching margins.
matched <- matchMargins(data, margins)
head(matched)
anchor1.counts <- margins[matched$anchor1,]
anchor2.counts <- margins[matched$anchor2,]
Run the code above in your browser using DataLab