diff --git a/R/compartments.R b/R/compartments.R index 1a2c262..eb6eb5d 100644 --- a/R/compartments.R +++ b/R/compartments.R @@ -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 @@ -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 { diff --git a/man/getCompartments.Rd b/man/getCompartments.Rd index 614c375..ed5b82d 100644 --- a/man/getCompartments.Rd +++ b/man/getCompartments.Rd @@ -19,12 +19,12 @@ getCompartments( \item{resolution}{Which resolution to use to compute eigen vectors} -\item{genome}{a BSgenome of DNAStringSet object associated with the Hi-C -contact matrix.} +\item{genome}{a \code{BSgenome}, \code{DNAStringSet}, \code{TxDb} or \code{RleList} +object associated with the Hi-C contact matrix.} \item{chromosomes}{character or integer vector indicating which} -\item{neigens}{Numver of eigen vectors to extract} +\item{neigens}{Number of eigen vectors to extract} \item{sort_eigens}{Can be FALSE or one of c('Spearman', 'Pearson')} diff --git a/tests/testthat/test-comps-insulation-scalogram.R b/tests/testthat/test-comps-insulation-scalogram.R index 6e50bea..ba17cc3 100644 --- a/tests/testthat/test-comps-insulation-scalogram.R +++ b/tests/testthat/test-comps-insulation-scalogram.R @@ -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') |>