Fetching Ids With Unknown Species From Ensembl Using Python
2
1
Entering edit mode
10.7 years ago
jergosh ▴ 70

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.

ensembl python • 2.2k views
ADD COMMENT
1
Entering edit mode
10.7 years ago
Biojl ★ 1.7k

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.

ADD COMMENT
0
Entering edit mode

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).

ADD REPLY
0
Entering edit mode
10.7 years ago
Emily 23k

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.

ADD COMMENT
0
Entering edit mode

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.)

ADD REPLY

Login before adding your answer.

Traffic: 2367 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6