Question: extending GenomicRanges::reduce warning, why ?
gravatar for hauken_heyken
21 months ago by
hauken_heyken60 wrote:

Ok, so I want my own definition of reduce, that calls GenomicRanges::reduce() if keep.names = F, the extra argument I want.

I can not find the original setGeneric for reduce, I guess it's auto-created ?

my generic is:

setGeneric("reduce", function(x, ...) standardGeneric("reduce")) # i extend with ...

It works, and all is good, but when doing check on package I get warning:

Warning: multiple methods tables found for ‘reduce’

How to fix this ?


My functions are:

#' Generic for reduce in ORFik
#' @param x a GRangesList
#' @param ... see \code{\link[GenomicRanges]{reduce}}
#' @importFrom methods setGeneric
#' @export
setGeneric("reduce", function(x, ...) standardGeneric("reduce"))

#' Reduce GRanges / GRangesList
#' Extends function \code{\link[GenomicRanges]{reduce}}
#' by trying to keep names and meta columns if it is a
#' GRangesList. If keep.names == F, it's just the normal
#' GenomicRanges::reduce.
#' Only tested for orfik, might not work for other naming conventions.
#' @param x a \code{\link[GenomicRanges]{GRangesList}} or GRanges object
#' @param drop.empty.ranges (FALSE) if a group is empty (width 0), delete it.
#' @param min.gapwidth (1L) how long gap can it be to say they belong together
#' @param with.revmap (FALSE) return info on which mapped to which
#' @param with.inframe.attrib (FALSE) For internal use.
#' @param ignore.strand (FALSE), can different strands be reduced together.
#' @param keep.names (FALSE) keep the names and meta columns of the GRangesList
#' @importFrom methods setMethod
#' @export
#' @return A reduced GRangesList
setMethod("reduce", signature = signature(x = "GRangesList"),
                    function(x, drop.empty.ranges = FALSE,
                             min.gapwidth = 1L, with.revmap = FALSE,
                             with.inframe.attrib = FALSE,
                             ignore.strand = FALSE , keep.names = FALSE){  #### <- here keep.names is defined, my variable.

  if (keep.names) { # return with names

    gr <- unlist(GenomicRanges::reduce(x), use.names = TRUE)
    if (length(gr) == 0) return(GRangesList())

    return(matchNaming(gr, x))
  } else { # return original
    return(GenomicRanges::reduce(x, drop.empty.ranges, min.gapwidth,
           with.revmap, with.inframe.attrib,
ADD COMMENTlink modified 20 months ago by Martin Morgan ♦♦ 24k • written 21 months ago by hauken_heyken60
Answer: extending GenomicRanges::reduce warning, why ?
gravatar for Martin Morgan
20 months ago by
Martin Morgan ♦♦ 24k
United States
Martin Morgan ♦♦ 24k wrote:

Probably a better question for the bioc-devel mailing list.

I have

standardGeneric for "reduce" defined from package "IRanges"

function (x, drop.empty.ranges = FALSE, ...) 
<bytecode: 0xb07d538>
<environment: 0xb04f978>
Methods may be defined for arguments: x
Use  showMethods("reduce")  for currently available ones.

which indicates that the generic is defined in the IRanges package with a particular signature. If one had a new class, one could define the method by first using importFrom(IRanges, reduce) and then setMethod(reduce, "MyClass", function(x, drop.empty.ranges = FALSE, ...) {}).

It is not a good idea to redefine a method. Think of the generic as offering a contract, and a method as implementing the contract. Either the method implements the contract and shouldn't be changed, or the method doesn't implement the contract, and should be fixed. So either live with the contract, or report a bug or feature request to the author of the method.

If you'd like a different contract, create a different generic.

ADD COMMENTlink written 20 months ago by Martin Morgan ♦♦ 24k

Thanks for the help Martin, slowly learning the way of R.


I renamed the function to reduce_keep_attr

It tries to keep the meta columns and naming if it makes sense after reduction.

ADD REPLYlink modified 20 months ago • written 20 months ago by hauken_heyken60
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 16.09
Traffic: 382 users visited in the last hour