From a2ccb53124d0c4e132cf83db2f66a0e5b961cf82 Mon Sep 17 00:00:00 2001
From: Andrew Yates <ayates@ebi.ac.uk>
Date: Thu, 22 Sep 2011 16:31:51 +0000
Subject: [PATCH] Adding a new method for describing a region's assembly
 exception type

---
 modules/Bio/EnsEMBL/Slice.pm                  | 28 +++++++++++++++++++
 modules/t/slice.t                             | 16 +++++++----
 .../homo_sapiens/core/attrib_type.txt         |  1 +
 .../homo_sapiens/core/seq_region_attrib.txt   |  1 +
 4 files changed, 41 insertions(+), 5 deletions(-)

diff --git a/modules/Bio/EnsEMBL/Slice.pm b/modules/Bio/EnsEMBL/Slice.pm
index a3b05713aa..e0d2aeb250 100644
--- a/modules/Bio/EnsEMBL/Slice.pm
+++ b/modules/Bio/EnsEMBL/Slice.pm
@@ -673,6 +673,34 @@ sub subseq {
   return $subseq;
 }
 
+=head2 assembly_exception_type
+
+  Example     : $self->assembly_exception_type(); 
+  Description : Returns the type of slice this is. If it is reference then you
+                will get 'REF' back. Otherwise you will get the first
+                element from C<get_all_AssemblyExceptionFeatures()>. If no
+                assembly exception exists you will get an empty string back.
+  Returntype  : String
+  Exceptions  : None
+  Caller      : Public
+  Status      : Beta
+
+=cut
+
+sub assembly_exception_type {
+  my ($self) = @_;
+  my $type = q{};
+  if($self->is_reference()) {
+    $type = 'REF';
+  }
+  else {
+    my $assembly_exceptions = $self->get_all_AssemblyExceptionFeatures();
+    if(@{$assembly_exceptions}) {
+      $type = $assembly_exceptions->[0]->type();
+    }
+  }
+  return $type;
+}
 
 
 =head2 get_base_count
diff --git a/modules/t/slice.t b/modules/t/slice.t
index 13e454ce7c..4d88439ca5 100644
--- a/modules/t/slice.t
+++ b/modules/t/slice.t
@@ -1,11 +1,7 @@
 use strict;
 use warnings;
 
-
-BEGIN { $| = 1;
-	use Test;
-	plan tests => 60;
-}
+use Test::More tests => 63;
 
 use Bio::EnsEMBL::Test::TestUtils;
 
@@ -153,6 +149,8 @@ ok($name eq "chromosome:NCBI33:$CHR:$START:$END:$STRAND");
 #
 ok($slice->length == ($END-$START + 1));
 
+# Test exception name
+is($slice->assembly_exception_type(), 'REF', 'Type of region is REF');
 
 #
 # Test get_attributes
@@ -437,3 +435,11 @@ $slice = $slice_adaptor->fetch_by_region('chromosome', 1, 1, 10);
 ok(@alt_names == 1);
 
 $multi->restore();
+
+
+#Test assembly exception type on HAP
+my $hap_slice = $slice_adaptor->fetch_by_region(undef, '20_HAP1');
+is($hap_slice->assembly_exception_type(), 'HAP', 'Ensuring haplotype regions are HAP');
+my $chr_one_slice = $slice_adaptor->fetch_by_region('chromosome', '1', 1, 10);
+is($chr_one_slice->assembly_exception_type(), 'REF', 'Ensuring reference regions are REF');
+
diff --git a/modules/t/test-genome-DBs/homo_sapiens/core/attrib_type.txt b/modules/t/test-genome-DBs/homo_sapiens/core/attrib_type.txt
index e23310e017..a6cee5d90f 100644
--- a/modules/t/test-genome-DBs/homo_sapiens/core/attrib_type.txt
+++ b/modules/t/test-genome-DBs/homo_sapiens/core/attrib_type.txt
@@ -15,3 +15,4 @@
 15	_rna_edit	RNA editing	\N
 16	_selenocysteine	Selenocysteine	\N
 17	codon_table	Codon Table	Alternate codon table
+18	non_ref	Non Reference	Non Reference Sequence Region
\ No newline at end of file
diff --git a/modules/t/test-genome-DBs/homo_sapiens/core/seq_region_attrib.txt b/modules/t/test-genome-DBs/homo_sapiens/core/seq_region_attrib.txt
index 58dd00b5e8..a4eff7fd65 100644
--- a/modules/t/test-genome-DBs/homo_sapiens/core/seq_region_attrib.txt
+++ b/modules/t/test-genome-DBs/homo_sapiens/core/seq_region_attrib.txt
@@ -13,3 +13,4 @@
 469283	14	1
 965899	17	2
 965888	17	2
+469351	18	1
\ No newline at end of file
-- 
GitLab