<p>While I wouldn't consider this as the best answer or solution - I decided to use Ensembl REST api to extract the coordinates of alignment blocks. </p>

<p>The quick fix - in python looks like this: </p>

<pre><code>#This is the main function which uses Ensembl REST API to access the Enesembl Compara database 
#And retrive the alignment blocks which correspond to the MM10 standard. 
#The function accepts chromosome, start and array and returns the alignment blocks
#reported by the API. Since the blocks can be on different chromosomes/and/or/contigs, it 
#returns the whole output in form of dataframe - containing chromosome, start and stop of the
#alignment blocks corresponding to input and all the other alignment blocks corresponding the 
#16 mice species, if available. 
#!!!!!!!----------Caution start----------!!!!!!!
#The API is a bit buggy, so it is advised not to request for specific species.
#!!!!!!!-----------Caution end-----------!!!!!!!
def liftover(chrom, start, end):
    mmStart, mmEnd, mmchr = [], [], []
    caStart, caEnd, cachr = [], [], []
    #ryStart, ryEnd, rychr = [], [], []
    server = "https://rest.ensembl.org"
    ext = "/alignment/region/mus_musculus/" + str(chrom) + ":" + str(start) + "-" + str(end) + ":1?species_set_group=murinae;method=CACTUS_HAL;content-type=application/json"
    headers={ "Content-Type" : "application/json"}
    r = requests.get(server+ext, headers={ "Content-Type" : "application/json"})
    if(r.ok):
        json_string = json.dumps(r.json())
        jData = json.loads(r.content)
        results = r.json()
        print("The response contains {0} properties".format(len(jData)))
        print("\n")
    else:
        r.raise_for_status()

    for element in jData:
        element.pop('tree', None)

    for element in jData:
        for key, value in element.items():
            for z in value:
                if (z["species"]=="mus_musculus"):
                    mmStart.append(z["start"])
                    mmEnd.append(z["end"])
                    mmchr.append(z["seq_region"])
                if (z["species"]=="mus_musculus_casteij"):
                    caStart.append(z["start"])
                    caEnd.append(z["end"])
                    cachr.append(z["seq_region"])
    if (len(mmStart) != len(caStart)):
        print("Length mismatch between species blocks - proceed with caution!")
    return [min(mmStart), max(mmEnd), min(caStart), max(caEnd), len(mmStart)]
</code></pre>

<p>Again, it depends on how alignment blocks are reported - and requires further digging to resolve which mm10 alignment block resembles CAST alignment block.</p>

CC BY-SA 4.0
2018-12-11T14:24:13.523Z
2018-12-11T14:24:13.523Z
Siddharth
<p>I'm trying to convert coordinates between the reference mouse genome and CAST/EiJ mice strain. Since Ensebml already has alignment available in the browser, I decided to use Ensembl perl API to lift over the alignment for the regions I'm interested in. The problem is that it doesn't seem to be working. I'm getting following error message: </p>

<pre><code>-------------------- EXCEPTION --------------------
MSG: The database do not contain any CACTUS_HAL data for Bio::EnsEMBL::Compara::GenomeDB=HASH(0x557db0d661e8)!
STACK toplevel coord.pl:42
Date (localtime)    = Mon Oct 15 07:42:17 2018
Ensembl API version = 94
---------------------------------------------------
</code></pre>

<p>which I assume means that I'm either searching for the wrong alignment record or the alignment itself is not available. Following is the perl script which I modified from the Ensembl Compara API <a href="https://www.ensembl.org/info/docs/api/compara/compara_tutorial.html" rel="nofollow noreferrer">tutorial</a>:</p>

<pre><code>use strict;
use Bio::EnsEMBL::Registry;
use Bio::EnsEMBL::Utils::Exception qw(throw);
use Bio::AlignIO;
use Getopt::Long;

my <span class="math-container">$species = "murinae";
my $</span>targetSpecies = "mus_musculus_casteij";
my <span class="math-container">$alignment_type = "CACTUS_HAL";
my $</span>output_file = undef;
my <span class="math-container">$coord_system = "chromosome";
my $</span>seq_region = "14";
my <span class="math-container">$seq_region_start = 5000000;
my $</span>seq_region_end = 5010000;
my <span class="math-container">$output_format = "clustalw";
my $</span>genome_dbs;

use Bio::EnsEMBL::Registry;
Bio::EnsEMBL::Registry-&gt;load_registry_from_db(
    -host =&gt; 'ensembldb.ensembl.org',
    -user =&gt; 'anonymous',
    -port =&gt; 5306);

my $genome_db_adaptor = Bio::EnsEMBL::Registry-&gt;get_adaptor(
    'Multi', 'compara', 'GenomeDB');

throw("Cannot connect to Compara") if (!$genome_db_adaptor);

my <span class="math-container">$this_genome_db = $</span>genome_db_adaptor-&gt;fetch_by_name_assembly(<span class="math-container">$species);
my $</span>target_genome_db = <span class="math-container">$genome_db_adaptor-&gt;fetch_by_name_assembly($</span>targetSpecies);
push(@<span class="math-container">$genome_dbs, $</span>this_genome_db);
push(@<span class="math-container">$genome_dbs, $</span>target_genome_db);

