Question: Defining BSgenome -> GRanges S4 coercer without package attaching
0
gravatar for Aditya
11 days ago by
Aditya120
Germany
Aditya120 wrote:

Defining an S4 coercer in my multicrispr package

methods::setAs( "BSgenome", "GRanges", 
            function(from)  from %>% 
                            GenomeInfoDb::seqinfo() %>% 
                            as('GRanges'))

gives this byte compile message:

** byte-compile and prepare package for lazy loading
   in method for 'coerce' with signature '"BSgenome","GRanges"': no definition for class "BSgenome"

Importing the BSgenome class in advance avoids these messages, but attaches many dependency packages:

BSgenome <- methods::getClassDef('BSgenome', package = 'BSgenome')

    Loading required package: BSgenome
    Loading required package: BiocGenerics
    Loading required package: parallel
    Attaching package: ‘BiocGenerics’
        The following objects are masked from ‘package:parallel’:
            clusterApply, clusterApplyLB, clusterCall, clusterEvalQ, clusterExport, 
            clusterMap, parApply, parCapply, parLapply, parLapplyLB, parRapply, 
            parSapply, parSapplyLB
        The following objects are masked from ‘package:stats’:
            IQR, mad, sd, var, xtabs
        The following objects are masked from ‘package:base’:
            anyDuplicated, append, as.data.frame, basename, cbind, colnames, 
            dirname, do.call, duplicated, eval, evalq, Filter, Find, get, grep, grepl, 
            intersect, is.unsorted, lapply, Map, mapply, match, mget, order, paste, 
            pmax, pmax.int, pmin, pmin.int, Position, rank, rbind, Reduce, 
            rownames, sapply, setdiff, sort, table, tapply, union, unique, unsplit, 
            which, which.max, which.min

    Loading required package: S4Vectors
    Loading required package: stats4
    Attaching package: ‘S4Vectors’
        The following object is masked from ‘package:base’: expand.grid

    Loading required package: IRanges
    Attaching package: ‘IRanges’
        The following object is masked from ‘package:grDevices’: windows

    Loading required package: GenomeInfoDb
    Loading required package: GenomicRanges
    Loading required package: Biostrings
    Loading required package: XVector
    Attaching package: ‘Biostrings’
        The following object is masked from ‘package:base’: strsplit

    Loading required package: rtracklayer

Is there a way to define the S4 coercer without attaching these dependencies?

ADD COMMENTlink modified 7 days ago • written 11 days ago by Aditya120

Many of your questions are similar and I wonder if it would be better to state what your goal is in avoiding 'attaching' packages. Also, it seems like these are related to package development, and the answer for a package developer may well be different from the answer for a user. If these are related to package development, then it is better to ask on the bioc-devel mailing list.

ADD REPLYlink written 11 days ago by Martin Morgan ♦♦ 23k

Thank you Martin :-)

Updated this question to give its full context, and posted to bioc-devel.

ADD REPLYlink modified 10 days ago • written 11 days ago by Aditya120
Answer: Defining BSgenome -> GRanges S4 coercer without package attaching
0
gravatar for Aditya
7 days ago by
Aditya120
Germany
Aditya120 wrote:

The solution is to use the roxygen keyword @importClassesFrom in the function documentation (thankyou Daniel Kasper Hansen on bioc-devel)

#' Convert BSgenome into GRanges 
#' @param from BSgenome, e.g. BSgenome.Mmusculus.UCSC.mm10::Mmusculus
#' @examples 
#' require(magrittr)
#' bsgenome <- BSgenome.Mmusculus.UCSC.mm10::BSgenome.Mmusculus.UCSC.mm10 
#' as(bsgenome, 'GRanges')
#' @importClassesFrom BSgenome BSgenome
#' @export
methods::setAs("BSgenome", 
               "GRanges", 
               function(from)  as(GenomeInfoDb::seqinfo(from), 'GRanges')

From my recent communications with Herve Pages I have come to understand that these apparant namespace clashes are actually intentional promotions of base primitives and S3 generics to S4 generics. So, not something to worry about.

ADD COMMENTlink modified 5 days ago • written 7 days ago by Aditya120
Please log in to add an answer.

Help
Access

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