[ensembl-dev] Registry->get_adaptor and magic strings

Andreas Kahari ak at ebi.ac.uk
Fri Nov 26 11:34:34 GMT 2010


On Fri, Nov 26, 2010 at 10:39:48AM +0000, Daniel Sobral wrote:
> Some people during a recent API course commented that
> Registry->get_adaptor() should return a warning or throw an error
> when invalid parameters are passed, instead of just returning undef.
> I also tend to agree with them.

Hi Daniel,

An undef return from get_adaptor() is a warning that the parameters were
not right.

Unless you're sure you are getting a valid adaptor, you can always check
this with defined() or, as someone else pointed out, by simply tagging
"|| die()" on to the get_adaptor() call.

> Also, is there an easy / recommended way of knowing all the valid
> adaptors I can get with the registry?

You could potentially use the get_all_DBAdaptors() method of the
registry to get all available database adaptors (one for each species,
for each type of database found by the registry) and then call
get_available_adaptors() on one of these to get a hash containing the
available adaptors.  This will return Core adaptors if the DBAdaptor is
a Core DBAdaptor, etc.  This method is usually called by code internal
to the API.

In fact, you don't even have to have a real database adaptor, you could
just call Bio::EnsEMBL::DBSQL::DBAdaptor::get_available_adaptors() to
get the hash of [Core] adaptors.  For the available Compara adaptors,
use Bio::EnsEMBL::Compara::DBSQL::DBAdaptor::get_available_adaptors()
(and analogous for Variation and Funcgen).

If you want the name of the adaptors, look at the keys of the returned
hash.  If you want the module names, look at the values.

How would you have known about this method?  You wouldn't, because
it is usually called from within the API and doesn't usually feature
prominently in user's code.  It is however there, and you may use it if
you wish.

> I think this goes back to the topic of Ensembl API 'magic strings'
> that I see sometimes mentioned in the dev mailing list.
> These should be minimized, or at least there should be obvious
> methods where we could find them.
> Maybe there is and I just don't know about it...

I don't think that the names of the adaptors are too magic and
counter-intuitive.  Please let us know what strings are not intuitive
enough and we'll see if we can make it better.  The only one I can
think of in the Core API is the DBEntry adaptor (it's not called Xref
adaptor), but then again, an xref is an entry in another database, a
database entry.

Cheers,
Andreas

> 
> Any opinion/help is most welcome.
> 
> Thanks,
> Daniel



-- 
Andreas Kähäri, Ensembl Software Developer
European Bioinformatics Institute (EMBL-EBI)
Wellcome Trust Genome Campus
Hinxton, Cambridge CB10 1SD, United Kingdom




More information about the Dev mailing list