Skip to content

Commit

Permalink
feat: new getters anchors{12} ranges{12}
Browse files Browse the repository at this point in the history
  • Loading branch information
js2264 committed Sep 2, 2023
1 parent 207a5d8 commit 2592655
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 13 deletions.
13 changes: 13 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ S3method(filter,GInteractions)
S3method(mutate,GInteractions)
S3method(select,GInteractions)
S3method(slice,GInteractions)
export(anchors1)
export(anchors2)
export(arrange)
export(as_ginteractions)
export(end1)
export(end2)
export(filter)
export(mutate)
export(ranges1)
export(ranges2)
export(select)
export(seqnames1)
export(seqnames2)
Expand All @@ -25,8 +29,12 @@ export(strand2)
export(width1)
export(width2)
exportMethods("$")
exportMethods(anchors1)
exportMethods(anchors2)
exportMethods(end1)
exportMethods(end2)
exportMethods(ranges1)
exportMethods(ranges2)
exportMethods(seqnames1)
exportMethods(seqnames2)
exportMethods(start1)
Expand All @@ -39,14 +47,19 @@ importFrom(BiocGenerics,end)
importFrom(BiocGenerics,start)
importFrom(BiocGenerics,strand)
importFrom(BiocGenerics,width)
importFrom(GenomeInfoDb,seqinfo)
importFrom(GenomeInfoDb,seqnames)
importFrom(GenomicRanges,GRanges)
importFrom(IRanges,IRanges)
importFrom(IRanges,ranges)
importFrom(InteractionSet,GInteractions)
importFrom(InteractionSet,anchors)
importFrom(InteractionSet,regions)
importFrom(S4Vectors,"first<-")
importFrom(S4Vectors,"mcols<-")
importFrom(S4Vectors,"second<-")
importFrom(S4Vectors,mcols)
importFrom(S4Vectors,showAsCell)
importFrom(dplyr,arrange)
importFrom(dplyr,filter)
importFrom(dplyr,mutate)
Expand Down
60 changes: 49 additions & 11 deletions R/ginteractions-getters.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
#' @examples
#' gi <- data.frame(
#' seqnames1 = 'chr1', start1 = 1, end1 = 10,
#' seqnames2 = 'chr1', start2 = 1, end2 = 10
#' seqnames2 = 'chr1', start2 = 2, end2 = 20
#' ) |> as_ginteractions() |> mutate(type = 'cis')
#' anchors1(gi)
#' anchors2(gi)
#' seqnames1(gi)
#' seqnames2(gi)
#' start1(gi)
Expand All @@ -20,6 +22,8 @@
#' end2(gi)
#' width1(gi)
#' width2(gi)
#' ranges1(gi)
#' ranges2(gi)
#' strand1(gi)
#' strand2(gi)
#' gi$type
Expand All @@ -37,6 +41,12 @@ setMethod("$", "GInteractions",
function(x, name) mcols(x, use.names=FALSE)[[name]]
)

#' @rdname ginteractions-getters
#' @export
setGeneric("anchors1", function(x) standardGeneric("anchors1"))
#' @rdname ginteractions-getters
#' @export
setGeneric("anchors2", function(x) standardGeneric("anchors2"))
#' @rdname ginteractions-getters
#' @export
setGeneric("seqnames1", function(x) standardGeneric("seqnames1"))
Expand Down Expand Up @@ -67,58 +77,86 @@ setGeneric("strand1", function(x) standardGeneric("strand1"))
#' @rdname ginteractions-getters
#' @export
setGeneric("strand2", function(x) standardGeneric("strand2"))
#' @rdname ginteractions-getters
#' @export
setGeneric("ranges1", function(x) standardGeneric("ranges1"))
#' @rdname ginteractions-getters
#' @export
setGeneric("ranges2", function(x) standardGeneric("ranges2"))