my $method_link_species_set_adaptor = Bio::EnsEMBL::Registry-&gt;get_adaptor(
    'Multi', 'compara', 'MethodLinkSpeciesSet');

my <span class="math-container">$method_link_species_set =
$</span>method_link_species_set_adaptor-&gt;fetch_by_method_link_type_GenomeDBs(
      <span class="math-container">$alignment_type, 
  $</span>genome_dbs);

throw("The database do not contain any <span class="math-container">$alignment_type data for $</span>target_genome_db!")
    if (!$method_link_species_set);


my <span class="math-container">$slice_adaptor = Bio::EnsEMBL::Registry-&gt;get_adaptor($</span>species, 'core', 'Slice');

throw("Registry configuration file has no data for connecting to &lt;<span class="math-container">$species&gt;")
if (!$</span>slice_adaptor);

my <span class="math-container">$query_slice = $</span>slice_adaptor-&gt;fetch_by_region('toplevel', <span class="math-container">$seq_region, $</span>seq_region_start, $seq_region_end);

throw("No Slice can be created with coordinates <span class="math-container">$seq_region:$</span>seq_region_start-".
    "<span class="math-container">$seq_region_end") if (!$</span>query_slice);

# Fetching all the GenomicAlignBlock corresponding to this Slice:
my $genomic_align_block_adaptor = Bio::EnsEMBL::Registry-&gt;get_adaptor(
    'Multi', 'compara', 'GenomicAlignBlock');

my <span class="math-container">$genomic_align_blocks =
$</span>genomic_align_block_adaptor-&gt;fetch_all_by_MethodLinkSpeciesSet_Slice(
      <span class="math-container">$method_link_species_set, 
  $</span>query_slice);

my $all_aligns;

# Get a Bio::SimpleAlign object from every GenomicAlignBlock
foreach my <span class="math-container">$this_genomic_align_block (@$</span>genomic_align_blocks) {
    my <span class="math-container">$simple_align = $</span>this_genomic_align_block-&gt;get_SimpleAlign;
    push(@<span class="math-container">$all_aligns, $</span>simple_align);
}

# print all the genomic alignments using a Bio::AlignIO object
my <span class="math-container">$alignIO = Bio::AlignIO-&gt;newFh(
-interleaved =&gt; 0,
-fh =&gt; \*STDOUT,
-format =&gt; $</span>output_format,
    -idlength =&gt; 10
);

foreach my <span class="math-container">$this_align (@$</span>all_aligns) {
    print <span class="math-container">$alignIO $</span>this_align;
}

exit; 
</code></pre>

<p>Any pointers on what I'm doing wrong ?</p>

CC BY-SA 4.0
2018-10-16T07:20:23.517Z
Perl is a language I haven't heard in a long time :D It seems like the GenomeDB is passing an argument that might be wrong. Are you using the latest bioperl/perl?
llrs
<ensembl><perl><api>
Error while performing "lift-over" of genomic coordinates between two species using Ensembl Compara API
# Error while performing "lift-over" of genomic coordinates between two species using Ensembl Compara API

(Asked by: username_0 on 2018-10-15)

I'm trying to convert coordinates between the reference mouse genome and CAST/EiJ mice strain. Since Ensebml already has alignment available in the browser, I decided to use Ensembl perl API to lift over the alignment for the regions I'm interested in. The problem is that it doesn't seem to be working. I'm getting following error message: 
-------------------- EXCEPTION --------------------
MSG: The database do not contain any CACTUS_HAL data for Bio::EnsEMBL::Compara::GenomeDB=HASH(0x557db0d661e8)!
STACK toplevel coord.pl:42
Date (localtime)    = Mon Oct 15 07:42:17 2018
Ensembl API version = 94
---------------------------------------------------

which I assume means that I'm either searching for the wrong alignment record or the alignment itself is not available. Following is the perl script which I modified from the Ensembl Compara API tutorial:
use strict;
use Bio::EnsEMBL::Registry;
use Bio::EnsEMBL::Utils::Exception qw(throw);
use Bio::AlignIO;
use Getopt::Long;

my $species = "murinae";
my $targetSpecies = "mus_musculus_casteij";
my $alignment_type = "CACTUS_HAL";
my $output_file = undef;
my $coord_system = "chromosome";
my $seq_region = "14";
my $seq_region_start = 5000000;
my $seq_region_end = 5010000;
my $output_format = "clustalw";
my $genome_dbs;

use Bio::EnsEMBL::Registry;
Bio::EnsEMBL::Registry->load_registry_from_db(
    -host => 'ensembldb.ensembl.org',
    -user => 'anonymous',
    -port => 5306);

my $genome_db_adaptor = Bio::EnsEMBL::Registry->get_adaptor(
    'Multi', 'compara', 'GenomeDB');

throw("Cannot connect to Compara") if (!$genome_db_adaptor);

