Skip to content

Commit

Permalink
doc: fix lines > 80 characters
Browse files Browse the repository at this point in the history
  • Loading branch information
js2264 committed Oct 8, 2023
1 parent bf8b198 commit 24c4ca2
Show file tree
Hide file tree
Showing 41 changed files with 354 additions and 152 deletions.
8 changes: 6 additions & 2 deletions R/AllGenerics.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#' @rdname replace_anchors
#' @export
setGeneric("replace_anchors", function(x, id, value) standardGeneric("replace_anchors"))
setGeneric("replace_anchors",
function(x, id, value) standardGeneric("replace_anchors")
)



Expand All @@ -27,7 +29,9 @@ setGeneric("unpin", function(x) standardGeneric("unpin"))
setGeneric("annotate", function(x, y, by) standardGeneric("annotate"))
#' @rdname ginteractions-annotate
#' @export
setGeneric("annotate_directed", function(x, y, by) standardGeneric("annotate_directed"))
setGeneric("annotate_directed",
function(x, y, by) standardGeneric("annotate_directed")
)



Expand Down
15 changes: 12 additions & 3 deletions R/anchor.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,28 @@ anchor_5p.PinnedGInteractions <- function(x) {
#' @name ginteractions-anchor
#' @export
anchor_start.AnchoredPinnedGInteractions <- function(x) {
new("AnchoredPinnedGInteractions", unanchor(x), pin = pin(x), anchor = "start")
new(
"AnchoredPinnedGInteractions",
unanchor(x), pin = pin(x), anchor = "start"
)
}

#' @name ginteractions-anchor
#' @export
anchor_end.AnchoredPinnedGInteractions <- function(x) {
new("AnchoredPinnedGInteractions", unanchor(x), pin = pin(x), anchor = "end")
new(
"AnchoredPinnedGInteractions",
unanchor(x), pin = pin(x), anchor = "end"
)
}

#' @name ginteractions-anchor
#' @export
anchor_center.AnchoredPinnedGInteractions <- function(x) {
new("AnchoredPinnedGInteractions", unanchor(x), pin = pin(x), anchor = "center")
new(
"AnchoredPinnedGInteractions",
unanchor(x), pin = pin(x), anchor = "center"
)
}

#' @name ginteractions-anchor
Expand Down
5 changes: 4 additions & 1 deletion R/annotate.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
#' gi <- read.table(text = "
#' chr1 11 20 - chr1 21 30 +
#' chr1 21 30 + chr2 51 60 +",
#' col.names = c("seqnames1", "start1", "end1", "strand1", "seqnames2", "start2", "end2", "strand2")
#' col.names = c(
#' "seqnames1", "start1", "end1", "strand1",
#' "seqnames2", "start2", "end2", "strand2"
#' )
#' ) |> as_ginteractions()
#'
#' gr <- GenomicRanges::GRanges(c("chr1:20-30:+", "chr2:55-65:+")) |>
Expand Down
5 changes: 4 additions & 1 deletion R/arrange.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
#' chr3 3 10 chr3 1 10
#' chr4 4 10 chr4 1 10
#' chr5 5 10 chr5 1 10",
#' col.names = c("seqnames1", "start1", "end1", "seqnames2", "start2", "end2")) |>
#' col.names = c(
#' "seqnames1", "start1", "end1",
#' "seqnames2", "start2", "end2")
#' ) |>
#' as_ginteractions() |>
#' mutate(cis = seqnames1 == seqnames2, score = runif(5)*100, gc = runif(5))
#' gi
Expand Down
9 changes: 7 additions & 2 deletions R/count-overlaps.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@
#' chr1 11 20 - chr1 51 55 +
#' chr1 21 30 - chr1 51 55 +
#' chr1 21 30 - chr2 51 60 +",
#' col.names = c("seqnames1", "start1", "end1", "strand1", "seqnames2", "start2", "end2", "strand2")
#' col.names = c(
#' "seqnames1", "start1", "end1", "strand1",
#' "seqnames2", "start2", "end2", "strand2"
#' )
#' ) |> as_ginteractions() |> mutate(id = 1:4, type = 'gi')
#'
#' gr <- GenomicRanges::GRanges(c("chr1:20-30:+", "chr2:55-65:-")) |> plyranges::mutate(id = 1:2, type = 'gr')
#' gr <- GenomicRanges::GRanges(
#' c("chr1:20-30:+", "chr2:55-65:-")
#' ) |> plyranges::mutate(id = 1:2, type = 'gr')
#'
#' gi
#'
Expand Down
4 changes: 3 additions & 1 deletion R/count.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@
#' @importFrom rlang expr
#' @importFrom dplyr desc
#' @export
tally.GroupedGInteractions <- function(x, wt = NULL, sort = FALSE, name = NULL) {
tally.GroupedGInteractions <- function(
x, wt = NULL, sort = FALSE, name = NULL
) {

## Check provided name against gorup names
name <- check_n_name(name, group_vars(x))
Expand Down
8 changes: 6 additions & 2 deletions R/filter-overlaps.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@
#' chr1 11 20 - chr1 51 55 +
#' chr1 21 30 - chr1 51 55 +
#' chr1 21 30 - chr2 51 60 +",
#' col.names = c("seqnames1", "start1", "end1", "strand1", "seqnames2", "start2", "end2", "strand2")
#' col.names = c(
#' "seqnames1", "start1", "end1", "strand1",
#' "seqnames2", "start2", "end2", "strand2")
#' ) |> as_ginteractions() |> mutate(id = 1:4, type = 'gi')
#'
#' gr <- GenomicRanges::GRanges(c("chr1:20-30:+", "chr2:55-65:-")) |> plyranges::mutate(id = 1:2, type = 'gr')
#' gr <- GenomicRanges::GRanges(
#' c("chr1:20-30:+", "chr2:55-65:-")
#' ) |> plyranges::mutate(id = 1:2, type = 'gr')
#'
#' gi
#'
Expand Down
5 changes: 4 additions & 1 deletion R/filter.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
#' chr3 3 10 chr3 1 10
#' chr4 4 10 chr4 1 10
#' chr5 5 10 chr5 1 10",
#' col.names = c("seqnames1", "start1", "end1", "seqnames2", "start2", "end2")) |>
#' col.names = c(
#' "seqnames1", "start1", "end1",
#' "seqnames2", "start2", "end2")
#' ) |>
#' as_ginteractions() |>
#' mutate(cis = seqnames1 == seqnames2, score = runif(5)*100, gc = runif(5))
#' gi
Expand Down
30 changes: 21 additions & 9 deletions R/find-overlaps.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
#' @section Rationale:
#'
#' `find_overlaps()` will search for any overlap between `GInteractions`
#' in `x` and `GRanges` in `y`. It will return a `GInteractions` object of length
#' equal to the number of times `x` overlaps `y`. This `GInteractions` will
#' have additional metadata columns corresponding to the metadata from `y`.
#' `find_overlaps_directed()` takes the strandness of each object into account.
#' in `x` and `GRanges` in `y`. It will return a `GInteractions`
#' object of length equal to the number of times `x` overlaps `y`.
#' This `GInteractions` will have additional metadata columns
#' corresponding to the metadata from `y`. `find_overlaps_directed()`
#' takes the strandness of each object into account.
#'
#' @section Pinned `GInteractions`:
#'
Expand Down Expand Up @@ -38,10 +39,15 @@
#' chr1 11 20 - chr1 51 55 +
#' chr1 21 30 - chr1 51 55 +
#' chr1 21 30 - chr2 51 60 +",
#' col.names = c("seqnames1", "start1", "end1", "strand1", "seqnames2", "start2", "end2", "strand2")
#' col.names = c(
#' "seqnames1", "start1", "end1", "strand1",
#' "seqnames2", "start2", "end2", "strand2"
#' )
#' ) |> as_ginteractions() |> mutate(id = 1:4, type = 'gi')
#'
#' gr <- GenomicRanges::GRanges(c("chr1:20-30:+", "chr2:55-65:-")) |> plyranges::mutate(id = 1:2, type = 'gr')
#' gr <- GenomicRanges::GRanges(
#' c("chr1:20-30:+", "chr2:55-65:-")
#' ) |> plyranges::mutate(id = 1:2, type = 'gr')
#'
#' gi
#'
Expand Down Expand Up @@ -168,19 +174,25 @@ find_overlaps_directed.GInteractions <- function(

}

.mcols_overlaps_update <- function(left, right, suffix, return_data_frame = FALSE) {
.mcols_overlaps_update <- function(
left, right, suffix, return_data_frame = FALSE
) {

left_names <- names(mcols(left))
right_names <- names(mcols(right))
common_name <- intersect(left_names, right_names)
lname_inx <- left_names %in% common_name
rname_inx <- right_names %in% common_name
if (any(lname_inx)) {
names(mcols(left))[lname_inx] <- paste0(left_names[lname_inx], suffix[1])
names(mcols(left))[lname_inx] <- paste0(
left_names[lname_inx], suffix[1]
)
}

if (any(rname_inx)) {
names(mcols(right))[rname_inx] <- paste0(right_names[rname_inx], suffix[2])
names(mcols(right))[rname_inx] <- paste0(
right_names[rname_inx], suffix[2]
)
}

if (!is.null(mcols(left))) {
Expand Down
3 changes: 2 additions & 1 deletion R/flank.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ NULL
flank_downstream <- function(x, width) UseMethod("flank_downstream")
#' @rdname plyranges-flank
#' @export
flank_downstream.Ranges <- function(x, width) plyranges::flank_downstream(x, width)
flank_downstream.Ranges <- function(x, width)
plyranges::flank_downstream(x, width)
#' @rdname plyranges-flank
#' @export
flank_downstream.PinnedGInteractions <- function(x, width) {
Expand Down
19 changes: 14 additions & 5 deletions R/ginteractions-construct.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@
#' pair2 chr1 50000 chr1 70000 + +
#' pair3 chr1 60000 chr2 10000 + +
#' pair4 chr1 30000 chr3 40000 + -",
#' col.names = c("pairID", "chr1", "pos1", "chr2", "pos2", "strand1", "strand2"))
#' col.names = c(
#' "pairID", "chr1", "pos1", "chr2", "pos2", "strand1", "strand2")
#' )
#' pairs |>
#' as_ginteractions(
#' seqnames1 = chr1, start1 = pos1, width1 = 1000,
Expand All @@ -84,7 +86,9 @@
#' chr1 1000 5000 chr1 3000 3800",
#' col.names = c("chr1", "start1", "end1", "chr2", "start2", "end2"))
#' df |>
#' as_ginteractions(seqnames1 = chr1, seqnames2 = chr2, strand1 = '+', strand2 = '-')
#' as_ginteractions(
#' seqnames1 = chr1, seqnames2 = chr2, strand1 = '+', strand2 = '-'
#' )
#'
#' data.frame(type = "cis", count = 3) |>
#' as_ginteractions(
Expand Down Expand Up @@ -150,7 +154,9 @@ as_ginteractions.data.frame <- function(
# Look for end*/width* fields
for (name in c('end1', 'end2')) {
if (!(any(name %in% c(names(rd), names(.data))))) {
if (!(any(gsub("end", "width", name) %in% c(names(rd), names(.data))))) {
if (!(any(
gsub("end", "width", name) %in% c(names(rd), names(.data))
))) {
stop(
"Please provide end/width information.",
call. = FALSE
Expand Down Expand Up @@ -184,15 +190,18 @@ as_ginteractions.data.frame <- function(
gi
}

.gi_construct <- function(.data, rd, col_names, core_gi, starts.in.df.are.0based) {
.gi_construct <- function(
.data, rd, col_names, core_gi, starts.in.df.are.0based
) {

## Check that all required columns are found, either in .data or ...
match_cols_i <- names(core_gi) %in% col_names
match_quosures_i <- names(core_gi) %in% names(rd)
if (sum(c(match_cols_i, match_quosures_i)) < 8) {
stop("Unable to construct GInteractions from .data.
Specify the column name used for each required field:
seqnames1, start1, end/wdith1, strand1, seqnames2, start2, end/wdith2, strand2",
seqnames1, start1, end/wdith1, strand1,
seqnames2, start2, end/wdith2, strand2",
call. = FALSE)
}

Expand Down
4 changes: 3 additions & 1 deletion R/ginteractions-env.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ setMethod("as.env", "GInteractions", function(x, enclos, tform = identity) {
env <- S4Vectors::as.env(
x@delegate,
envir,
tform = function(col) unname(S4Vectors::splitAsList(col, x@group_indices))
tform = function(col) unname(
S4Vectors::splitAsList(col, x@group_indices)
)
)
rlang::new_data_mask(env, top = parent.env(env))
}
Loading

0 comments on commit 24c4ca2

Please sign in to comment.