[Bioc-devel] Identical methods in two packages
Hervé Pagès
hpages at fredhutch.org
Tue Sep 12 18:35:20 CEST 2017
Hi Laurent,
The 2 Ontology,character methods defined in AnnotationDbi and
rols do very different things. The 1st one expects a vector of
GO IDs and returns the GO sub-ontologies that they belong to:
> Ontology(c("GO:0000009", "GO:0000012", "GO:0000006"))
GO:0000009 GO:0000012 GO:0000006
"MF" "BP" "MF"
The 2nd one takes the name of an ontology and returns a
summary/description of it:
> Ontology("efo")
Ontology: Experimental Factor Ontology (efo)
The Experimental Factor Ontology (EFO) provides a systematic
description of many experimental variables available in EBI databases,
and for external projects such as the NHGRI GWAS catalogue. It combines
parts of several biological ontologies, such as anatomy, disease and
chemical compounds. The scope of EFO is to support the annotation,
analysis and visualization of data handled by many groups at the EBI
and as the core ontology for OpenTargets.org
Loaded: 2017-08-16 Updated: 2017-09-12 Version: 2.87
20063 terms 297 properties 0 individuals
So the problem here is that even though now we have a single Ontology
generic in BiocGenerics for the 2 methods, we haven't really talked
about semantics i.e. what Ontology() is actually supposed to do. Having
a generic without some sort of contract that methods are supposed to
honor is like having a generic called doSomething() and have people
start writing a bunch of methods for it ;-)
The right thing to do here would be to use 2 different generics with
2 different names e.g. Ontology() in AnnotationDbi and ontologySummary()
in rols. Or GOontology() in AnnotationDbi and Ontology() in rols.
If we want to keep the current situation and make it work properly, we
could implement the following hack: have rols depend on AnnotationDbi
and make the method in rols work on GO ids. The code would just need
to detect whether the strings in the supplied character vector start
with the "GO:" prefix and delegate to the code in AnnotationDbi (this
means that rols would need to be able to call that code so the body
of the AnnotationDbi method would need to be moved to an helper
function). An ugly hack though!
What do you want to do?
H.
On 09/03/2017 07:59 AM, Laurent Gatto wrote:
>
> Dear all,
>
> This is a follow up to a previous email regarding the Ontology generic
> function, that is now in the BiocGenerics package. It seems that my
> problem was not only that both rols and AnnotationDbi defined the same
> generic, but they also both defined Ontology,character.
>
>> library("rols")
>
> This is 'rols' version 2.5.2
>
>> Ontology("go")
> Ontology: Gene Ontology (go)
> An ontology for describing the function of genes and gene products
> Loaded: 2017-08-31 Updated: 2017-09-01 Version: 2017-08-30
> 49075 terms 67 properties 0 individuals
>> Ontology
> standardGeneric for "Ontology" defined from package "BiocGenerics"
>
> function (object)
> standardGeneric("Ontology")
> <environment:0x2da7cf0>
> Methods may be defined for arguments: object
> Use showMethods("Ontology") for currently available ones.
>> showMethods("Ontology")
> Function: Ontology (package BiocGenerics)
> object="character"
> object="Ontology"
>
>> getMethod("Ontology", "character")
> Method Definition:
>
> function (object)
> {
> url <- ontologyUrl(object)
> x <- GET(url)
> stop_for_status(x)
> cx <- content(x)
> makeOntology(cx)
> }
> <environment:namespace:rols>
>
> Signatures:
> object
> target "character"
> defined "character"
>
> Until now, everything works as expected. The trouble begins when loading
> AnnotationDbi.
>
>> suppressPackageStartupMessages(library("AnnotationDbi"))
>> showMethods("Ontology")
> Function: Ontology (package BiocGenerics)
> object="character"
> object="GOTerms"
> object="GOTermsAnnDbBimap"
> object="Ontology"
>
>> getMethod("Ontology", "character")
> Method Definition:
>
> function (object)
> .GOid2go_termField(object, "ontology")
> <environment:namespace:AnnotationDbi>
>
> Signatures:
> object
> target "character"
> defined "character"
>> Ontology("go")
> Loading required package: GO.db
>
> <NA>
> NA
>
> Ok, fair enough, these things happen. The issue is to recover
> Ontology,character from rols. If I unload AnnotationDbi's namespace (I
> also neet to unload GO.db, that got loaded automatically), there is no
> Ontology,character anymore.
>
>> unloadNamespace("GO.db")
>> unloadNamespace("AnnotationDbi")
>> showMethods("Ontology")
> Function: Ontology (package BiocGenerics)
> object="Ontology"
>
>> Ontology("go")
> Error in (function (classes, fdef, mtable) :
> unable to find an inherited method for function ‘Ontology’ for signature ‘"character"’
>> rols::Ontology("go")
> Error in (function (classes, fdef, mtable) :
> unable to find an inherited method for function ‘Ontology’ for signature ‘"character"’
>
>> getMethod("Ontology", "character")
> Error in getMethod("Ontology", "character") :
> no method found for function 'Ontology' and signature character
>> getMethod("Ontology", "character", where = "package:rols")
> Method Definition:
>
> function (object)
> {
> url <- ontologyUrl(object)
> x <- GET(url)
> stop_for_status(x)
> cx <- content(x)
> makeOntology(cx)
> }
> <environment:namespace:rols>
>
> Signatures:
> object
> target "character"
> defined "character"
>
>
> It is really the expected behaviour? How could I recover rols'
> Ontology,character?
>
> Thank you in advance.
>
> Best wishes,
>
> Laurent
>
--
Hervé Pagès
Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024
E-mail: hpages at fredhutch.org
Phone: (206) 667-5791
Fax: (206) 667-1319
More information about the Bioc-devel
mailing list