forked from tidyomics/plyinteractions
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: start AnchoredPinnedGInteractions and anchor methods
- Loading branch information
Showing
12 changed files
with
680 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#' @importFrom InteractionSet GInteractions | ||
#' @importFrom S4Vectors DataFrame | ||
#' @importFrom S4Vectors Rle | ||
#' @importFrom utils capture.output | ||
#' @importFrom methods show | ||
#' @include PinnedGInteractions-class.R | ||
setClass("AnchoredPinnedGInteractions", | ||
slot = c( | ||
anchor = "character" | ||
), | ||
contains = c("PinnedGInteractions") | ||
) | ||
|
||
#' @importFrom InteractionSet GInteractions | ||
#' @importFrom methods setMethod initialize | ||
setMethod("initialize", "AnchoredPinnedGInteractions", function( | ||
.Object, delegate = InteractionSet::GInteractions(), pin, anchor | ||
) { | ||
stopifnot( | ||
pin %in% c("anchors1", "first", "1", "anchors2", "second", "2") | ||
) | ||
pin <- switch(pin, | ||
"anchors1" = 1L, | ||
"first" = 1L, | ||
"1" = 1L, | ||
"anchors2" = 2L, | ||
"second" = 2L, | ||
"2" = 2L | ||
) | ||
.Object@delegate <- delegate | ||
.Object@pin <- pin | ||
.Object@anchor <- anchor | ||
.Object | ||
}) | ||
|
||
setMethod("show", "AnchoredPinnedGInteractions", function(object) { | ||
output <- c("", utils::capture.output(show(object@delegate))) | ||
output[1] <- output[2] | ||
output[2] <- paste0( | ||
"Pinned on: `anchors", object@pin, | ||
"` (anchored on: `", object@anchor, "`)" | ||
) | ||
cat(output, sep = "\n") | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#' @importFrom InteractionSet GInteractions | ||
#' @importFrom S4Vectors DataFrame | ||
#' @importFrom S4Vectors Rle | ||
#' @importFrom utils capture.output | ||
#' @importFrom methods show | ||
#' @include DelegatingGInteractions-class.R | ||
setClass("PinnedGInteractions", | ||
slot = c( | ||
pin = "integer" | ||
), | ||
contains = c("DelegatingGInteractions") | ||
) | ||
|
||
#' @importFrom InteractionSet GInteractions | ||
#' @importFrom methods setMethod initialize | ||
setMethod("initialize", "PinnedGInteractions", function( | ||
.Object, delegate = InteractionSet::GInteractions(), pin | ||
) { | ||
stopifnot( | ||
pin %in% c("anchors1", "first", "1", "anchors2", "second", "2") | ||
) | ||
pin <- switch(pin, | ||
"anchors1" = 1L, | ||
"first" = 1L, | ||
"1" = 1L, | ||
"anchors2" = 2L, | ||
"second" = 2L, | ||
"2" = 2L | ||
) | ||
.Object@delegate <- delegate | ||
.Object@pin <- pin | ||
.Object | ||
}) | ||
|
||
setMethod("show", "PinnedGInteractions", function(object) { | ||
output <- c("", utils::capture.output(show(object@delegate))) | ||
output[1] <- output[2] | ||
output[2] <- paste0("Pinned on: anchors", object@pin) | ||
cat(output, sep = "\n") | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
#' Pin GInteractions by anchors set (anchors1 or anchors2). | ||
#' | ||
#' @param .data,x a (Grouped)GInteractions object | ||
#' @param anchors Anchors to pin on ("first" or "second") | ||
#' | ||
#' @return a PinnedGInteractions object. | ||
#' | ||
#' @rdname ginteractions-pin | ||
#' | ||
#' @examples | ||
#' gi <- read.table(text = " | ||
#' chr1 11 20 chr1 21 30 | ||
#' chr1 11 20 chr1 51 50 | ||
#' chr1 11 30 chr1 51 50 | ||
#' chr1 11 30 chr2 51 60", | ||
#' col.names = c("seqnames1", "start1", "end1", "seqnames2", "start2", "end2")) |> | ||
#' as_ginteractions() |> | ||
#' mutate(type = c('cis', 'cis', 'cis', 'trans'), score = runif(4)) | ||
#' | ||
#' #################################################################### | ||
#' # 1. Pin and modify anchors | ||
#' #################################################################### | ||
#' | ||
#' gi |> pin("first") | ||
#' | ||
#' gi |> pin_by("first") | ||
#' | ||
#' gi |> pin_first() | ||
#' | ||
#' gi |> pin_anchors1() | ||
#' | ||
#' #################################################################### | ||
#' # 2. Pin by second anchors | ||
#' #################################################################### | ||
#' | ||
#' gi |> pin("second") | ||
#' | ||
#' gi |> pin_by("second") | ||
#' | ||
#' gi |> pin_second() | ||
#' | ||
#' gi |> pin_anchors2() | ||
#' | ||
#' #################################################################### | ||
#' # 3. Unpin | ||
#' #################################################################### | ||
#' | ||
#' gi |> pin("second") |> unpin() | ||
#' | ||
#' @export | ||
setGeneric("pin", function(x, anchors) standardGeneric("pin")) | ||
|
||
#' @rdname ginteractions-pin | ||
#' @export | ||
setMethod("pin", signature(x = "GInteractions", anchors = "character"), function(x, anchors) { | ||
methods::new("PinnedGInteractions", x, anchors) | ||
}) | ||
|
||
#' @rdname ginteractions-pin | ||
#' @export | ||
setMethod("pin", signature(x = "GInteractions", anchors = "numeric"), function(x, anchors) { | ||
if (!anchors %in% c(1, 2)) stop("`anchors` can only be set to `1` or `2`") | ||
methods::new("PinnedGInteractions", x, as.character(anchors)) | ||
}) | ||
|
||
#' @rdname ginteractions-pin | ||
#' @export | ||
setMethod("pin", signature(x = "PinnedGInteractions", anchors = "missing"), function(x, anchors) { | ||
x@pin | ||
}) | ||
|
||
#' @rdname ginteractions-pin | ||
#' @export | ||
setMethod("pin", signature(x = "PinnedGInteractions", anchors = "character"), function(x, anchors) { | ||
methods::new("PinnedGInteractions", x@delegate, anchors) | ||
}) | ||
|
||
#' @rdname ginteractions-pin | ||
#' @export | ||
setMethod("pin", signature(x = "PinnedGInteractions", anchors = "numeric"), function(x, anchors) { | ||
if (!anchors %in% c(1, 2)) stop("`anchors` can only be set to `1` or `2`") | ||
methods::new("PinnedGInteractions", x@delegate, as.character(anchors)) | ||
}) | ||
|
||
#' @export | ||
#' @rdname ginteractions-pin | ||
setGeneric("pin_by", function(x, anchors) pin(x, anchors)) | ||
|
||
#' @rdname ginteractions-pin | ||
#' @export | ||
pin_first <- function(x) pin(x, 1) | ||
|
||
#' @rdname ginteractions-pin | ||
#' @export | ||
pin_second <- function(x) pin(x, 2) | ||
|
||
#' @rdname ginteractions-pin | ||
#' @export | ||
pin_anchors1 <- function(x) pin(x, 1) | ||
|
||
#' @rdname ginteractions-pin | ||
#' @export | ||
pin_anchors2 <- function(x) pin(x, 2) | ||
|
||
#' @rdname ginteractions-pin | ||
#' @export | ||
setGeneric("unpin", function(x) standardGeneric("unpin")) | ||
|
||
#' @rdname ginteractions-pin | ||
#' @export | ||
setMethod("unpin", signature(x = "PinnedGInteractions"), function(x) { | ||
x@delegate | ||
}) | ||
|
||
#' @rdname ginteractions-pin | ||
#' @export | ||
setMethod("unpin", signature(x = "GInteractions"), function(x) { | ||
x | ||
}) | ||
|
||
#' @rdname ginteractions-pin | ||
#' @export | ||
setGeneric("pinned_anchors", function(x) standardGeneric("pinned_anchors")) | ||
|
||
#' @rdname ginteractions-pin | ||
#' @export | ||
setMethod("pinned_anchors", signature(x = "PinnedGInteractions"), function(x) { | ||
id <- switch(pin(x), "1" = "first", "2" = "second") | ||
InteractionSet::anchors(x@delegate, type = id) | ||
}) |
Oops, something went wrong.