From a8b6934daccd56f6d30f4871d112f632424d74e9 Mon Sep 17 00:00:00 2001
From: Thibaut Hourlier <thibaut@ebi.ac.uk>
Date: Tue, 6 Nov 2018 15:44:31 +0000
Subject: [PATCH] Use seq_region_start and seq_region_end when updating gene
 coordinates in the database

---
 modules/Bio/EnsEMBL/DBSQL/GeneAdaptor.pm |  4 ++--
 modules/t/gene.t                         | 14 ++++++++++++++
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/modules/Bio/EnsEMBL/DBSQL/GeneAdaptor.pm b/modules/Bio/EnsEMBL/DBSQL/GeneAdaptor.pm
index 06d3237367..2b231989c5 100644
--- a/modules/Bio/EnsEMBL/DBSQL/GeneAdaptor.pm
+++ b/modules/Bio/EnsEMBL/DBSQL/GeneAdaptor.pm
@@ -1655,8 +1655,8 @@ sub update_coords {
        WHERE gene_id = ?
     );
   my $sth = $self->prepare($update_sql);
-  $sth->bind_param(1, $gene->start);
-  $sth->bind_param(2, $gene->end);
+  $sth->bind_param(1, $gene->seq_region_start);
+  $sth->bind_param(2, $gene->seq_region_end);
   $sth->bind_param(3, $gene->dbID);
   $sth->execute();
 }
diff --git a/modules/t/gene.t b/modules/t/gene.t
index 65e330555b..a2f5cd08e5 100644
--- a/modules/t/gene.t
+++ b/modules/t/gene.t
@@ -473,6 +473,20 @@ my $new_gene = $ga->fetch_by_stable_id("ENSG00000171456");
 cmp_ok($new_gene->start(), '==', 30735607, 'Updated gene start');
 cmp_ok($new_gene->end(), '==', 30815178, 'Updated gene end');
 
+# test update_coords method when working on sub Slice
+my $update_slice = $db->get_SliceAdaptor()->fetch_by_region('chromosome', '20', 30730000, 30815178);
+my $update_genes = $update_slice->get_all_Genes();
+cmp_ok(scalar(@$update_genes), '>=', 1, 'Check the region has at least one gene');
+foreach my $gene_to_update (@$update_genes) {
+  if ($gene_to_update->stable_id() eq 'ENSG00000171456') {
+    $ga->update_coords($gene_to_update);
+  }
+}
+
+my $updated_gene = $ga->fetch_by_stable_id("ENSG00000171456");
+cmp_ok($updated_gene->start(), '==', 30735607, 'Updated gene start');
+cmp_ok($updated_gene->end(), '==', 30815178, 'Updated gene end');
+
 #
 # test GeneAdaptor::fetch_all_by_domain
 #
-- 
GitLab