#' @rdname ginteractions-getters
#' @export
setMethod("anchors1", signature("GInteractions"), function(x) {
S4Vectors::first(x)
})
#' @rdname ginteractions-getters
#' @export
setMethod("anchors2", signature("GInteractions"), function(x) {
S4Vectors::second(x)
})
#' @importFrom GenomeInfoDb seqnames
#' @rdname ginteractions-getters
#' @export
setMethod("seqnames1", signature("GInteractions"), function(x) {
GenomeInfoDb::seqnames(S4Vectors::first(x))
GenomeInfoDb::seqnames(anchors1(x))
})
#' @rdname ginteractions-getters
#' @export
setMethod("seqnames2", signature("GInteractions"), function(x) {
GenomeInfoDb::seqnames(S4Vectors::second(x))
GenomeInfoDb::seqnames(anchors2(x))
})
#' @importFrom BiocGenerics start
#' @rdname ginteractions-getters
#' @export
setMethod("start1", signature("GInteractions"), function(x) {
BiocGenerics::start(S4Vectors::first(x))
BiocGenerics::start(anchors1(x))
})
#' @rdname ginteractions-getters
#' @export
setMethod("start2", signature("GInteractions"), function(x) {
BiocGenerics::start(S4Vectors::second(x))
BiocGenerics::start(anchors2(x))
})
#' @importFrom BiocGenerics end
#' @rdname ginteractions-getters
#' @export
setMethod("end1", signature("GInteractions"), function(x) {
BiocGenerics::end(S4Vectors::first(x))
BiocGenerics::end(anchors1(x))
})
#' @rdname ginteractions-getters
#' @export
setMethod("end2", signature("GInteractions"), function(x) {
BiocGenerics::end(S4Vectors::second(x))
BiocGenerics::end(anchors2(x))
})
#' @importFrom BiocGenerics width
#' @rdname ginteractions-getters
#' @export
setMethod("width1", signature("GInteractions"), function(x) {
BiocGenerics::width(S4Vectors::first(x))
BiocGenerics::width(anchors1(x))
})
#' @rdname ginteractions-getters
#' @export
setMethod("width2", signature("GInteractions"), function(x) {
BiocGenerics::width(S4Vectors::second(x))
BiocGenerics::width(anchors2(x))
})
#' @importFrom BiocGenerics strand
#' @rdname ginteractions-getters
#' @export
setMethod("strand1", signature("GInteractions"), function(x) {
BiocGenerics::strand(S4Vectors::first(x))
BiocGenerics::strand(anchors1(x))
})
#' @rdname ginteractions-getters
#' @export
setMethod("strand2", signature("GInteractions"), function(x) {
BiocGenerics::strand(S4Vectors::second(x))
BiocGenerics::strand(anchors2(x))
})
#' @importFrom IRanges ranges
#' @rdname ginteractions-getters
#' @export
setMethod("ranges1", signature("GInteractions"), function(x) {
IRanges::ranges(anchors1(x))
})
#' @rdname ginteractions-getters
#' @export
setMethod("ranges2", signature("GInteractions"), function(x) {
IRanges::ranges(anchors2(x))
})
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ and logical expressions;
- Pick out any columns from the associated metadata with `select`
using [`<tidy-select>` arguments](https://dplyr.tidyverse.org/reference/dplyr_tidy_select.html);
- Subset using indices with `slice`.
- Order genomic interactions with `arrange` using categorical/numerical
variables.

## Installation

Expand All @@ -42,4 +44,4 @@ This package is largely inspired by `plyranges` and the `tidyverse`:

- Lee, Stuart, Dianne Cook, and Michael Lawrence. 2019. “Plyranges: A Grammar of Genomic Data Transformation.” Genome Biology 20 (1): 4. https://doi.org/10.1186/s13059-018-1597-8.
- Wickham H, François R, Henry L, Müller K, Vaughan D (2023). _dplyr: A Grammar of Data Manipulation_. R package version 1.1.2, <https://CRAN.R-project.org/package=dplyr>.
- Henry L, Wickham H (2023). _rlang: Functions for Base Types and Core R and 'Tidyverse' Features_. R package version 1.1.1, <https://CRAN.R-project.org/package=rlang>.
- Henry L, Wickham H (2023). _rlang: Functions for Base Types and Core R and 'Tidyverse' Features_. R package version 1.1.1, <https://CRAN.R-project.org/package=rlang>.
30 changes: 29 additions & 1 deletion man/ginteractions-getters.Rd

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

0 comments on commit 2592655

Please sign in to comment.