From d2a3a46038925d62e2f9a0024217f8cfabe48923 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20Kusalananda=20K=C3=A4h=C3=A4ri?=
 <ak4@sanger.ac.uk>
Date: Wed, 5 Jan 2011 13:14:58 +0000
Subject: [PATCH] Fixed the overlap test in add_Exon().

---
 modules/Bio/EnsEMBL/Transcript.pm | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/modules/Bio/EnsEMBL/Transcript.pm b/modules/Bio/EnsEMBL/Transcript.pm
index bc75835138..d7f4bfa238 100755
--- a/modules/Bio/EnsEMBL/Transcript.pm
+++ b/modules/Bio/EnsEMBL/Transcript.pm
@@ -1231,17 +1231,17 @@ sub add_Exon {
   if ( @{$ea} ) {
     if ( $exon->strand() == 1 ) {
 
-      if (    ( $exon->start() > $ea->[$#$ea]->end() )
-           && ( $exon->end() > $ea->[$#$ea]->end() ) )
-      {
+      if ( $exon->start() > $ea->[$#$ea]->end() ) {
         push( @{$ea}, $exon );
         $was_added = 1;
       } else {
         # insert it at correct place
         for ( my $i = 0; $i <= $#$ea; $i++ ) {
-          if (    ( $exon->start() < $ea->[$i]->start() )
-               && ( $exon->end() < $ea->[$i]->start() ) )
-          {
+          if ( $exon->start() < $ea->[$i]->start() ) {
+            if ( $exon->end() >= $ea->[$i]->start() ) {
+              # Overlap
+              last;
+            }
             splice( @{$ea}, $i, 0, $exon );
             $was_added = 1;
             last;
@@ -1251,17 +1251,17 @@ sub add_Exon {
 
     } else {
 
-      if (    ( $exon->start() < $ea->[$#$ea]->start() )
-           && ( $exon->end() < $ea->[$#$ea]->start() ) )
-      {
+      if ( $exon->end() < $ea->[$#$ea]->start() ) {
         push( @{$ea}, $exon );
         $was_added = 1;
       } else {
         # insert it at correct place
         for ( my $i = 0; $i <= $#$ea; $i++ ) {
-          if (    ( $exon->start() > $ea->[$i]->end() )
-               && ( $exon->end() > $ea->[$i]->end() ) )
-          {
+          if ( $exon->end() > $ea->[$i]->end() ) {
+            if ( $exon->start() <= $ea->[$i]->end() ) {
+              # Overlap
+              last;
+            }
             splice( @{$ea}, $i, 0, $exon );
             $was_added = 1;
             last;
-- 
GitLab