The REST API is great but only supports the current version of Ensembl -- I should've said I'm working with IDs from 2011 (now edited my question to reflect that).
Is there a PyCogent (or more generally, Python) equivalent of get_species_and_object_type() from the Ensembl Perl API? I would like to fetch sequences for Ensembl IDs where I don't know what species a given ID comes from. As far as I can see, querying with cogent.db.ensembl requires creating a Genome object for a specific organism, and the Compara instances are also accessed as compara.SpeciesName. Is there a species-agnostic way of performing queries?
I tried using the REST API but it only supports the current release of ensembl whereas the IDs I'm dealing with are from a past release.
2 answers
You may want to take a look to REST http://beta.rest.ensembl.org/
You will find it much easier than PyCogent and works with python too.
This Perl script does exactly what you need it to:
use strict;
use warnings;
use Bio::EnsEMBL::Registry;
my $reg = "Bio::EnsEMBL::Registry";
$reg->load_registry_from_db(
-host => 'ensembldb.ensembl.org',
-user => 'anonymous',
);
my $stable_id = 'ENST00000326632';
my ( $species, $object_type, $db_type ) = $reg->get_species_and_object_type($stable_id);
my $adaptor = $reg->get_adaptor( $species, $db_type, $object_type );
my $object = $adaptor->fetch_by_stable_id($stable_id);
print ">", $stable_id, "\n", $object->seq->seq, "\n\n";
I'm really not sure why you're trying to make things more complicated for yourself by avoiding Perl.
It would maybe make sense to use Perl if this was the only kind of analysis I was doing. As it is, the rest of my code is in Python and my environment is not set up for Perl (no BioPerl, no Ensembl API etc.)
Log in to answer this question.