[ensembl-dev] stable_id by gene name

mag mr6 at ebi.ac.uk
Thu Jun 29 09:08:35 BST 2017


Hi Mahmood,

To access all genes in a species, you can use directly the GeneAdaptor.
This will allow you to loop through all the genes without having to 
retrieve the chromosomes first.

Additionally, there is a method called fetch_all_by_external_name
http://www.ensembl.org/info/docs/Doxygen/core-api/classBio_1_1EnsEMBL_1_1DBSQL_1_1GeneAdaptor.html#a940d6dc7e9273ad373a23eb563a455e6
which allows you to retrieve all Gene objects for a gene symbol.

An example script would look like:
$registry->load_registry_from_db(
   -host => 'ensembldb.ensembl.org',
   -user => 'anonymous',
   -port => 3337
);
my $gene_adaptor = $registry->get_adaptor('human', 'core', 'Gene');
my @genes = @{ $gene_adaptor->fetch_all() };
my @brca_genes = @{ $gene_adaptor->fetch_all_by_external_name('BRCA2') };
while (my $brca_gene = shift @brca_genes) {
   print ">" . $brca_gene->stable_id . " " . 
$brca_gene->display_xref->display_id . "\n";
   print $brca_gene->seq . "\n";
}

I would recommend looking through our API course to get more familiar 
with it.
We have slides from our in-person workshops
https://github.com/Ensembl/ensembl-presentation/tree/master/API/Core
a tutorial
http://www.ensembl.org/info/docs/api/core/core_tutorial.html
and videos
http://www.ebi.ac.uk/training/online/course/ensembl-filmed-api-workshop


Hope that helps,
Magali

On 28/06/2017 19:36, Mahmood Naderan wrote:
> Hi,
> Is exonerate the only tool to get the stable_id by the gene name? I 
> was wondering if an ensemble perl api does this job.
> Also, I didn't see an api to access the database by the gene name. It 
> seems that I have to get the chromosome first and then iterate over 
> all genes in it.
>
> Regards,
> Mahmood
>
>
>
>
> _______________________________________________
> Dev mailing list    Dev at ensembl.org
> Posting guidelines and subscribe/unsubscribe info: http://lists.ensembl.org/mailman/listinfo/dev
> Ensembl Blog: http://www.ensembl.info/

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.ensembl.org/pipermail/dev_ensembl.org/attachments/20170629/536ac8e0/attachment.html>


More information about the Dev mailing list