diff --git a/NAMESPACE b/NAMESPACE index c41b675..a1432df 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -11,14 +11,14 @@ export(adjustEnrichment) export(aggHicMatrices) export(aggMetadata) export(as_ginteractions) -export(assignToBins) +export(binPairs) export(binRanges) export(calcLoopEnrichment) export(changePixelRes) -export(clusters) export(defaultBuffer) export(end1) export(end2) +export(getPairClusters) export(hdf5BlockApply) export(makeGInteractionsFromDataFrame) export(makeRandomGInteractions) @@ -52,12 +52,12 @@ export(selectTopRight) export(selectionMethod) export(seqnames1) export(seqnames2) -export(sets) export(shiftRanges) export(snapToBins) export(sources) export(start1) export(start2) +export(subsetBySource) exportClasses(DelegatingGInteractions) exportClasses(InteractionArray) exportClasses(InteractionJaggedArray) @@ -79,12 +79,11 @@ exportMethods(aggHicMatrices) exportMethods(aggMetadata) exportMethods(as.list) exportMethods(as_ginteractions) -exportMethods(assignToBins) +exportMethods(binPairs) exportMethods(binRanges) exportMethods(calcLoopEnrichment) exportMethods(cbind) exportMethods(changePixelRes) -exportMethods(clusters) exportMethods(colData) exportMethods(countOverlaps) exportMethods(counts) @@ -92,6 +91,7 @@ exportMethods(dim) exportMethods(end1) exportMethods(end2) exportMethods(findOverlaps) +exportMethods(getPairClusters) exportMethods(hdf5BlockApply) exportMethods(interactions) exportMethods(length) @@ -131,7 +131,6 @@ exportMethods(selectTopRight) exportMethods(selectionMethod) exportMethods(seqnames1) exportMethods(seqnames2) -exportMethods(sets) exportMethods(shiftRanges) exportMethods(show) exportMethods(snapToBins) @@ -139,6 +138,7 @@ exportMethods(sources) exportMethods(start1) exportMethods(start2) exportMethods(subsetByOverlaps) +exportMethods(subsetBySource) import(data.table, except = c(between, shift, first, second, indices)) import(methods) diff --git a/R/AllGenerics.R b/R/AllGenerics.R index 0009ff4..c7b3367 100644 --- a/R/AllGenerics.R +++ b/R/AllGenerics.R @@ -16,15 +16,15 @@ setGeneric("makeGInteractionsFromDataFrame", ...) standardGeneric("makeGInteractionsFromDataFrame")) -#' @rdname assignToBins +#' @rdname binPairs #' @export -setGeneric("assignToBins", +setGeneric("binPairs", function(x, binSize, pos1 = 'center', pos2 = 'center', ...) - standardGeneric("assignToBins")) + standardGeneric("binPairs")) #' @rdname binRanges #' @export @@ -63,22 +63,22 @@ setGeneric("mergePairs", setGeneric("selectionMethod", function(x, ...) standardGeneric("selectionMethod")) -#' @rdname clusters +#' @rdname getPairClusters #' @export -setGeneric("clusters", function(x, ...) - standardGeneric("clusters")) +setGeneric("getPairClusters", function(x, ...) + standardGeneric("getPairClusters")) #' @rdname sources #' @export setGeneric("sources", function(x) standardGeneric("sources")) -#' @rdname sets +#' @rdname subsetBySource #' @export -setGeneric("sets", function(x, +setGeneric("subsetBySource", function(x, include, exclude) - standardGeneric("sets")) + standardGeneric("subsetBySource")) #' @rdname aggMetadata #' @export diff --git a/R/methods-CountMatrix.R b/R/methods-CountMatrix.R index 39745a7..f63fbae 100644 --- a/R/methods-CountMatrix.R +++ b/R/methods-CountMatrix.R @@ -35,7 +35,7 @@ #' setNames("WT") |> #' read.table(header=TRUE) |> #' as_ginteractions(keep.extra.columns=FALSE) |> -#' assignToBins(binSize=100e3) +#' binPairs(binSize=100e3) #' #' ## Removes the "chr" prefix for compatibility #' ## with the preprocessed hic files diff --git a/R/methods-InteractionJaggedArray.R b/R/methods-InteractionJaggedArray.R index 1196d57..df0cb94 100644 --- a/R/methods-InteractionJaggedArray.R +++ b/R/methods-InteractionJaggedArray.R @@ -303,7 +303,7 @@ setMethod("[", "InteractionJaggedArray", function(x, i, j) { #' iarr <- pullHicMatrices(gi, hicFiles, 100e03, half="both") #' #' ## Shift first two ranges out of range -#' gi2 <- c(assignToBins(gi[1:2], binSize=100e3, pos1=-200e3), gi[3:4]) +#' gi2 <- c(binPairs(gi[1:2], binSize=100e3, pos1=-200e3), gi[3:4]) #' #' ## Find overlaps #' findOverlaps(iarr, gi2) diff --git a/R/methods-MatrixSelection.R b/R/methods-MatrixSelection.R index 1203be2..d500d9d 100644 --- a/R/methods-MatrixSelection.R +++ b/R/methods-MatrixSelection.R @@ -38,7 +38,7 @@ abort(c(glue("All interactions in `x` must be \\ the same width."), "i"="Check this with `width(x)`.", - "i"="Set binSize with `assignToBins(x, binSize)`.")) + "i"="Set binSize with `binPairs(x, binSize)`.")) } ## How does moving down or right change dist to diag? p <- pairdist(x) diff --git a/R/methods-MergedGInteractions.R b/R/methods-MergedGInteractions.R index 9932117..5362a3f 100644 --- a/R/methods-MergedGInteractions.R +++ b/R/methods-MergedGInteractions.R @@ -162,7 +162,7 @@ setMethod("aggMetadata", signature(x = "MergedGInteractions", #' Access the names or source files of #' a `MergedGInteractions` object. #' -#' @inheritParams sets +#' @inheritParams subsetBySource #' @return A character vector of names or source #' files of a `MergedGInteractions` object. #' @examples @@ -198,7 +198,7 @@ setMethod("sources", "MergedGInteractions", function(x) as.character(unique(x@allPairs$src))) #' Create logial matrix of sources for each merged pair -#' @inheritParams sets +#' @inheritParams subsetBySource #' @importFrom data.table data.table as.data.table #' @importFrom stats setNames #' @return A logical matrix with columns for each source @@ -241,7 +241,7 @@ setMethod("sources", "MergedGInteractions", } #' Check source names -#' @inheritParams sets +#' @inheritParams subsetBySource #' @param vec Input character vector (i.e. include, exclude or both) #' @importFrom glue glue glue_collapse double_quote #' @importFrom rlang abort @@ -264,11 +264,11 @@ setMethod("sources", "MergedGInteractions", } #' Find subset pairs using include and exclude sources -#' @inheritParams sets +#' @inheritParams subsetBySource #' @importFrom data.table data.table #' @return A `MergedGInteractions` object of subset pairs. #' @noRd -.setsIncludeExclude <- function(x, include, exclude) { +.subsetBySourceIncludeExclude <- function(x, include, exclude) { ## Check source names .checkSourceNames(x, vec = c(include, exclude)) @@ -286,11 +286,11 @@ setMethod("sources", "MergedGInteractions", } #' Find subset pairs using include sources -#' @inheritParams sets +#' @inheritParams subsetBySource #' @importFrom data.table data.table #' @return A `MergedGInteractions` object of subset pairs. #' @noRd -.setsInclude <- function(x, include) { +.subsetBySourceInclude <- function(x, include) { ## Check source names .checkSourceNames(x, vec = include) @@ -306,11 +306,11 @@ setMethod("sources", "MergedGInteractions", } #' Find subset pairs using exclude sources -#' @inheritParams sets +#' @inheritParams subsetBySource #' @importFrom data.table data.table #' @return A `MergedGInteractions` object of subset pairs. #' @noRd -.setsExclude <- function(x, exclude) { +.subsetBySourceExclude <- function(x, exclude) { ## Check source names .checkSourceNames(x, vec = exclude) @@ -331,7 +331,7 @@ setMethod("sources", "MergedGInteractions", #' @importFrom utils combn #' @return A `MergedGInteractions` object of de novo pairs. #' @noRd -.sets <- function(x) { +.subsetBySource <- function(x) { ## Calculate the src matrix srcMat <- .makeSrcMatrix(x) @@ -374,9 +374,9 @@ setMethod("sources", "MergedGInteractions", }) |> unlist() names(idxList) <- srcNames - ## Index the sets - sets <- lapply(idxList, \(i) x[i]) - return(sets) + ## Index the subsetBySource + subsetBySource <- lapply(idxList, \(i) x[i]) + return(subsetBySource) } #' Get each set from a MergedGInteractions object @@ -389,8 +389,8 @@ setMethod("sources", "MergedGInteractions", #' merged pair is not returned. #' #' Optional `include` and `exclude` parameters modulate -#' the behavior of `sets` to return different -#' subsets of originating pairs. For example, `include` requires +#' the behavior of `subsetBySource` to return different +#' subsubsetBySource of originating pairs. For example, `include` requires #' that the returned pairs be present in specific sources, #' while `exclude` requires that returned pairs be absent #' from specific sources. Sources not listed in either @@ -435,47 +435,47 @@ setMethod("sources", "MergedGInteractions", #' ## Merge pairs #' x <- mergePairs(x = giList, radius = 20) #' -#' sets(x) +#' subsetBySource(x) #' -#' @rdname sets +#' @rdname subsetBySource #' @export -setMethod("sets", +setMethod("subsetBySource", signature(x = "MergedGInteractions", include = "missing", exclude = "missing"), - definition = .sets) + definition = .subsetBySource) -#' @rdname sets +#' @rdname subsetBySource #' @export -setMethod("sets", +setMethod("subsetBySource", signature(x = "MergedGInteractions", include = "character_OR_missing", exclude = "missing"), - definition = .setsInclude) + definition = .subsetBySourceInclude) -#' @rdname sets +#' @rdname subsetBySource #' @export -setMethod("sets", +setMethod("subsetBySource", signature(x = "MergedGInteractions", include = "missing", exclude = "character_OR_missing"), - definition = .setsExclude) + definition = .subsetBySourceExclude) -#' @rdname sets +#' @rdname subsetBySource #' @export -setMethod("sets", +setMethod("subsetBySource", signature(x = "MergedGInteractions", include = "character_OR_missing", exclude = "character_OR_missing"), - definition = .setsIncludeExclude) + definition = .subsetBySourceIncludeExclude) -#' Internal accessor function for clusters -#' @inheritParams clusters +#' Internal accessor function for getPairClusters +#' @inheritParams getPairClusters #' @importFrom data.table data.table #' @noRd -.clusters <- function(x) { +.getPairClusters <- function(x) { ## Suppress NSE notes in R CMD check i.id <- NULL @@ -533,16 +533,16 @@ setMethod("sets", #' radius = 10e03, #' column = "APScoreAvg") #' -#' ## Access pair clusters -#' clusters(x[1:3]) -#' clusters(x[3:1]) -#' clusters(x[c(3, 1, 2)]) -#' clusters(x) |> length() +#' ## Access pair getPairClusters +#' getPairClusters(x[1:3]) +#' getPairClusters(x[3:1]) +#' getPairClusters(x[c(3, 1, 2)]) +#' getPairClusters(x) |> length() #' -#' @rdname clusters +#' @rdname getPairClusters #' @export -setMethod("clusters", signature(x = "MergedGInteractions"), - definition = .clusters) +setMethod("getPairClusters", signature(x = "MergedGInteractions"), + definition = .getPairClusters) #' Get selectionMethod from MergedGInteractions object #' diff --git a/R/methods-adjustEnrichment.R b/R/methods-adjustEnrichment.R index 767c074..dc44016 100644 --- a/R/methods-adjustEnrichment.R +++ b/R/methods-adjustEnrichment.R @@ -122,7 +122,7 @@ #' #' ## Calculate loop enrichment #' enrich <- calcLoopEnrichment( -#' x=assignToBins(loops, 100e03), +#' x=binPairs(loops, 100e03), #' files=hicFiles #' ) #' diff --git a/R/methods-aggHicMatrices.R b/R/methods-aggHicMatrices.R index 701927d..0094fec 100644 --- a/R/methods-aggHicMatrices.R +++ b/R/methods-aggHicMatrices.R @@ -229,7 +229,7 @@ #' #' ## Expand pixel ranges with a 5 pixel buffer on either side #' loops <- -#' assignToBins(loops, binSize=100e3) |> +#' binPairs(loops, binSize=100e3) |> #' pixelsToMatrices(buffer=5) #' #' ## Extract 10, 11x11 count matrices from 2 hic files diff --git a/R/methods-assignToBins.R b/R/methods-assignToBins.R index 56dbd6b..6fb6177 100644 --- a/R/methods-assignToBins.R +++ b/R/methods-assignToBins.R @@ -1,5 +1,5 @@ -#' Internal assignToBins function -#' @inheritParams assignToBins +#' Internal binPairs function +#' @inheritParams binPairs #' @importFrom data.table data.table #' @importFrom S4Vectors DataFrame mcols #' @importFrom InteractionSet anchors @@ -7,7 +7,7 @@ #' @return Input object that has been binned. #' #' @noRd -.assignToBins <- function(x, binSize, pos1, pos2) { +.binPairs <- function(x, binSize, pos1, pos2) { ## Convert x to a GInteractions if (is(x, 'data.frame') | is(x, 'DFrame')) { @@ -73,21 +73,21 @@ #' chr2 = "chr1", y1 = 30000, y2 = 40000) #' #' ## Assign each range to 20-kb bins from the start positions -#' assignToBins(x = df1, +#' binPairs(x = df1, #' binSize = 20000, #' pos1 = 'start', #' pos2 = 'start') #' -#' @rdname assignToBins +#' @rdname binPairs #' @export -setMethod("assignToBins", +setMethod("binPairs", signature(x = 'DF_OR_df_OR_dt', binSize = 'numeric', pos1 = 'character_OR_numeric_OR_missing', pos2 = 'character_OR_numeric_OR_missing'), - definition = .assignToBins) + definition = .binPairs) -#' @rdname assignToBins +#' @rdname binPairs #' @examples #' ## Construct GInteractions #' library(InteractionSet) @@ -97,14 +97,14 @@ setMethod("assignToBins", #' as_ginteractions() #' #' ## Assign each range to 20-kb bins from the start positions -#' assignToBins(x = gi1, +#' binPairs(x = gi1, #' binSize = 20000, #' pos1 = 'start', #' pos2 = 'start') #' @export -setMethod("assignToBins", +setMethod("binPairs", signature(x = 'GInteractions', binSize = 'numeric', pos1 = 'character_OR_numeric_OR_missing', pos2 = 'character_OR_numeric_OR_missing'), - definition = .assignToBins) + definition = .binPairs) diff --git a/R/methods-calcLoopEnrichment.R b/R/methods-calcLoopEnrichment.R index 24ce597..72f9019 100644 --- a/R/methods-calcLoopEnrichment.R +++ b/R/methods-calcLoopEnrichment.R @@ -138,7 +138,7 @@ abort(c(glue("All interactions in `x` must be \\ the same width."), "i"="Check this with `width(x)`.", - "i"="Set binSize with `assignToBins(x, binSize)`.")) + "i"="Set binSize with `binPairs(x, binSize)`.")) } ## Check & show selection @@ -266,7 +266,7 @@ #' GenomeInfoDb::seqlevelsStyle(loops) <- 'ENSEMBL' #' #' ## Expand binSize of loops -#' loops <- assignToBins(x=loops, binSize=100e3) +#' loops <- binPairs(x=loops, binSize=100e3) #' #' ## Calculate loop enrichment #' calcLoopEnrichment(x=loops[1:10], @@ -296,7 +296,7 @@ setMethod("calcLoopEnrichment", #' #' @examples #' ## Extract count matrices first -#' mats <- assignToBins(loops[1:10],100e3) |> +#' mats <- binPairs(loops[1:10],100e3) |> #' pixelsToMatrices(buffer=10) |> #' pullHicMatrices( #' files=hicFiles, diff --git a/R/methods-changePixelRes.R b/R/methods-changePixelRes.R index 3734c99..1e6d389 100644 --- a/R/methods-changePixelRes.R +++ b/R/methods-changePixelRes.R @@ -113,7 +113,7 @@ #' GenomeInfoDb::seqlevelsStyle(loops) <- 'ENSEMBL' #' #' ## Rebin loops to 2.5e6 resolution -#' loops <- assignToBins(x=loops, binSize=2.5e06) +#' loops <- binPairs(x=loops, binSize=2.5e06) #' #' ## Pull 5x5 matrices #' iarr <- pullHicMatrices(x=loops[1:5], @@ -155,7 +155,7 @@ setMethod("selectPixel", ## Execute steps x |> - assignToBins(binSize=from) |> + binPairs(binSize=from) |> pullHicMatrices(binSize=to, files=files, norm=norm, ...) |> selectPixel(aggFUN, selectFUN, nBlocks, verbose) } @@ -237,7 +237,7 @@ setMethod("selectPixel", #' GenomeInfoDb::seqlevelsStyle(loops) <- 'ENSEMBL' #' #' ## Rebin loops to 2.5e6 resolution -#' loops <- assignToBins(x=loops, binSize=2.5e06) +#' loops <- binPairs(x=loops, binSize=2.5e06) #' #' ## Change pixel resolution from 2.5e6 to 500e3 #' changePixelRes(x=loops[1:5], diff --git a/R/methods-pileupPixels.R b/R/methods-pileupPixels.R index 086b2af..09776d5 100644 --- a/R/methods-pileupPixels.R +++ b/R/methods-pileupPixels.R @@ -91,7 +91,7 @@ #' setNames("WT") |> #' read.table(header=TRUE, nrows=1000) |> #' as_ginteractions(keep.extra.columns=FALSE) |> -#' assignToBins(binSize=5e3) +#' binPairs(binSize=5e3) #' #' ## Removes the "chr" prefix for compatibility #' ## with the preprocessed hic files diff --git a/R/methods-pullHic.R b/R/methods-pullHic.R index 4013577..50a61b6 100644 --- a/R/methods-pullHic.R +++ b/R/methods-pullHic.R @@ -43,7 +43,7 @@ x <- snapToBins(x, binSize) msg <- c("Pairs are not binned to `binSize`.", 'i' = glue("Snapping to binSize={binSize}, "), - 'i' = glue("Use `assignToBins()` or `snapToBins()` ", + 'i' = glue("Use `binPairs()` or `snapToBins()` ", "for more binning options.")) inform(msg) } @@ -873,7 +873,7 @@ #' setNames("WT") |> #' read.table(header=TRUE) |> #' as_ginteractions(keep.extra.columns=FALSE) |> -#' assignToBins(binSize=100e3) +#' binPairs(binSize=100e3) #' #' ## Removes the "chr" prefix for compatibility #' ## with the preprocessed hic files @@ -1097,7 +1097,7 @@ setMethod("pullHicMatrices", abort(c("`x` are not binned to `binSize`.", 'i' = glue("All ranges in `x` must be equal \\ widths for `pullHicPixels()`."), - 'i' = glue("Use `assignToBins()` to bin or use \\ + 'i' = glue("Use `binPairs()` to bin or use \\ `pullHicMatrices()` instead."))) } @@ -1184,7 +1184,7 @@ setMethod("pullHicMatrices", #' setNames("WT") |> #' read.table(header=TRUE) |> #' as_ginteractions(keep.extra.columns=FALSE) |> -#' assignToBins(binSize=100e3) +#' binPairs(binSize=100e3) #' #' ## Removes the "chr" prefix for compatibility #' ## with the preprocessed hic files diff --git a/R/utils.R b/R/utils.R index db15a49..7476814 100644 --- a/R/utils.R +++ b/R/utils.R @@ -227,7 +227,7 @@ widths <- unique(width(regions(x))) - 1 if (length(widths) != 1L) { abort(c("All ranges in `x` must be equal widths.", - "i"="Use `assignToBins()` to bin into equal widths.")) + "i"="Use `binPairs()` to bin into equal widths.")) } return(widths) } diff --git a/_pkgdown.yml b/_pkgdown.yml index 7ec7cda..d000a63 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -18,7 +18,7 @@ reference: - as_ginteractions - shiftRanges - binRanges - - assignToBins + - binPairs - snapToBins - seqnames1 - makeRandomGRanges diff --git a/man/CountMatrix-class.Rd b/man/CountMatrix-class.Rd index f5638ef..fde6871 100644 --- a/man/CountMatrix-class.Rd +++ b/man/CountMatrix-class.Rd @@ -51,7 +51,7 @@ pixels <- setNames("WT") |> read.table(header=TRUE) |> as_ginteractions(keep.extra.columns=FALSE) |> - assignToBins(binSize=100e3) + binPairs(binSize=100e3) ## Removes the "chr" prefix for compatibility ## with the preprocessed hic files diff --git a/man/InteractionJaggedArray-overlaps.Rd b/man/InteractionJaggedArray-overlaps.Rd index 77c404e..26a0dee 100644 --- a/man/InteractionJaggedArray-overlaps.Rd +++ b/man/InteractionJaggedArray-overlaps.Rd @@ -212,7 +212,7 @@ gi <- read.table(text=" iarr <- pullHicMatrices(gi, hicFiles, 100e03, half="both") ## Shift first two ranges out of range -gi2 <- c(assignToBins(gi[1:2], binSize=100e3, pos1=-200e3), gi[3:4]) +gi2 <- c(binPairs(gi[1:2], binSize=100e3, pos1=-200e3), gi[3:4]) ## Find overlaps findOverlaps(iarr, gi2) diff --git a/man/adjustEnrichment.Rd b/man/adjustEnrichment.Rd index facc406..7362cad 100644 --- a/man/adjustEnrichment.Rd +++ b/man/adjustEnrichment.Rd @@ -72,7 +72,7 @@ GenomeInfoDb::seqlevelsStyle(loops) <- 'ENSEMBL' ## Calculate loop enrichment enrich <- calcLoopEnrichment( - x=assignToBins(loops, 100e03), + x=binPairs(loops, 100e03), files=hicFiles ) diff --git a/man/aggHicMatrices.Rd b/man/aggHicMatrices.Rd index 7bb4763..c80da37 100644 --- a/man/aggHicMatrices.Rd +++ b/man/aggHicMatrices.Rd @@ -101,7 +101,7 @@ GenomeInfoDb::seqlevelsStyle(loops) <- 'ENSEMBL' ## Expand pixel ranges with a 5 pixel buffer on either side loops <- - assignToBins(loops, binSize=100e3) |> + binPairs(loops, binSize=100e3) |> pixelsToMatrices(buffer=5) ## Extract 10, 11x11 count matrices from 2 hic files diff --git a/man/assignToBins.Rd b/man/binPairs.Rd similarity index 71% rename from man/assignToBins.Rd rename to man/binPairs.Rd index a86801a..25ad679 100644 --- a/man/assignToBins.Rd +++ b/man/binPairs.Rd @@ -1,16 +1,16 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/AllGenerics.R, R/methods-assignToBins.R -\name{assignToBins} -\alias{assignToBins} -\alias{assignToBins,DF_OR_df_OR_dt,numeric,character_OR_numeric_OR_missing,character_OR_numeric_OR_missing-method} -\alias{assignToBins,GInteractions,numeric,character_OR_numeric_OR_missing,character_OR_numeric_OR_missing-method} +\name{binPairs} +\alias{binPairs} +\alias{binPairs,DF_OR_df_OR_dt,numeric,character_OR_numeric_OR_missing,character_OR_numeric_OR_missing-method} +\alias{binPairs,GInteractions,numeric,character_OR_numeric_OR_missing,character_OR_numeric_OR_missing-method} \title{Flexibly bin paired ranges} \usage{ -assignToBins(x, binSize, pos1 = "center", pos2 = "center", ...) +binPairs(x, binSize, pos1 = "center", pos2 = "center", ...) -\S4method{assignToBins}{DF_OR_df_OR_dt,numeric,character_OR_numeric_OR_missing,character_OR_numeric_OR_missing}(x, binSize, pos1, pos2) +\S4method{binPairs}{DF_OR_df_OR_dt,numeric,character_OR_numeric_OR_missing,character_OR_numeric_OR_missing}(x, binSize, pos1, pos2) -\S4method{assignToBins}{GInteractions,numeric,character_OR_numeric_OR_missing,character_OR_numeric_OR_missing}(x, binSize, pos1, pos2) +\S4method{binPairs}{GInteractions,numeric,character_OR_numeric_OR_missing,character_OR_numeric_OR_missing}(x, binSize, pos1, pos2) } \arguments{ \item{x}{`GInteractions` or `data.frame`-like @@ -48,7 +48,7 @@ df1 <- chr2 = "chr1", y1 = 30000, y2 = 40000) ## Assign each range to 20-kb bins from the start positions -assignToBins(x = df1, +binPairs(x = df1, binSize = 20000, pos1 = 'start', pos2 = 'start') @@ -61,7 +61,7 @@ gi1 <- as_ginteractions() ## Assign each range to 20-kb bins from the start positions -assignToBins(x = gi1, +binPairs(x = gi1, binSize = 20000, pos1 = 'start', pos2 = 'start') diff --git a/man/calcLoopEnrichment.Rd b/man/calcLoopEnrichment.Rd index 4c86136..fb4a031 100644 --- a/man/calcLoopEnrichment.Rd +++ b/man/calcLoopEnrichment.Rd @@ -111,7 +111,7 @@ loops <- GenomeInfoDb::seqlevelsStyle(loops) <- 'ENSEMBL' ## Expand binSize of loops -loops <- assignToBins(x=loops, binSize=100e3) +loops <- binPairs(x=loops, binSize=100e3) ## Calculate loop enrichment calcLoopEnrichment(x=loops[1:10], @@ -131,7 +131,7 @@ calcLoopEnrichment(x=loops[1:10], bg=bg) ## Extract count matrices first -mats <- assignToBins(loops[1:10],100e3) |> +mats <- binPairs(loops[1:10],100e3) |> pixelsToMatrices(buffer=10) |> pullHicMatrices( files=hicFiles, diff --git a/man/changePixelRes.Rd b/man/changePixelRes.Rd index 1e5e134..7760493 100644 --- a/man/changePixelRes.Rd +++ b/man/changePixelRes.Rd @@ -124,7 +124,7 @@ loops <- GenomeInfoDb::seqlevelsStyle(loops) <- 'ENSEMBL' ## Rebin loops to 2.5e6 resolution -loops <- assignToBins(x=loops, binSize=2.5e06) +loops <- binPairs(x=loops, binSize=2.5e06) ## Change pixel resolution from 2.5e6 to 500e3 changePixelRes(x=loops[1:5], diff --git a/man/clusters.Rd b/man/getPairClusters.Rd similarity index 79% rename from man/clusters.Rd rename to man/getPairClusters.Rd index 468f9ee..aeaa83c 100644 --- a/man/clusters.Rd +++ b/man/getPairClusters.Rd @@ -1,13 +1,13 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/AllGenerics.R, R/methods-MergedGInteractions.R -\name{clusters} -\alias{clusters} -\alias{clusters,MergedGInteractions-method} +\name{getPairClusters} +\alias{getPairClusters} +\alias{getPairClusters,MergedGInteractions-method} \title{Get clustered pairs from MergedGInteractions object} \usage{ -clusters(x, ...) +getPairClusters(x, ...) -\S4method{clusters}{MergedGInteractions}(x) +\S4method{getPairClusters}{MergedGInteractions}(x) } \arguments{ \item{x}{MergedGInteractions object.} @@ -50,10 +50,10 @@ x <- mergePairs(x = giList, radius = 10e03, column = "APScoreAvg") -## Access pair clusters -clusters(x[1:3]) -clusters(x[3:1]) -clusters(x[c(3, 1, 2)]) -clusters(x) |> length() +## Access pair getPairClusters +getPairClusters(x[1:3]) +getPairClusters(x[3:1]) +getPairClusters(x[c(3, 1, 2)]) +getPairClusters(x) |> length() } diff --git a/man/pileupPixels.Rd b/man/pileupPixels.Rd index 6c4abd1..87e28b1 100644 --- a/man/pileupPixels.Rd +++ b/man/pileupPixels.Rd @@ -106,7 +106,7 @@ loops <- setNames("WT") |> read.table(header=TRUE, nrows=1000) |> as_ginteractions(keep.extra.columns=FALSE) |> - assignToBins(binSize=5e3) + binPairs(binSize=5e3) ## Removes the "chr" prefix for compatibility ## with the preprocessed hic files diff --git a/man/pullHicMatrices.Rd b/man/pullHicMatrices.Rd index 1ff7f08..648313b 100644 --- a/man/pullHicMatrices.Rd +++ b/man/pullHicMatrices.Rd @@ -130,7 +130,7 @@ pixels <- setNames("WT") |> read.table(header=TRUE) |> as_ginteractions(keep.extra.columns=FALSE) |> - assignToBins(binSize=100e3) + binPairs(binSize=100e3) ## Removes the "chr" prefix for compatibility ## with the preprocessed hic files diff --git a/man/pullHicPixels.Rd b/man/pullHicPixels.Rd index 56a0836..76b7eff 100644 --- a/man/pullHicPixels.Rd +++ b/man/pullHicPixels.Rd @@ -120,7 +120,7 @@ pixels <- setNames("WT") |> read.table(header=TRUE) |> as_ginteractions(keep.extra.columns=FALSE) |> - assignToBins(binSize=100e3) + binPairs(binSize=100e3) ## Removes the "chr" prefix for compatibility ## with the preprocessed hic files diff --git a/man/selectPixel.Rd b/man/selectPixel.Rd index 194ce38..29fd512 100644 --- a/man/selectPixel.Rd +++ b/man/selectPixel.Rd @@ -75,7 +75,7 @@ loops <- GenomeInfoDb::seqlevelsStyle(loops) <- 'ENSEMBL' ## Rebin loops to 2.5e6 resolution -loops <- assignToBins(x=loops, binSize=2.5e06) +loops <- binPairs(x=loops, binSize=2.5e06) ## Pull 5x5 matrices iarr <- pullHicMatrices(x=loops[1:5], diff --git a/man/sets.Rd b/man/subsetBySource.Rd similarity index 70% rename from man/sets.Rd rename to man/subsetBySource.Rd index 5190ca7..75eea1a 100644 --- a/man/sets.Rd +++ b/man/subsetBySource.Rd @@ -1,22 +1,22 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/AllGenerics.R, R/methods-MergedGInteractions.R -\name{sets} -\alias{sets} -\alias{sets,MergedGInteractions,missing,missing-method} -\alias{sets,MergedGInteractions,character_OR_missing,missing-method} -\alias{sets,MergedGInteractions,missing,character_OR_missing-method} -\alias{sets,MergedGInteractions,character_OR_missing,character_OR_missing-method} +\name{subsetBySource} +\alias{subsetBySource} +\alias{subsetBySource,MergedGInteractions,missing,missing-method} +\alias{subsetBySource,MergedGInteractions,character_OR_missing,missing-method} +\alias{subsetBySource,MergedGInteractions,missing,character_OR_missing-method} +\alias{subsetBySource,MergedGInteractions,character_OR_missing,character_OR_missing-method} \title{Get each set from a MergedGInteractions object} \usage{ -sets(x, include, exclude) +subsetBySource(x, include, exclude) -\S4method{sets}{MergedGInteractions,missing,missing}(x) +\S4method{subsetBySource}{MergedGInteractions,missing,missing}(x) -\S4method{sets}{MergedGInteractions,character_OR_missing,missing}(x, include) +\S4method{subsetBySource}{MergedGInteractions,character_OR_missing,missing}(x, include) -\S4method{sets}{MergedGInteractions,missing,character_OR_missing}(x, exclude) +\S4method{subsetBySource}{MergedGInteractions,missing,character_OR_missing}(x, exclude) -\S4method{sets}{MergedGInteractions,character_OR_missing,character_OR_missing}(x, include, exclude) +\S4method{subsetBySource}{MergedGInteractions,character_OR_missing,character_OR_missing}(x, include, exclude) } \arguments{ \item{x}{MergedGInteractions object.} @@ -44,8 +44,8 @@ merged pair is not returned. } \details{ Optional `include` and `exclude` parameters modulate -the behavior of `sets` to return different -subsets of originating pairs. For example, `include` requires +the behavior of `subsetBySource` to return different +subsubsetBySource of originating pairs. For example, `include` requires that the returned pairs be present in specific sources, while `exclude` requires that returned pairs be absent from specific sources. Sources not listed in either @@ -78,6 +78,6 @@ giList <- split(x = GInteractions(gr1, gr2), ## Merge pairs x <- mergePairs(x = giList, radius = 20) -sets(x) +subsetBySource(x) } diff --git a/tests/testthat/Rplots.pdf b/tests/testthat/Rplots.pdf new file mode 100644 index 0000000..7a5f8a8 Binary files /dev/null and b/tests/testthat/Rplots.pdf differ diff --git a/tests/testthat/_snaps/MergedGInteractions.md b/tests/testthat/_snaps/MergedGInteractions.md index f27c0ed..07b5b12 100644 --- a/tests/testthat/_snaps/MergedGInteractions.md +++ b/tests/testthat/_snaps/MergedGInteractions.md @@ -24,12 +24,12 @@ Avg_diffMaxNeihgboor_1 Avg_diffMaxNeihgboor_2 avg std value 1: 1.8755854 2.121637 2.605124 0.7942202 4.272311 2: 1.8755854 2.121637 2.605124 0.7942202 4.272311 - 3: 1.9105295 1.946362 1.854944 0.6729783 3.553193 - 4: 1.9105295 1.946362 1.854944 0.6729783 3.553193 + 3: 1.9105295 1.946361 1.854944 0.6729783 3.553193 + 4: 1.9105295 1.946361 1.854944 0.6729783 3.553193 5: 1.0059373 1.645508 3.437883 0.5164226 4.332049 6: 1.0059373 1.645508 3.437883 0.5164226 4.332049 - 7: 0.8104557 1.486894 3.200528 0.6733462 3.920933 - 8: 0.8104557 1.486894 3.200528 0.6733462 3.920933 + 7: 0.8104557 1.486893 3.200528 0.6733462 3.920933 + 8: 0.8104557 1.486893 3.200528 0.6733462 3.920933 src id grp clst i.id 1: FS 1 1 1 1 2: FS 5 1 1 1 diff --git a/tests/testthat/_snaps/regularize.md b/tests/testthat/_snaps/regularize.md index 3575f29..9cee0bb 100644 --- a/tests/testthat/_snaps/regularize.md +++ b/tests/testthat/_snaps/regularize.md @@ -2,7 +2,7 @@ Code counts(regularize(ija, ndim = c(3, 3), scale = FALSE)) - Message + Message / Reading and realizing block 1/3 of file 1/1 ... OK \ Processing it ... diff --git a/tests/testthat/test_InteractionJaggedArray.R b/tests/testthat/test_InteractionJaggedArray.R index 60796c6..e6373ab 100644 --- a/tests/testthat/test_InteractionJaggedArray.R +++ b/tests/testthat/test_InteractionJaggedArray.R @@ -107,7 +107,7 @@ test_that("InteractionJaggedArray subsetByOverlaps", { ## Shift first two ranges out of range - gi2 <- c(assignToBins(gi[1:2], binSize=100e3, pos1=-200e3), gi[3:4]) + gi2 <- c(binPairs(gi[1:2], binSize=100e3, pos1=-200e3), gi[3:4]) ## findOverlaps expect_identical(length(findOverlaps(iarr, iarr)), 4L) diff --git a/tests/testthat/test_MergedGInteractions.R b/tests/testthat/test_MergedGInteractions.R index f34b62f..c515535 100644 --- a/tests/testthat/test_MergedGInteractions.R +++ b/tests/testthat/test_MergedGInteractions.R @@ -61,29 +61,29 @@ test_that(".mapIds returns expected output", { expect_snapshot(x = .mapIds(x)) }) -test_that("clusters accessor works", { +test_that("getPairClusters accessor works", { ## Merge pairs and add names x <- mergePairs(x = giList, radius = 10e03) names(x) <- paste0("loop", 1:length(x)) x[3:1] |> - clusters() |> + getPairClusters() |> names() |> expect_identical(paste0("loop", 3:1)) x[1:3] |> - clusters() |> + getPairClusters() |> names() |> expect_identical(paste0("loop", 1:3)) - expect_equal(length(clusters(x)), length(x)) + expect_equal(length(getPairClusters(x)), length(x)) }) -## TODO: Modfiy sets to return all sets +## TODO: Modfiy subsetBySource to return all subsetBySource ## by default -test_that("sets method works (and sources accessor)", { +test_that("subsetBySource method works (and sources accessor)", { ## LIMA loops test loopFiles <- c( @@ -114,71 +114,71 @@ test_that("sets method works (and sources accessor)", { ## Test sources accessor expect_identical(sources(x), names(loopFiles)) - ## sets method dispatch - expect_equal(sets(x) |> length(), 255) - expect_equal(sets(x)[[sources(x)[1]]] |> length(), 846) - expect_equal(sets(x, include = sources(x)[1]) |> length(), 3982) - expect_equal(sets(x, exclude = sources(x)[1]) |> length(), 9890) + ## subsetBySource method dispatch + expect_equal(subsetBySource(x) |> length(), 255) + expect_equal(subsetBySource(x)[[sources(x)[1]]] |> length(), 846) + expect_equal(subsetBySource(x, include = sources(x)[1]) |> length(), 3982) + expect_equal(subsetBySource(x, exclude = sources(x)[1]) |> length(), 9890) ## Handles cases where none are found - sets(x, + subsetBySource(x, include = sources(x)[1], exclude = sources(x)[1]) |> length() |> expect_equal(0) - sets(x, + subsetBySource(x, include = sources(x)[1:2], exclude = sources(x)[1]) |> length() |> expect_equal(0) - sets(x, exclude = sources(x)) |> + subsetBySource(x, exclude = sources(x)) |> length() |> expect_equal(0) ## Handles improper source name - expect_error(sets(x, include = "foo"), + expect_error(subsetBySource(x, include = "foo"), ".*foo.*not source option") - expect_error(sets(x, exclude = "foo"), + expect_error(subsetBySource(x, exclude = "foo"), ".*foo.*not source option") - expect_error(sets(x, include = ""), + expect_error(subsetBySource(x, include = ""), ".*not source option") - expect_error(sets(x, exclude = ""), + expect_error(subsetBySource(x, exclude = ""), ".*not source option") - expect_error(sets(x, include = "foo", exclude = "foo"), + expect_error(subsetBySource(x, include = "foo", exclude = "foo"), ".*foo.*not source option") - expect_error(sets(x, include = "foo", exclude = "bar"), + expect_error(subsetBySource(x, include = "foo", exclude = "bar"), ".*foo.*bar.*not source option") - expect_error(sets(x, + expect_error(subsetBySource(x, include = c(sources(x)[1], "foo"), exclude = "bar"), ".*foo.*bar.*not source option") - ## sets(x) produces same result as + ## subsetBySource(x) produces same result as ## using include & exclude - expect_equal(length(sets(x)[[sources(x)[1]]]), - length(sets(x, + expect_equal(length(subsetBySource(x)[[sources(x)[1]]]), + length(subsetBySource(x, include = sources(x)[1], exclude = sources(x)[2:8]))) - ## sets(x) produces same result as + ## subsetBySource(x) produces same result as ## include/exclude for the first 8 sources expect_equal( lapply(seq_along(sources(x)), \(i){ j <- seq_along(sources(x))[-i] - sets(x = x, + subsetBySource(x = x, include = sources(x)[i], exclude = sources(x)[j]) }) |> lapply(length) |> unlist(), - sets(x)[1:8] |> lapply(length) |> unlist() |> unname() + subsetBySource(x)[1:8] |> lapply(length) |> unlist() |> unname() ) - ## Results track with clusters(x) - mgi <- sets(x, + ## Results track with getPairClusters(x) + mgi <- subsetBySource(x, include = sources(x)[1:2], exclude = sources(x)[3:8]) - expect_identical(clusters(mgi) |> + expect_identical(getPairClusters(mgi) |> lapply(`[[`, "src") |> unlist() |> unique() |> @@ -210,7 +210,7 @@ test_that("Aggregating metadata columns works", { expect_identical(object = aggMetadata(x[1:10], columns = "APScoreAvg", funs = "mean")$mean.APScoreAvg, - expected = clusters(x[1:10]) |> + expected = getPairClusters(x[1:10]) |> lapply(`[[`, "APScoreAvg") |> lapply(mean) |> unlist()) diff --git a/tests/testthat/test_adjustEnrichment.R b/tests/testthat/test_adjustEnrichment.R index 8217ddf..5c39007 100644 --- a/tests/testthat/test_adjustEnrichment.R +++ b/tests/testthat/test_adjustEnrichment.R @@ -22,7 +22,7 @@ GenomeInfoDb::seqlevelsStyle(loops) <- 'ENSEMBL' ## Calculate loop enrichment enrich <- calcLoopEnrichment( - x=assignToBins(loops, 100e03), + x=binPairs(loops, 100e03), files=hicFiles ) diff --git a/tests/testthat/test_aggHicMatrices.R b/tests/testthat/test_aggHicMatrices.R index 1613d83..6d6657b 100644 --- a/tests/testthat/test_aggHicMatrices.R +++ b/tests/testthat/test_aggHicMatrices.R @@ -23,7 +23,7 @@ GenomeInfoDb::seqlevelsStyle(loops) <- 'ENSEMBL' ## Expand pixel ranges with a 5 pixel buffer on either side loops <- - assignToBins(loops, binSize=100e3) |> + binPairs(loops, binSize=100e3) |> pixelsToMatrices(buffer=5) ## Extract 10, 11x11 count matrices from 2 hic files diff --git a/tests/testthat/test_binPairs.R b/tests/testthat/test_binPairs.R index bc0982f..b7387c4 100644 --- a/tests/testthat/test_binPairs.R +++ b/tests/testthat/test_binPairs.R @@ -12,7 +12,7 @@ gi1 <- ## Tests ----------------------------------------------------------------------- -test_that("assignToBins can expand the resolution (from start)", { +test_that("binPairs can expand the resolution (from start)", { ## Construct GInteractions from data.frame exp <- @@ -21,7 +21,7 @@ test_that("assignToBins can expand the resolution (from start)", { as_ginteractions() obj <- - assignToBins(x = gi1, + binPairs(x = gi1, binSize = 20000, pos1 = 'start', pos2 = 'start') @@ -45,7 +45,7 @@ test_that("Bin to the TSS of one anchor", { as_ginteractions() obj <- - assignToBins(x = gi2, + binPairs(x = gi2, binSize = 1000, pos1 = 'start', pos2 = 2000) @@ -54,7 +54,7 @@ test_that("Bin to the TSS of one anchor", { }) -test_that("assignToBins retains metadata", { +test_that("binPairs retains metadata", { ## Construct GInteractions from data.frame exp <- @@ -67,7 +67,7 @@ test_that("assignToBins retains metadata", { gi1$var2 <- 10 obj <- - assignToBins(x = gi1, + binPairs(x = gi1, binSize = 20000, pos1 = 'start', pos2 = 'start') @@ -76,7 +76,7 @@ test_that("assignToBins retains metadata", { }) -test_that("assignToBins doesn't modify class", { +test_that("binPairs doesn't modify class", { ## Load required packages library(data.table) @@ -102,7 +102,7 @@ test_that("assignToBins doesn't modify class", { ## Binning bmgi <- - assignToBins(x = mgi, + binPairs(x = mgi, binSize = 10e03, pos1 = 'start', pos2 = 'end') @@ -113,7 +113,7 @@ test_that("assignToBins doesn't modify class", { ## For non merged data bp <- - assignToBins(x = giList[[1]], + binPairs(x = giList[[1]], binSize = 10e03, pos1 = 'start', pos2 = 'end') @@ -124,12 +124,12 @@ test_that("assignToBins doesn't modify class", { }) test_that("Binning checks for appropriate binSize", { - assignToBins(gi1, binSize = 0) |> + binPairs(gi1, binSize = 0) |> expect_error("`binSize` must be > 0") }) test_that("Anchors can be binned independently", { - bgi <- assignToBins(gi1, binSize=c(5e03, 1e03)) + bgi <- binPairs(gi1, binSize=c(5e03, 1e03)) expect_equal(unique(width(regions(bgi)))-1, c(5e03, 1e03)) }) diff --git a/tests/testthat/test_calcLoopEnrichment.R b/tests/testthat/test_calcLoopEnrichment.R index 88deb86..bf9b12c 100644 --- a/tests/testthat/test_calcLoopEnrichment.R +++ b/tests/testthat/test_calcLoopEnrichment.R @@ -529,7 +529,7 @@ test_that("calcLoopEnrichment", { ## Doesn't accept loops of variable resolution loops |> - assignToBins(c(5e03, 10e03)) |> + binPairs(c(5e03, 10e03)) |> calcLoopEnrichment(files=hicFiles) |> expect_error("All ranges.*must be equal widths.") @@ -556,7 +556,7 @@ test_that("calcLoopEnrichment", { dim = c(10L, 2L), dimnames = list(NULL, c("FS","WT")) )) - res <- calcLoopEnrichment(x=loops[1:10] |> assignToBins(100e03), + res <- calcLoopEnrichment(x=loops[1:10] |> binPairs(100e03), files=hicFiles) expect_equal(res, exp) expect_s4_class(res, "DelayedMatrix") @@ -585,7 +585,7 @@ test_that("InteractionArray method for calcLoopEnrichment runs correctly",{ ## Test non-square matrices mats <- - assignToBins(loops[1:100],binSize = c(100e3, 50e3)) |> + binPairs(loops[1:100],binSize = c(100e3, 50e3)) |> pullHicMatrices( files=hicFiles, binSize=10e3, @@ -597,7 +597,7 @@ test_that("InteractionArray method for calcLoopEnrichment runs correctly",{ ## Test even matrices mats <- - assignToBins(loops[1:100],binSize = 100e3) |> + binPairs(loops[1:100],binSize = 100e3) |> pullHicMatrices( files=hicFiles, binSize=50e3, @@ -609,7 +609,7 @@ test_that("InteractionArray method for calcLoopEnrichment runs correctly",{ ## Test non-matching buffers mats <- - assignToBins(loops[1:100],100e3) |> + binPairs(loops[1:100],100e3) |> pixelsToMatrices(buffer=5) |> pullHicMatrices( files=hicFiles, @@ -624,7 +624,7 @@ test_that("InteractionArray method for calcLoopEnrichment runs correctly",{ ) |> expect_error("`buffer` must be the same") mats <- - assignToBins(loops[1:100],100e3) |> + binPairs(loops[1:100],100e3) |> pixelsToMatrices(buffer=10) |> pullHicMatrices( files=hicFiles, @@ -676,7 +676,7 @@ test_that("InteractionArray method for calcLoopEnrichment runs correctly",{ )) mats <- - assignToBins(loops[1:10],100e3) |> + binPairs(loops[1:10],100e3) |> pixelsToMatrices(buffer=5) |> pullHicMatrices( files=hicFiles, @@ -731,7 +731,7 @@ test_that("calcLoopEnrichment function can use local environment objects",{ expect_error(.modifyEnrichFun(simpleFun), "object.*not found") mats <- - assignToBins(loops[1:10],100e3) |> + binPairs(loops[1:10],100e3) |> pixelsToMatrices(buffer=5) |> pullHicMatrices( files=hicFiles, diff --git a/tests/testthat/test_changePixelRes.R b/tests/testthat/test_changePixelRes.R index 548cdf2..872702d 100644 --- a/tests/testthat/test_changePixelRes.R +++ b/tests/testthat/test_changePixelRes.R @@ -20,7 +20,7 @@ loops <- GenomeInfoDb::seqlevelsStyle(loops) <- 'ENSEMBL' ## Rebin loops to 2.5e6 resolution -loops <- assignToBins(x=loops, binSize=2.5e06) +loops <- binPairs(x=loops, binSize=2.5e06) test_that("selectPixel chooses correctly", { diff --git a/tests/testthat/test_mergePairs.R b/tests/testthat/test_mergePairs.R index d610390..2bc6f90 100644 --- a/tests/testthat/test_mergePairs.R +++ b/tests/testthat/test_mergePairs.R @@ -345,8 +345,8 @@ test_that("Mean of modes option doesn't alter original ranges", { mgi1 <- mergePairs(x=gi, radius=binSize*2, column='count') mgi2 <- mergePairs(x=gi, radius=binSize*2) expect_identical( - clusters(mgi1), - clusters(mgi2) + getPairClusters(mgi1), + getPairClusters(mgi2) ) }) diff --git a/tests/testthat/test_pileupPixels.R b/tests/testthat/test_pileupPixels.R index 359c6dc..7e0832a 100644 --- a/tests/testthat/test_pileupPixels.R +++ b/tests/testthat/test_pileupPixels.R @@ -13,7 +13,7 @@ test_that("pileupPixels works", { setNames("WT") |> read.table(header=TRUE, nrows=1000) |> as_ginteractions(keep.extra.columns=FALSE) |> - assignToBins(binSize=5e3) + binPairs(binSize=5e3) ## Removes the "chr" prefix for compatibility ## with the preprocessed hic files diff --git a/tests/testthat/test_pixelsToMatrices.R b/tests/testthat/test_pixelsToMatrices.R index bf12209..b65e395 100644 --- a/tests/testthat/test_pixelsToMatrices.R +++ b/tests/testthat/test_pixelsToMatrices.R @@ -24,7 +24,7 @@ test_that("metadata columns are kept", { }) test_that("throws error when ranges are not binned", { - assignToBins(gi, binSize=c(10, 20)) |> + binPairs(gi, binSize=c(10, 20)) |> pixelsToMatrices(buffer=3) |> expect_error(".*must be equal widths.*") }) diff --git a/tests/testthat/test_pullHic.R b/tests/testthat/test_pullHic.R index 6d70048..ab75e1a 100644 --- a/tests/testthat/test_pullHic.R +++ b/tests/testthat/test_pullHic.R @@ -49,7 +49,7 @@ mgi <- mergePairs(x = giList, radius = 50e03) ## Bin MergedGInteractions -bgi <- assignToBins(x = mgi, binSize = 50e03) +bgi <- binPairs(x = mgi, binSize = 50e03) ## Bin with snapping sgi <- snapToBins(x = mgi, binSize = 50e03) @@ -237,7 +237,7 @@ test_that("Straw args are checked correctly", { test_that("pullHicPixels pulls correct counts", { ## Assign to x (to avoid modifying in place) - x <- assignToBins(bgi[1:10], 2.5e06) + x <- binPairs(bgi[1:10], 2.5e06) seqlevelsStyle(x) <- "ENSEMBL" ## Give names to hicFiles diff --git a/tests/testthat/test_removeShortPairs.R b/tests/testthat/test_removeShortPairs.R index 7996bda..bb995a4 100644 --- a/tests/testthat/test_removeShortPairs.R +++ b/tests/testthat/test_removeShortPairs.R @@ -80,7 +80,7 @@ test_that("complex test for removeShortPairs", { loops <- mergePairs(loopList, radius=100e3) |> GenomeInfoDb::`seqlevelsStyle<-`('ENSEMBL') |> - assignToBins(binSize=100e3) + binPairs(binSize=100e3) ## Expand to apa regions regions <- pixelsToMatrices(loops, buffer=5) diff --git a/tests/testthat/test_utils.R b/tests/testthat/test_utils.R index a5e06ea..adfcc72 100644 --- a/tests/testthat/test_utils.R +++ b/tests/testthat/test_utils.R @@ -177,7 +177,7 @@ test_that("Getting binSize", { .getBinSize(x=loops) |> expect_identical(5000) - .getBinSize(x=assignToBins(loops, 10e03)) |> + .getBinSize(x=binPairs(loops, 10e03)) |> expect_identical(10000) }) @@ -212,7 +212,7 @@ test_that("defaultBuffer returns correct result", { ## Extract count matrices mats <- - assignToBins(loops[1:10],100e3) |> + binPairs(loops[1:10],100e3) |> pixelsToMatrices(buffer=testBuffer) |> pullHicMatrices( files=hicFiles, diff --git a/vignettes/articles/pull_hic.Rmd b/vignettes/articles/pull_hic.Rmd index a8947bd..01d3d89 100644 --- a/vignettes/articles/pull_hic.Rmd +++ b/vignettes/articles/pull_hic.Rmd @@ -49,7 +49,7 @@ border-bottom: 1px solid #dee2e6; You can check your `.hic` file to see which resolutions are available for the `binSize` argument with the -`strawr::readHicBpResolutions()`. See the `assignToBins()` +`strawr::readHicBpResolutions()`. See the `binPairs()` to set your interactions to an acceptable resolution. @@ -153,7 +153,7 @@ the width of both anchors to be 500 Kb ```{r} ## Create 500x500 Kb regions -regions <- assignToBins(x=gi, binSize=500e3, pos1="start", pos2="start") +regions <- binPairs(x=gi, binSize=500e3, pos1="start", pos2="start") ``` Then set the `binSize` to 100 Kb @@ -222,7 +222,7 @@ to be 600 Kb. ```{r} ## Create 300x600 Kb regions -regions <- assignToBins( +regions <- binPairs( x=gi, binSize=c(300e3, 600e3), pos1="start", diff --git a/vignettes/mariner.Rmd b/vignettes/mariner.Rmd index ecb7c32..34a470c 100644 --- a/vignettes/mariner.Rmd +++ b/vignettes/mariner.Rmd @@ -117,7 +117,7 @@ to differently sized bins. ```{r binning1, message=FALSE} ## Assign to 1Kb bins -binned <- assignToBins(x=gi, binSize = 1e3, pos1='center', pos2='center') +binned <- binPairs(x=gi, binSize = 1e3, pos1='center', pos2='center') ## Show that each anchor is 1Kb library(InteractionSet) @@ -150,14 +150,14 @@ binned separately and from different reference points ```{r binning2} ## Assign anchor1 to 1Kb bins and anchor2 to 25Kb bins -binned <- assignToBins(x=gi, binSize=c(1e3, 25e3), pos1="start", pos2="center") +binned <- binPairs(x=gi, binSize=c(1e3, 25e3), pos1="start", pos2="center") ## Show that the first anchor is 1Kb and ## second anchor is 25Kb width(binned) |> lapply(unique) ``` -While `assignToBins()` assigns each pair of ranges +While `binPairs()` assigns each pair of ranges to a single bin, the `snapToBins()` function assigns the starts and ends of the ranges to their nearest bin. This allows each anchor to @@ -256,7 +256,7 @@ The metadata is missing from these interactions. Since no `column` was provided, each interaction may be an average of one or more interaction. The user can decide how metadata from each cluster -should be aggregated with `aggMetadata()`. +should be aggregated with `aggPairMcols()`. The resulting object is `MergedGInteractions` class, @@ -266,11 +266,11 @@ behaves like `GInteractions` but contains additional information about the clustered interactions. To view the clusters of specific interactions, use -the `clusters()` accessor. +the `getPairClusters()` accessor. ```{r clusters, results='hold'} mgi[12772] -clusters(mgi[12772]) +getPairClusters(mgi[12772]) ``` When no `column` argument is provided the most @@ -297,10 +297,10 @@ for "APScoreAvg" has been selected. ```{r clusters2, results='hold'} mgi[12772] -clusters(mgi[12772]) +getPairClusters(mgi[12772]) ``` -The `sets()` accessor allows users to +The `subsetBySource()` accessor allows users to find which interactions are shared or exclusive between sets of interactions in the giList. @@ -309,15 +309,15 @@ between sets of interactions in the giList. sources(mgi) ## Interactions unique to each source -sets(mgi) |> lapply(summary) +subsetBySource(mgi) |> lapply(summary) ## Interactions shared by both sources -sets(x=mgi, include=sources(mgi)) +subsetBySource(x=mgi, include=sources(mgi)) ``` This is particularly useful for identifying _de novo_, shared or transient interactions. -For more information see `?sets()`. +For more information see `?subsetBySource()`. ## Extracting & Aggregating Interactions @@ -408,11 +408,11 @@ GenomeInfoDb::seqlevelsStyle(mgi) <- 'ENSEMBL' These interactions can then be binned to the desired -resolution with the `assignToBins()` function. +resolution with the `binPairs()` function. ```{r binPixels} ## Assign interactions to 100Kb bins -binned <- assignToBins(x=mgi, binSize=100e3) +binned <- binPairs(x=mgi, binSize=100e3) ``` Contact frequency can then be extracted with @@ -553,7 +553,7 @@ This also works on rectangular selections. ```{r pullMatrices3} ## Bin at two different resolutions -binned <- assignToBins(x=mgi, binSize=c(100e3, 250e3)) +binned <- binPairs(x=mgi, binSize=c(100e3, 250e3)) ## Pull 10x25 matrices from 1000 interactions and 2 hic files iarr2 <- pullHicMatrices( @@ -682,7 +682,7 @@ loops <- setNames("WT") |> read.table(header=TRUE, nrows=1000) |> as_ginteractions() |> - assignToBins(binSize=100e3) |> + binPairs(binSize=100e3) |> GenomeInfoDb::`seqlevelsStyle<-`('ENSEMBL') ## Define foreground & background