[Bioc-devel] Import BSgenome class without attaching BiocGenerics (and others)?

Bhagwat, Aditya Ad|ty@@Bh@gw@t @end|ng |rom mp|-bn@mpg@de
Fri Sep 6 19:07:52 CEST 2019


Thanks Kasper and Michael.

The importClassesFrom  sounds like something that would allow an attachment-free S4 class import, will check them out.
Michael, the current auto-attach is causing 66 namespace clashes<https://support.bioconductor.org/p/124442/> – not feeling very comfortable about that, so trying to avoid them.

I also think there’s something about S4 coercion that I don’t yet fully understand.
For instance: the S4Vectors package has three different versions of a S4Vectors::Vector -> data.frame coercer. Why? Any useful pointers?

setAs("Vector", "data.frame", function(from) as.data.frame(from))

as.data.frame.Vector <- function(x, row.names=NULL, optional=FALSE, ...) {
    as.data.frame(x, row.names=NULL, optional=optional, ...)
}

setMethod("as.data.frame", "Vector",
          function(x, row.names=NULL, optional=FALSE, ...)
          {
              x <- as.vector(x)
              as.data.frame(x, row.names=row.names, optional=optional, ...)
          })



From: Kasper Daniel Hansen <kasperdanielhansen using gmail.com>
Sent: Freitag, 6. September 2019 17:49
To: Michael Lawrence <lawrence.michael using gene.com>
Cc: Bhagwat, Aditya <Aditya.Bhagwat using mpi-bn.mpg.de>; bioc-devel using r-project.org
Subject: Re: [Bioc-devel] Import BSgenome class without attaching BiocGenerics (and others)?

There are
  importMethodsFrom(PACKAGE, NAME_OF_METHODS)
  importClassesFrom(PACKAGE, NAME_OF_METHODS)
to help with selective importing S4 methods/classes.  See section 1.5.6 of WRE.

On Fri, Sep 6, 2019 at 9:24 AM Michael Lawrence via Bioc-devel <bioc-devel using r-project.org<mailto:bioc-devel using r-project.org>> wrote:
It sounds like you are trying to defer loading of namespaces in order
to save time when they are unnecessary? That's probably going to end
up a losing battle.

On Fri, Sep 6, 2019 at 5:47 AM Bhagwat, Aditya
<Aditya.Bhagwat using mpi-bn.mpg.de<mailto:Aditya.Bhagwat using mpi-bn.mpg.de>> wrote:
>
> Thank you Michael,
>
> Appreciate your time for helping me fill the gaps in my understanding of the S4 flow :-).
>
> It all started when I defined (in my multicrispr package) the S4 coercer :
> methods::setAs( "BSgenome",
>
> "GRanges",
> function(from) as(GenomeInfoDb::seqinfo(from), "GRanges")
>
> When building, I noticed the message
> in method for 'coerce' with signature '"BSgenome","GRanges"': no definition for class "BSgenome"
>
> So, I added
> BSgenome <- methods::getClassDef('BSgenome', package = 'BSgenome')
>
> That loads all these dependencies.
> From your answer, I understand that there is currently no alternative to loading all these dependencies.
> I guess because these dependencies are needed to provide for all required S4 methods for the BSgenome class, am I right?
>
> Is there a way to define a methods::setAs without loading the class definition?
>
> Aditya
>
>
>
>
> ________________________________________
> From: Michael Lawrence [lawrence.michael using gene.com<mailto:lawrence.michael using gene.com>]
> Sent: Friday, September 06, 2019 1:09 PM
> To: Bhagwat, Aditya
> Cc: bioc-devel using r-project.org<mailto:bioc-devel using r-project.org>
> Subject: Re: [Bioc-devel] Import BSgenome class without attaching BiocGenerics (and others)?
>
> The way to keep a "clean namespace" is to selectively import symbols
> into your namespace, not to import _nothing_ into your namespace.
> Otherwise, your code will fill with namespace qualifications that
> distract from what is more important to communicate: the intent of the
> code. And no, there's no way to define method signatures using
> anything other than simple class names.
>
> It would be interesting to explore alternative ways of specifying
> method signatures. One way would be if every package exported a "class
> reference" (class name with package attribute, at least) for each of
> its classes. Those could be treated like any other exported object,
> and referenced via namespace qualification. It would require major
> changes to the methods package but that should probably happen anyway
> to support disambiguation when two packages define a class of the same
> name. It would be nice to get away from the exportClasses() and
> importClasses() stuff. File that under the "rainy year" category.
>
> Michael
>
> On Fri, Sep 6, 2019 at 3:39 AM Bhagwat, Aditya
> <Aditya.Bhagwat using mpi-bn.mpg.de<mailto:Aditya.Bhagwat using mpi-bn.mpg.de>> wrote:
> >
> > Dear Bioc devel,
> >
> > Is it possible to import the BSgenome class without attaching BiocGenerics (to keep a clean namespace during the development of multicrispr<https://gitlab.gwdg.de/loosolab/software/multicrispr>).
> >
> > BSgenome <- methods::getClassDef('BSgenome', package = 'BSgenome')
> >
> > (Posted earlier on BioC support<https://support.bioconductor.org/p/124442/> and redirected here following Martin's suggestion)
> >
> > Thankyou :-)
> >
> > Aditya
> >
> > [[alternative HTML version deleted]]
> >
> > _______________________________________________
> > Bioc-devel using r-project.org<mailto:Bioc-devel using r-project.org> mailing list
> > https://stat.ethz.ch/mailman/listinfo/bioc-devel
>
>
>
> --
> Michael Lawrence
> Scientist, Bioinformatics and Computational Biology
> Genentech, A Member of the Roche Group
> Office +1 (650) 225-7760
> michafla using gene.com<mailto:michafla using gene.com>
>
> Join Genentech on LinkedIn | Twitter | Facebook | Instagram | YouTube



--
Michael Lawrence
Scientist, Bioinformatics and Computational Biology
Genentech, A Member of the Roche Group
Office +1 (650) 225-7760
michafla using gene.com<mailto:michafla using gene.com>

Join Genentech on LinkedIn | Twitter | Facebook | Instagram | YouTube

_______________________________________________
Bioc-devel using r-project.org<mailto:Bioc-devel using r-project.org> mailing list
https://stat.ethz.ch/mailman/listinfo/bioc-devel


--
Best,
Kasper

	[[alternative HTML version deleted]]



More information about the Bioc-devel mailing list