[BioC] Using annotation maps as environments in packages

Antti Honkela antti.honkela at tkk.fi
Thu Mar 4 20:27:02 CET 2010

Hi Marc,

I think there is something deeper going on in that the overloaded  
"get" generic function for the ProbeAnnDbBimap class does not work the  
way one would assume when called from a function inside a package.  
Unfortunately my understanding of intricacies of R packages,  
namespaces and generic functions does not help any further.

The suggested getAnnMap() does not solve that, as changing the  
function (in the package) to
getAnnotation <- function(gene, map, chip) {

   env <- getAnnMap(map, chip)
   return (get(gene, env=env))

leads to the same result:
 > getAnnotation("1419728_at", "SYMBOL", "mouse430a2")
Loading required package: annotate
Loading required package: AnnotationDbi
Loading required package: Biobase

Welcome to Bioconductor

   Vignettes contain introductory material. To view, type
   'openVignette()'. To cite Bioconductor, see
   'citation("Biobase")' and for packages 'citation(pkgname)'.

Loading required package: org.Mm.eg.db
Loading required package: DBI
SYMBOL map for chip mouse430a2 (object of class "ProbeAnnDbBimap")
Error in get(gene, env = env) : invalid 'envir' argument

Note the output of show(env), i.e. we are getting the correct map but  
the get() call still fails.

At the same time doing the same on the command line works:
 > map <- getAnnMap("SYMBOL", "mouse430a2")
 > map
SYMBOL map for chip mouse430a2 (object of class "ProbeAnnDbBimap")
 > get("1419728_at", map)
[1] "Cxcl5"


On Mar 4, 2010, at 18:42 , Marc Carlson wrote:

> Hi Antti,
> You didn't give a lot of detail, but this message probably means that
> you did not load the Annotation package before calling (in the 3rd
> case). You can put a call to require() in your function to make the
> specific annotation package be loaded, but this is probably NOT the  
> best
> way to handle that.  It is probably a much better idea at this point  
> for
> you to look at the getAnnMap() function from the annotate package.
> library(annotate)
> ?getAnnMap
> As you read the manual page, you will see that getAnnMap is used to
> return the map (what you are calling the envir) so that you can do  
> this
> sort of thing in a more generic way.  That is, you specify the package
> name and the mapping you want, and getAnnMap will try to load any  
> needed
> packages etc. to make sure that its there for you.
> Hope this helps,
>  Marc
> On 03/04/2010 10:18 AM, Antti Honkela wrote:
>> Hi all,
>> I have a weird problem when I try to write a function in a package
>> that would use annotation maps (e.g. mouse430a2SYMBOL) as an
>> environment that the function works on its own breaks when moved into
>> a package.
>> The maps can usually be used as environments without problems and the
>> following works fine:
>>> library(mouse430a2.db)
>>> get("1419728_at", env=mouse430a2SYMBOL)
>> The same is true if I define an own function to access the map, and
>> this runs without problems:
>>> getAnnotation <- function(gene, env) { return (get(gene, env=env)) }
>>> getAnnotation("1419728_at", env=mouse430a2SYMBOL)
>> However, if I move the same function definition to an independent
>> package, the same call results in an error:
>>> getAnnotation("1419728_at", env=mouse430a2SYMBOL)
>> Error in get(gene, env = env) : invalid 'envir' argument
>> Any ideas how to fix or circumvent this?
>> (Note that in the sessionInfo below, testpkg is a minimal package  
>> only
>> containing the above function definition.)
>> Best regards,
>> Antti
>> ---------------------------------------------------------
>>> sessionInfo()
>> R version 2.10.1 (2009-12-14)
>> i386-apple-darwin9.8.0
>> locale:
>> [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8
>> attached base packages:
>> [1] stats     graphics  grDevices utils     datasets  methods   base
>> other attached packages:
>> [1] mouse430a2.db_2.3.5 org.Mm.eg.db_2.3.6  RSQLite_0.7-3
>> DBI_0.2-4           AnnotationDbi_1.8.1 Biobase_2.6.0
>> [7] testpkg_0.0-1
>> loaded via a namespace (and not attached):
>> [1] affy_1.24.2          affyio_1.14.0        preprocessCore_1.8.0
> _______________________________________________
> Bioconductor mailing list
> Bioconductor at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/bioconductor
> Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor

Antti Honkela
Antti.Honkela at tkk.fi   -   http://www.cis.hut.fi/ahonkela/

More information about the Bioconductor mailing list