my $this_genome_db = $genome_db_adaptor->fetch_by_name_assembly($species);
my $target_genome_db = $genome_db_adaptor->fetch_by_name_assembly($targetSpecies);
push(@$genome_dbs, $this_genome_db);
push(@$genome_dbs, $target_genome_db);

my $method_link_species_set_adaptor = Bio::EnsEMBL::Registry->get_adaptor(
    'Multi', 'compara', 'MethodLinkSpeciesSet');

my $method_link_species_set =
$method_link_species_set_adaptor->fetch_by_method_link_type_GenomeDBs(
      $alignment_type, 
  $genome_dbs);

throw("The database do not contain any $alignment_type data for $target_genome_db!")
    if (!$method_link_species_set);


my $slice_adaptor = Bio::EnsEMBL::Registry->get_adaptor($species, 'core', 'Slice');

throw("Registry configuration file has no data for connecting to <$species>")
if (!$slice_adaptor);

my $query_slice = $slice_adaptor->fetch_by_region('toplevel', $seq_region, $seq_region_start, $seq_region_end);

throw("No Slice can be created with coordinates $seq_region:$seq_region_start-".
    "$seq_region_end") if (!$query_slice);

# Fetching all the GenomicAlignBlock corresponding to this Slice:
my $genomic_align_block_adaptor = Bio::EnsEMBL::Registry->get_adaptor(
    'Multi', 'compara', 'GenomicAlignBlock');

my $genomic_align_blocks =
$genomic_align_block_adaptor->fetch_all_by_MethodLinkSpeciesSet_Slice(
      $method_link_species_set, 
  $query_slice);

my $all_aligns;

# Get a Bio::SimpleAlign object from every GenomicAlignBlock
foreach my $this_genomic_align_block (@$genomic_align_blocks) {
    my $simple_align = $this_genomic_align_block->get_SimpleAlign;
    push(@$all_aligns, $simple_align);
}

# print all the genomic alignments using a Bio::AlignIO object
my $alignIO = Bio::AlignIO->newFh(
-interleaved => 0,
-fh => \*STDOUT,
-format => $output_format,
    -idlength => 10
);

foreach my $this_align (@$all_aligns) {
    print $alignIO $this_align;
}

exit; 

Any pointers on what I'm doing wrong ?

**Tags:** ensembl, perl, api
> **Comments:**
> **username_1**: Perl is a language I haven't heard in a long time :D It seems like the GenomeDB is passing an argument that might be wrong. Are you using the latest bioperl/perl?  

---

## 1 answers

### Answer by username_0 on 2018-12-11. Score: 2

While I wouldn't consider this as the best answer or solution - I decided to use Ensembl REST api to extract the coordinates of alignment blocks. 
The quick fix - in python looks like this: 
#This is the main function which uses Ensembl REST API to access the Enesembl Compara database 
#And retrive the alignment blocks which correspond to the MM10 standard. 
#The function accepts chromosome, start and array and returns the alignment blocks
#reported by the API. Since the blocks can be on different chromosomes/and/or/contigs, it 
#returns the whole output in form of dataframe - containing chromosome, start and stop of the
#alignment blocks corresponding to input and all the other alignment blocks corresponding the 
#16 mice species, if available. 
#!!!!!!!----------Caution start----------!!!!!!!
#The API is a bit buggy, so it is advised not to request for specific species.
#!!!!!!!-----------Caution end-----------!!!!!!!
def liftover(chrom, start, end):
    mmStart, mmEnd, mmchr = [], [], []
    caStart, caEnd, cachr = [], [], []
    #ryStart, ryEnd, rychr = [], [], []
    server = "https://rest.ensembl.org"
    ext = "/alignment/region/mus_musculus/" + str(chrom) + ":" + str(start) + "-" + str(end) + ":1?species_set_group=murinae;method=CACTUS_HAL;content-type=application/json"
    headers={ "Content-Type" : "application/json"}
    r = requests.get(server+ext, headers={ "Content-Type" : "application/json"})
    if(r.ok):
        json_string = json.dumps(r.json())
        jData = json.loads(r.content)
        results = r.json()
        print("The response contains {0} properties".format(len(jData)))
        print("\n")
    else:
        r.raise_for_status()

    for element in jData:
        element.pop('tree', None)

    for element in jData:
        for key, value in element.items():
            for z in value:
                if (z["species"]=="mus_musculus"):
                    mmStart.append(z["start"])
                    mmEnd.append(z["end"])
                    mmchr.append(z["seq_region"])
                if (z["species"]=="mus_musculus_casteij"):
                    caStart.append(z["start"])
                    caEnd.append(z["end"])
                    cachr.append(z["seq_region"])
    if (len(mmStart) != len(caStart)):
        print("Length mismatch between species blocks - proceed with caution!")
    return [min(mmStart), max(mmEnd), min(caStart), max(caEnd), len(mmStart)]

Again, it depends on how alignment blocks are reported - and requires further digging to resolve which mm10 alignment block resembles CAST alignment block.


---

