Skip to content

Instantly share code, notes, and snippets.

@avrilcoghlan
Created December 18, 2013 11:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avrilcoghlan/8020815 to your computer and use it in GitHub Desktop.
Save avrilcoghlan/8020815 to your computer and use it in GitHub Desktop.
Perl script that uses the Ensembl Compara API to get all the homologues for the human gene ENSG00000229314
#!/usr/bin/env perl
# Get all the homologues for the human gene ENSG00000229314
# Note: get a warning about a variable declaration in the Compara API when this script is run.
use strict;
use warnings;
use Bio::EnsEMBL::Registry;
my $registry = 'Bio::EnsEMBL::Registry';
$registry->load_registry_from_db(
-host => 'ensembldb.ensembl.org',
-user => 'anonymous'
);
my $gma = $registry->get_adaptor('multi', 'compara', 'GeneMember');
my $ha = $registry->get_adaptor('multi', 'compara', 'Homology');
my $gene_member = $gma->fetch_by_source_stable_id("ENSEMBLGENE", "ENSG00000229314"); # Get the 'GeneMember' object for the gene ENSG00000238344
# Get all homologies for gene ENSG00000238344
my @homologies = @{ $ha->fetch_all_by_Member($gene_member)};
foreach my $homology (@homologies){
my $desc = $homology->description(); # ortholog_many2many or ortholog_one2one or within_species_paralog
my $taxonomy_level = $homology->taxonomy_level(); # eg. 'Chordata', 'Euteleostomi', 'Homo sapiens'
print "desc=$desc taxonomy_level=$taxonomy_level\n";
# Get all the gene members of this homology relationship:
my @homologue_genes = @{$homology->get_all_GeneMembers};
foreach my $homologue_gene (@homologue_genes) {
my $source_name = $homologue_gene->source_name(); # eg. ENSEMBLGENE
my $stable_id = $homologue_gene->stable_id();
my $genome = $homologue_gene->genome_db()->name(); # eg. homo_sapiens
print "___homologue id=$stable_id source=$source_name genome=$genome\n";
}
}
# One-to-many or many-to-many homologies are given as pairs of homologues, eg.
# desc=ortholog_one2many taxonomy_level=Euarchontoglires
# ___homologue id=ENSG00000229314 source=ENSEMBLGENE genome=homo_sapiens
# ___homologue id=ENSOCUG00000004625 source=ENSEMBLGENE genome=oryctolagus_cuniculus
# In this case this oryctolagus_cuniculus gene has ENSG00000229314 as its ortholog, but also has
# a second human ortholog (not given by this script, as ENSG00000229314 is the focus of this script).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment