From 7356c0b03e671e0c0be9dd8ed4883a625f1bd119 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 18 Apr 2026 14:03:21 +0000 Subject: [PATCH 1/8] Initial plan From b74903270c92a459594c7a181e2ba0779af85727 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 18 Apr 2026 14:05:35 +0000 Subject: [PATCH 2/8] fix: support RleList genomic tracks for compartment phasing Agent-Logs-Url: https://github.com/js2264/HiContacts/sessions/b522298c-8b9e-4b0a-9cc0-70727bf49c6b Co-authored-by: js2264 <19528818+js2264@users.noreply.github.com> --- R/compartments.R | 5 +++-- man/getCompartments.Rd | 4 ++-- tests/testthat/test-comps-insulation-scalogram.R | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/R/compartments.R b/R/compartments.R index 1a2c262..01da757 100644 --- a/R/compartments.R +++ b/R/compartments.R @@ -8,8 +8,8 @@ #' #' @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 sort_eigens Can be FALSE or one of c('Spearman', 'Pearson') @@ -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..16345a4 100644 --- a/man/getCompartments.Rd +++ b/man/getCompartments.Rd @@ -19,8 +19,8 @@ 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} diff --git a/tests/testthat/test-comps-insulation-scalogram.R b/tests/testthat/test-comps-insulation-scalogram.R index 6e50bea..9771680 100644 --- a/tests/testthat/test-comps-insulation-scalogram.R +++ b/tests/testthat/test-comps-insulation-scalogram.R @@ -26,6 +26,21 @@ test_that("compartments works", { ) }) +test_that("compartments can be phased with an RleList track", { + full_contacts_yeast <- HiCExperiment::contacts_yeast(full = TRUE) + full_contacts_yeast_VI <- full_contacts_yeast["VI"] + VI_regions <- HiCExperiment::regions(full_contacts_yeast_VI) + cov_track <- IRanges::RleList(VI = IRanges::Rle( + seq_len(max(GenomicRanges::end(VI_regions))) + )) + + 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') |> From f173079f64741e0b70c2fdf5ed18c63c2e804e37 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 18 Apr 2026 14:06:11 +0000 Subject: [PATCH 3/8] docs: fix typo in getCompartments parameter docs Agent-Logs-Url: https://github.com/js2264/HiContacts/sessions/b522298c-8b9e-4b0a-9cc0-70727bf49c6b Co-authored-by: js2264 <19528818+js2264@users.noreply.github.com> --- R/compartments.R | 2 +- man/getCompartments.Rd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/compartments.R b/R/compartments.R index 01da757..eb6eb5d 100644 --- a/R/compartments.R +++ b/R/compartments.R @@ -11,7 +11,7 @@ #' @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 diff --git a/man/getCompartments.Rd b/man/getCompartments.Rd index 16345a4..ed5b82d 100644 --- a/man/getCompartments.Rd +++ b/man/getCompartments.Rd @@ -24,7 +24,7 @@ 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')} From cfe748249fb59dabb4c8a7475e0198f66fbde5ed Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 19 Apr 2026 01:23:13 +0000 Subject: [PATCH 4/8] test: phase compartments using smoothed GC coverage RleList Agent-Logs-Url: https://github.com/js2264/HiContacts/sessions/f02bcc18-320e-4ba4-9316-8b5381c7eedc Co-authored-by: js2264 <19528818+js2264@users.noreply.github.com> --- .../test-comps-insulation-scalogram.R | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/tests/testthat/test-comps-insulation-scalogram.R b/tests/testthat/test-comps-insulation-scalogram.R index 9771680..4fb3423 100644 --- a/tests/testthat/test-comps-insulation-scalogram.R +++ b/tests/testthat/test-comps-insulation-scalogram.R @@ -27,12 +27,27 @@ test_that("compartments works", { }) test_that("compartments can be phased with an RleList track", { + library(BSgenome.Scerevisiae.UCSC.sacCer3) + genome <- BSgenome.Scerevisiae.UCSC.sacCer3 + GenomeInfoDb::seqlevelsStyle(genome) <- "NCBI" full_contacts_yeast <- HiCExperiment::contacts_yeast(full = TRUE) - full_contacts_yeast_VI <- full_contacts_yeast["VI"] - VI_regions <- HiCExperiment::regions(full_contacts_yeast_VI) - cov_track <- IRanges::RleList(VI = IRanges::Rle( - seq_len(max(GenomicRanges::end(VI_regions))) - )) + chr_ids <- as.character(GenomeInfoDb::seqnames(GenomeInfoDb::seqinfo(full_contacts_yeast))) + gc_cov <- lapply(Biostrings::getSeq(genome, chr_ids), function(seq_chr) { + smooth_bin <- 100L + gc_sliding <- as.numeric( + Biostrings::letterFrequencyInSlidingView(seq_chr, smooth_bin, "GC") + ) / smooth_bin + left_pad <- floor((smooth_bin - 1L) / 2L) + right_pad <- ceiling((smooth_bin - 1L) / 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_cov) + names(cov_track) <- chr_ids expect_no_error(getCompartments( full_contacts_yeast, From 06a8417076133ea322c062749a461bf735c3ea78 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 19 Apr 2026 01:23:41 +0000 Subject: [PATCH 5/8] test: clean up GC smoothing constants in coverage-track test Agent-Logs-Url: https://github.com/js2264/HiContacts/sessions/f02bcc18-320e-4ba4-9316-8b5381c7eedc Co-authored-by: js2264 <19528818+js2264@users.noreply.github.com> --- tests/testthat/test-comps-insulation-scalogram.R | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/testthat/test-comps-insulation-scalogram.R b/tests/testthat/test-comps-insulation-scalogram.R index 4fb3423..0931274 100644 --- a/tests/testthat/test-comps-insulation-scalogram.R +++ b/tests/testthat/test-comps-insulation-scalogram.R @@ -30,15 +30,16 @@ test_that("compartments can be phased with an RleList track", { library(BSgenome.Scerevisiae.UCSC.sacCer3) genome <- BSgenome.Scerevisiae.UCSC.sacCer3 GenomeInfoDb::seqlevelsStyle(genome) <- "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_cov <- lapply(Biostrings::getSeq(genome, chr_ids), function(seq_chr) { - smooth_bin <- 100L gc_sliding <- as.numeric( Biostrings::letterFrequencyInSlidingView(seq_chr, smooth_bin, "GC") ) / smooth_bin - left_pad <- floor((smooth_bin - 1L) / 2L) - right_pad <- ceiling((smooth_bin - 1L) / 2L) + left_pad <- floor(smooth_span / 2L) + right_pad <- ceiling(smooth_span / 2L) gc_smoothed <- c( rep(gc_sliding[[1]], left_pad), gc_sliding, From 0baa78e2ab6856240287e7dcc52d1a6268b593c7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 19 Apr 2026 01:24:20 +0000 Subject: [PATCH 6/8] test: refine GC track test namespaces and indexing Agent-Logs-Url: https://github.com/js2264/HiContacts/sessions/f02bcc18-320e-4ba4-9316-8b5381c7eedc Co-authored-by: js2264 <19528818+js2264@users.noreply.github.com> --- tests/testthat/test-comps-insulation-scalogram.R | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-comps-insulation-scalogram.R b/tests/testthat/test-comps-insulation-scalogram.R index 0931274..ee54e87 100644 --- a/tests/testthat/test-comps-insulation-scalogram.R +++ b/tests/testthat/test-comps-insulation-scalogram.R @@ -27,8 +27,7 @@ test_that("compartments works", { }) test_that("compartments can be phased with an RleList track", { - library(BSgenome.Scerevisiae.UCSC.sacCer3) - genome <- BSgenome.Scerevisiae.UCSC.sacCer3 + genome <- BSgenome.Scerevisiae.UCSC.sacCer3::BSgenome.Scerevisiae.UCSC.sacCer3 GenomeInfoDb::seqlevelsStyle(genome) <- "NCBI" smooth_bin <- 100L smooth_span <- smooth_bin - 1L @@ -41,9 +40,9 @@ test_that("compartments can be phased with an RleList track", { left_pad <- floor(smooth_span / 2L) right_pad <- ceiling(smooth_span / 2L) gc_smoothed <- c( - rep(gc_sliding[[1]], left_pad), + rep(gc_sliding[1], left_pad), gc_sliding, - rep(gc_sliding[[length(gc_sliding)]], right_pad) + rep(gc_sliding[length(gc_sliding)], right_pad) ) S4Vectors::Rle(gc_smoothed) }) From b0a1b1fc5677d8d6b3dfd9690301807dcfe8f8e6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 19 Apr 2026 01:24:48 +0000 Subject: [PATCH 7/8] test: clarify variable names in GC track phasing test Agent-Logs-Url: https://github.com/js2264/HiContacts/sessions/f02bcc18-320e-4ba4-9316-8b5381c7eedc Co-authored-by: js2264 <19528818+js2264@users.noreply.github.com> --- tests/testthat/test-comps-insulation-scalogram.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-comps-insulation-scalogram.R b/tests/testthat/test-comps-insulation-scalogram.R index ee54e87..3b0e8b4 100644 --- a/tests/testthat/test-comps-insulation-scalogram.R +++ b/tests/testthat/test-comps-insulation-scalogram.R @@ -27,13 +27,13 @@ test_that("compartments works", { }) test_that("compartments can be phased with an RleList track", { - genome <- BSgenome.Scerevisiae.UCSC.sacCer3::BSgenome.Scerevisiae.UCSC.sacCer3 - GenomeInfoDb::seqlevelsStyle(genome) <- "NCBI" + yeast_genome <- BSgenome.Scerevisiae.UCSC.sacCer3::BSgenome.Scerevisiae.UCSC.sacCer3 + GenomeInfoDb::seqlevelsStyle(yeast_genome) <- "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_cov <- lapply(Biostrings::getSeq(genome, chr_ids), function(seq_chr) { + gc_content <- lapply(Biostrings::getSeq(yeast_genome, chr_ids), function(seq_chr) { gc_sliding <- as.numeric( Biostrings::letterFrequencyInSlidingView(seq_chr, smooth_bin, "GC") ) / smooth_bin @@ -46,7 +46,7 @@ test_that("compartments can be phased with an RleList track", { ) S4Vectors::Rle(gc_smoothed) }) - cov_track <- IRanges::RleList(gc_cov) + cov_track <- IRanges::RleList(gc_content) names(cov_track) <- chr_ids expect_no_error(getCompartments( From bba7156d9205f3716d2e2e0f19d6297b88267bbc Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 19 Apr 2026 01:25:15 +0000 Subject: [PATCH 8/8] test: align naming in GC track test variables Agent-Logs-Url: https://github.com/js2264/HiContacts/sessions/f02bcc18-320e-4ba4-9316-8b5381c7eedc Co-authored-by: js2264 <19528818+js2264@users.noreply.github.com> --- tests/testthat/test-comps-insulation-scalogram.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-comps-insulation-scalogram.R b/tests/testthat/test-comps-insulation-scalogram.R index 3b0e8b4..ba17cc3 100644 --- a/tests/testthat/test-comps-insulation-scalogram.R +++ b/tests/testthat/test-comps-insulation-scalogram.R @@ -27,15 +27,15 @@ test_that("compartments works", { }) test_that("compartments can be phased with an RleList track", { - yeast_genome <- BSgenome.Scerevisiae.UCSC.sacCer3::BSgenome.Scerevisiae.UCSC.sacCer3 - GenomeInfoDb::seqlevelsStyle(yeast_genome) <- "NCBI" + 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_genome, chr_ids), function(seq_chr) { + gc_content <- lapply(Biostrings::getSeq(yeast_bsgenome, chr_ids), function(chr_seq) { gc_sliding <- as.numeric( - Biostrings::letterFrequencyInSlidingView(seq_chr, smooth_bin, "GC") + Biostrings::letterFrequencyInSlidingView(chr_seq, smooth_bin, "GC") ) / smooth_bin left_pad <- floor(smooth_span / 2L) right_pad <- ceiling(smooth_span / 2L)