Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions R/compartments.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
#'
#' @param x A `HiCExperiment` object over a full genome
#' @param resolution Which resolution to use to compute eigen vectors
#' @param genome a BSgenome of DNAStringSet object associated with the Hi-C
#' contact matrix.
#' @param genome a `BSgenome`, `DNAStringSet`, `TxDb` or `RleList` object
#' associated with the Hi-C contact matrix.
#' @param chromosomes character or integer vector indicating which
#' @param neigens Numver of eigen vectors to extract
#' @param neigens Number of eigen vectors to extract
#' @param sort_eigens Can be FALSE or one of c('Spearman', 'Pearson')
#' @param BPPARAM BiocParallel parallelization settings
#' @return A `HiCExperiment` object with additional `eigens` metadata containing the
Expand Down Expand Up @@ -234,6 +234,7 @@ getCompartments <- function(
}
else if (is(genome, "RleList")) {
## -- Get average coverage per bin
cov <- genome
gr$phasing <- BiocGenerics::mean(cov[gr])
}
else {
Expand Down
6 changes: 3 additions & 3 deletions man/getCompartments.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions tests/testthat/test-comps-insulation-scalogram.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,36 @@ test_that("compartments works", {
)
})

test_that("compartments can be phased with an RleList track", {
yeast_bsgenome <- BSgenome.Scerevisiae.UCSC.sacCer3::BSgenome.Scerevisiae.UCSC.sacCer3
GenomeInfoDb::seqlevelsStyle(yeast_bsgenome) <- "NCBI"
smooth_bin <- 100L
smooth_span <- smooth_bin - 1L
full_contacts_yeast <- HiCExperiment::contacts_yeast(full = TRUE)
chr_ids <- as.character(GenomeInfoDb::seqnames(GenomeInfoDb::seqinfo(full_contacts_yeast)))
gc_content <- lapply(Biostrings::getSeq(yeast_bsgenome, chr_ids), function(chr_seq) {
gc_sliding <- as.numeric(
Biostrings::letterFrequencyInSlidingView(chr_seq, smooth_bin, "GC")
) / smooth_bin
left_pad <- floor(smooth_span / 2L)
right_pad <- ceiling(smooth_span / 2L)
gc_smoothed <- c(
rep(gc_sliding[1], left_pad),
gc_sliding,
rep(gc_sliding[length(gc_sliding)], right_pad)
)
S4Vectors::Rle(gc_smoothed)
})
cov_track <- IRanges::RleList(gc_content)
names(cov_track) <- chr_ids

expect_no_error(getCompartments(
full_contacts_yeast,
genome = cov_track,
chromosomes = "VI"
))
})

test_that("insulation works", {
hic <- HiCExperiment::contacts_yeast() |>
HiCExperiment::refocus('II:1-300000') |>
Expand Down
Loading