EnsEMBL/Feature.pm untested

filter: Statementstmt 0.0% 0 / 438 Branchbran 0.0% 0 / 216 Conditioncond 0.0% 0 / 163 Subroutinesub 0.0% 0 / 45 Podpod 0.0% 0 / 36 totaltotal 0.0% 0 / 898 CC 109 SCAR 42.6
CC
109
Cov
0%
transform
240.0
get_all_alt_locations
210.0
new
110.0
CRAP 71.2
1 =head1 LICENSE
2  
3 See the NOTICE file distributed with this work for additional information
4 regarding copyright ownership.
5  
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9  
10 http://www.apache.org/licenses/LICENSE-2.0
11  
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17  
18 =cut
19  
20  
21 =head1 CONTACT
22  
23 Please email comments or questions to the public Ensembl
24 developers list at <http://lists.ensembl.org/mailman/listinfo/dev>.
25  
26 Questions may also be sent to the Ensembl help desk at
27 <http://www.ensembl.org/Help/Contact>.
28  
29 =cut
30  
31 =head1 NAME
32  
33 Bio::EnsEMBL::Feature - Ensembl specific sequence feature.
34  
35 =head1 SYNOPSIS
36  
37 my $feat = new Bio::EnsEMBL::Feature(
38 -start => 100,
39 -end => 220,
40 -strand => -1,
41 -slice => $slice,
42 -analysis => $analysis
43 );
44  
45 my $start = $feat->start();
46 my $end = $feat->end();
47 my $strand = $feat->strand();
48  
49 # Move the feature to the chromosomal coordinate system
50 $feature = $feature->transform('chromosome');
51  
52 # Move the feature to a different slice (possibly on another coord
53 # system)
54 $feature = $feature->transfer($new_slice);
55  
56 # Project the feature onto another coordinate system possibly across
57 # boundaries:
58 @projection = @{ $feature->project('contig') };
59  
60 # Change the start, end, and strand of the feature in place
61 $feature->move( $new_start, $new_end, $new_strand );
62  
63 =head1 DESCRIPTION
64  
65 This is the Base feature class from which all Ensembl features inherit.
66 It provides a bare minimum functionality that all features require. It
67 basically describes a location on a sequence in an arbitrary coordinate
68 system.
69  
70 =head1 METHODS
71  
72 =cut
73  
74  
75 package Bio::EnsEMBL::Feature;
76 $Bio::EnsEMBL::Feature::VERSION = '114.0.0_50'; # TRIAL
77 $Bio::EnsEMBL::Feature::VERSION = '114.0.050';
78 use strict;
79 use warnings;
80  
81 use Bio::EnsEMBL::Storable;
82 use Bio::EnsEMBL::Utils::Argument qw(rearrange);
83 use Bio::EnsEMBL::Utils::Exception qw(throw warning);
84 use Bio::EnsEMBL::Utils::Scalar qw(check_ref assert_ref);
85 use Bio::EnsEMBL::Slice;
86  
87 use vars qw(@ISA);
88  
89 use Scalar::Util qw(weaken);
90  
91 @ISA = qw(Bio::EnsEMBL::Storable);
92  
93  
94 =head2 new
95  
96 Arg [-SLICE]: Bio::EnsEMBL::SLice - Represents the sequence that this
97 feature is on. The coordinates of the created feature are
98 relative to the start of the slice.
99 Arg [-START]: The start coordinate of this feature relative to the start
100 of the slice it is sitting on. Coordinates start at 1 and
101 are inclusive.
102 Arg [-END] : The end coordinate of this feature relative to the start of
103 the slice it is sitting on. Coordinates start at 1 and are
104 inclusive.
105 Arg [-STRAND]: The orientation of this feature. Valid values are 1,-1,0.
106 Arg [-SEQNAME] : A seqname to be used instead of the default name of the
107 of the slice. Useful for features that do not have an
108 attached slice such as protein features.
109 Arg [-dbID] : (optional) internal database id
110 Arg [-ADAPTOR]: (optional) Bio::EnsEMBL::DBSQL::BaseAdaptor
111 Example : $feature = Bio::EnsEMBL::Feature->new(-start => 1,
112 -end => 100,
113 -strand => 1,
114 -slice => $slice,
115 -analysis => $analysis);
116 Description: Constructs a new Bio::EnsEMBL::Feature. Generally subclasses
117 of this method are instantiated, rather than this class itself.
118 Returntype : Bio::EnsEMBL::Feature
119 Exceptions : Thrown on invalid -SLICE, -ANALYSIS, -STRAND ,-ADAPTOR arguments
120 Caller : general, subclass constructors
121 Status : Stable
122  
123 =cut
124  
125  
126 sub new {
127 my $caller = shift;
128  
129 my $class = ref($caller) || $caller;
130 my ( $start, $end, $strand, $slice, $analysis,$seqname, $dbID, $adaptor ) =
131 rearrange(['START','END','STRAND','SLICE','ANALYSIS', 'SEQNAME',
132 'DBID', 'ADAPTOR'], @_);
133 if($slice) {
134 if(!ref($slice) || !($slice->isa('Bio::EnsEMBL::Slice') or $slice->isa('Bio::EnsEMBL::LRGSlice')) ) {
135 throw('-SLICE argument must be a Bio::EnsEMBL::Slice not '.$slice);
136 }
137 }
138  
139 if($analysis) {
140 if(!ref($analysis) || !$analysis->isa('Bio::EnsEMBL::Analysis')) {
141 throw('-ANALYSIS argument must be a Bio::EnsEMBL::Analysis not '.
142 $analysis);
143 }
144 }
145  
146 if(defined($strand)) {
147 if(!($strand == 1) && !($strand == -1) && !($strand == 0)) {
148 throw('-STRAND argument must be 1, -1, or 0');
149 }
150 }
151  
152 if(defined($start) && defined($end)) {
153 if (($start =~ /\d+/) && ($end =~ /\d+/)) {
154 if($end+1 < $start and $slice and !$slice->is_circular()) {
155 throw(sprintf('Start (%d) must be less than or equal to end+1 (%d)', $start, ($end+1)));
156 }
157 } else {
158 throw('Start and end must be integers');
159 }
160 }
161  
162 my $self = bless({'start' => $start,
163 'end' => $end,
164 'strand' => $strand,
165 'slice' => $slice,
166 'analysis' => $analysis,
167 'seqname' => $seqname,
168 'dbID' => $dbID}, $class);
169  
170 $self->adaptor($adaptor);
171 return $self;
172 }
173  
174  
175 =head2 start
176  
177 Arg [1] : (optional) int $start
178 The start of this feature relative to the start of the slice
179 that it is on.
180 Example : $start = $feat->start()
181 Description: Getter/Setter for the start of this feature relative to the
182 start of the slice it is on. Note that negative values, or
183 values exceeding the length of the slice are permitted.
184 Start must be less than or equal to the end regardless of the
185 strand. Coordinate values start at 1 and are inclusive.
186 Returntype : int
187 Exceptions : none
188 Caller : general
189 Status : Stable
190  
191 =cut
192  
193 sub start {
194 my ( $self, $value ) = @_;
195  
196 if ( defined($value) ) {
197 $self->{'start'} = $value;
198 }
199  
200 return $self->{'start'};
201 }
202  
203  
204  
205 =head2 end
206  
207 Arg [1] : (optional) int $end
208 Example : $end = $feat->end();
209 Description: Getter/Setter for the end of this feature relative to the
210 start of the slice that it is on. Note that negative values,
211 of values exceeding the length of the slice are permitted. End
212 must be greater than or equal to start regardless of the strand.
213 Coordinate values start at 1 and are inclusive.
214 Returntype : int
215 Exceptions : none
216 Caller : general
217 Status : Stable
218  
219 =cut
220  
221 sub end {
222 my ( $self, $value ) = @_;
223  
224 if ( defined($value) ) {
225 $self->{'end'} = $value;
226 }
227  
228 return $self->{'end'};
229 }
230  
231  
232  
233  
234 =head2 strand
235  
236 Arg [1] : (optional) int $strand
237 Example : $feat->strand(-1);
238 Description: Getter/Setter for the strand of this feature relative to the
239 slice it is on. 0 is an unknown or non-applicable strand.
240 -1 is the reverse (negative) strand and 1 is the forward
241 (positive) strand. No other values are permitted.
242 Returntype : int
243 Exceptions : thrown if an invalid strand argument is passed
244 Caller : general
245 Status : Stable
246  
247 =cut
248  
249 sub strand {
250 my ( $self, $strand ) = @_;
251  
252 if ( defined($strand) ) {
253 if ( $strand != 0 && $strand != 1 && $strand != -1 ) {
254 throw('strand argument must be 0, -1 or 1');
255 }
256  
257 $self->{'strand'} = $strand;
258 }
259  
260 return $self->{'strand'};
261 }
262  
263 =head2 move
264  
265 Arg [1] : int start
266 Arg [2] : int end
267 Arg [3] : (optional) int strand
268 Description: Sets the start, end and strand in one call rather than in
269 3 seperate calls to the start(), end() and strand() methods.
270 This is for convenience and for speed when this needs to be
271 done within a tight loop.
272 Returntype : none
273 Exceptions : Thrown is invalid arguments are provided
274 Caller : general
275 Status : Stable
276  
277 =cut
278  
279 sub move {
280 my $self = shift;
281  
282 throw('start and end arguments are required') if(@_ < 2);
283  
284 my $start = shift;
285 my $end = shift;
286 my $strand = shift;
287  
288 if(defined($start) && defined($end) && $end < $start) {
289 throw('start must be less than or equal to end');
290 }
291 if(defined($strand) && $strand != 0 && $strand != -1 && $strand != 1) {
292 throw('strand must be 0, -1 or 1');
293 }
294  
295 $self->{'start'} = $start;
296 $self->{'end'} = $end;
297 $self->{'strand'} = $strand if(defined($strand));
298 }
299  
300  
301  
302 =head2 length
303  
304 Arg [1] : none
305 Example : $length = $feat->length();
306 Description: Returns the length of this feature
307 Returntype : Integer
308 Exceptions : Throws if end < start and the feature is not on a
309 circular slice
310 Caller : general
311 Status : Stable
312  
313 =cut
314  
315 sub length {
316 my ($self) = @_;
317  
318 if ( $self->{'end'} < $self->{'start'} ) {
319 # if circular, we can work out the length of an origin-spanning
320 # feature using the size of the underlying region.
321 if ( $self->slice() && $self->slice()->is_circular() ) {
322 my $len =
323 $self->slice()->seq_region_length() -
324 ( $self->{'start'} - $self->{'end'} ) + 1;
325 return $len;
326 } else {
327 throw( "Cannot determine length of non-circular feature "
328 . "where start > end" );
329 }
330 }
331  
332 return $self->{'end'} - $self->{'start'} + 1;
333 }
334  
335 =head2 analysis
336  
337 Arg [1] : (optional) Bio::EnsEMBL::Analysis $analysis
338 Example : $feature->analysis(new Bio::EnsEMBL::Analysis(...))
339 Description: Getter/Setter for the analysis that is associated with
340 this feature. The analysis describes how this feature
341 was derived.
342 Returntype : Bio::EnsEMBL::Analysis
343 Exceptions : thrown if an invalid argument is passed
344 Caller : general
345 Status : Stable
346  
347 =cut
348  
349 sub analysis {
350 my $self = shift;
351  
352 if(@_) {
353 my $an = shift;
354 if(defined($an) && (!ref($an) || !$an->isa('Bio::EnsEMBL::Analysis'))) {
355 throw('analysis argument must be a Bio::EnsEMBL::Analysis');
356 }
357 $self->{'analysis'} = $an;
358 }
359  
360 return $self->{'analysis'};
361 }
362  
363  
364  
365 =head2 slice
366  
367 Arg [1] : (optional) Bio::EnsEMBL::Slice $slice
368 Example : $seqname = $feature->slice()->name();
369 Description: Getter/Setter for the Slice that is associated with this
370 feature. The slice represents the underlying sequence that this
371 feature is on. Note that this method call is analagous to the
372 old SeqFeature methods contig(), entire_seq(), attach_seq(),
373 etc.
374 Returntype : Bio::EnsEMBL::Slice
375 Exceptions : thrown if an invalid argument is passed
376 Caller : general
377 Status : Stable
378  
379 =cut
380  
381 sub slice {
382 my ( $self, $slice ) = @_;
383  
384 if ( defined($slice) ) {
385 if ( !check_ref( $slice, 'Bio::EnsEMBL::Slice' )
386 && !check_ref( $slice, 'Bio::EnsEMBL::LRGSlice' ) )
387 {
388 throw('slice argument must be a Bio::EnsEMBL::Slice');
389 }
390  
391 $self->{'slice'} = $slice;
392 } elsif ( @_ > 1 ) {
393 delete($self->{'slice'});
394 }
395  
396 return $self->{'slice'};
397 }
398  
399 =head2 equals
400  
401 Arg [1] : Bio::EnsEMBL::Feature object
402 Example : if ($featureA->equals($featureB)) { ... }
403 Description : Compares two features using various criteria. The
404 test for eqality goes through the following list and
405 terminates at the first true match:
406  
407 1. If the two features are the same object, they are
408 equal.
409 2. If they are of different types (e.g., transcript
410 and gene), they are *not* equal.
411 3. If they both have dbIDs: if these are the same,
412 then they are equal, otherwise not.
413 4. If they both have slices and analysis objects:
414 if the analysis dbIDs are the same and the
415 seq_region_id are the same, along with
416 seq_region_start and seq_region_end, then they are
417 equal, otherwise not.
418  
419 If none of the above is able to determine equality,
420 undef is returned.
421  
422 Return type : tri-Boolean (0, 1, undef = "unknown")
423  
424 Exceptions : Thrown if a non-feature is passed as the argument.
425  
426 =cut
427  
428 sub equals {
429 my ( $self, $feature ) = @_;
430  
431 # If the features are the same object, they are equal.
432 if ( !defined($feature) ) { return 0 }
433 if ( $self eq $feature ) { return 1 }
434  
435 assert_ref( $feature, 'Bio::EnsEMBL::Feature' );
436  
437 # If the features have different types, they are *not* equal.
438 if ( ref($self) ne ref($feature) ) {
439 return 0;
440 }
441  
442 # If the features has the same dbID, they are equal.
443 if ( defined( $self->dbID() ) && defined( $feature->dbID() ) ) {
444 if ( $self->dbID() == $feature->dbID() ) { return 1 }
445 else { return 0 }
446 }
447  
448 # We now know that one of the features do not have a dbID.
449  
450 # If the features have the same start, end, strand and seq_region_id,
451 # and analysis_id, they are equal.
452 if (
453 ( defined( $self->analysis() ) && defined( $feature->analysis() ) )
454 && ( defined( $self->slice() ) && defined( $feature->slice() ) ) )
455 {
456 if ( ( $self->start() == $feature->start() ) &&
457 ( $self->end() == $feature->end() ) &&
458 ( $self->strand() == $feature->strand() ) &&
459 ( $self->slice()->get_seq_region_id() ==
460 $feature->slice()->get_seq_region_id() ) &&
461 ( $self->analysis()->dbID() == $feature->analysis()->dbID() ) )
462 {
463 return 1;
464 }
465 else { return 0 }
466 }
467  
468 # We now know that one of the features does not have either analysis
469 # or slice.
470  
471 # We don't know if the features are equal. This happens if they are
472 # not the same object but are of the same type, and one of them lacks
473 # dbID, and if there aren't slice and analysis objects attached to
474 # them both.
475 return undef;
476 } ## end sub equals
477  
478  
479 =head2 transform
480  
481 Arg [1] : string $coord_system
482 The coord system to transform this feature to.
483 Arg [2] : string $version (optional)
484 The version of the coord system to transform this feature to.
485 Arg [3] : Bio::EnsEMBL::Slice (optional)
486 Specified when a projection may land on many overlapping slices
487 and disambiguation is required.
488 Example : $feature = $feature->transform('contig');
489 next if(!defined($feature));
490 Description: Returns a copy of this feature, but converted to a different
491 coordinate system. The converted feature will be placed on a
492 slice which spans an entire sequence region of the new
493 coordinate system. If the requested coordinate system is the
494 same coordinate system it is simply placed on a slice which
495 spans the entire seq_region (as opposed to the original slice
496 which may have only partially covered the seq_region).
497  
498 If a feature spans a boundary in the new coordinate system,
499 undef is returned instead.
500  
501 For example, transforming an exon in contig coordinates to one
502 in chromosomal coodinates will place the exon on a slice of an
503 entire chromosome.
504 Returntype : Bio::EnsEMBL::Feature (or undef)
505 Exceptions : thrown if an invalid coordinate system is provided
506 warning if Feature is not attached to a slice
507 Caller : general, transfer()
508 Status : Stable
509  
510 =cut
511  
512 sub transform {
513 my $self = shift;
514 my $cs_name = shift;
515 my $cs_version = shift;
516 my $to_slice = shift;
517  
518 my $slice = $self->{'slice'};
519  
520 if(!$slice) {
521 warning("Feature cannot be transformed without attached slice.");
522 return undef;
523 }
524  
525 if(!$slice->adaptor()) {
526 warning("Feature cannot be transformed without adaptor on" .
527 " attached slice.");
528 return undef;
529 }
530  
531 #use db from slice since this feature may not yet be stored in a database
532 my $db = $slice->adaptor->db();
533 my $cs = $db->get_CoordSystemAdaptor->fetch_by_name($cs_name, $cs_version);
534 my $current_cs = $slice->coord_system();
535  
536 if(!$current_cs) {
537 warning("Feature cannot be transformed without CoordSystem on " .
538 "attached slice.");
539 return undef;
540 }
541  
542 if(!$cs) {
543 throw("Cannot transform to unknown coordinate system " .
544 "[$cs_name $cs_version]\n");
545 }
546  
547 # if feature is already in the requested coordinate system, we can just
548 # return a copy
549 if( $cs->equals( $current_cs ) && $slice->start() == 1 &&
550 $slice->strand() == 1 ) {
551 my $new_feature;
552 %$new_feature = %$self;
553 bless $new_feature, ref $self;
554 return $new_feature;
555 }
556 my $projection;
557 if(defined($to_slice)){
558 $projection = $self->project_to_slice( $to_slice ); }
559 else{
560 $projection = $self->project( $cs_name, $cs_version );
561 }
562  
563 if(@$projection == 0){
564 return undef;
565 }
566 if( @$projection != 1 and !defined($to_slice)) {
567 # warn "MORE than one projection and NO slice specified ";
568 # warn "from ".$self->slice->name." to $cs_name, $cs_version\n";
569 return undef;
570 }
571 my $index = 0;
572 if(defined($to_slice)){
573 my $found = 0;
574 my $i = 0;
575 foreach my $proj (@{$projection}) {
576 my $slice = $proj->[2];
577 if($to_slice->get_seq_region_id eq $slice->get_seq_region_id){
578 $found =1;
579 $index = $i;
580 }
581 $i++;
582 }
583 if(!$found){
584 if(@$projection != 1){
585 if(@$projection == 0){
586 warn "number of mappings is ".@$projection."\n";
587 warn "could not project feature ".ref($self)." from ".$self->slice->seq_region_name." to ".$to_slice->seq_region_name."\n";
588 warn "In the region of ".$self->slice->start." <-> ".$self->slice->end."\n";
589 warn "feat start=".($self->slice->start+$self->start)."\tend=".($self->slice->start+$self->end)."\n";
590 }
591 else{
592 foreach my $proj (@{$projection}) {
593 my $slice = $proj->[2];
594 warn "available slice ".$slice->seq_region_name."\n";
595 }
596 warn "MORE than one projection and no to slice specified (".$to_slice->seq_region_name.")\n";
597 }
598 }
599 else {
600 foreach my $proj (@{$projection}) {
601 warn "Mapping is to ".$proj->[2]->seq_region_name."\n";
602 }
603 warn "One projection but none to slice specified\n";
604 }
605 return undef;
606 }
607 }
608
609 my $p_slice = $projection->[$index]->[2];
610 my $slice_adaptor = $db->get_SliceAdaptor;
611 $slice = $slice_adaptor->fetch_by_region($p_slice->coord_system()->name(),
612 $p_slice->seq_region_name(),
613 undef, #start
614 undef, #end
615 1, #strand
616 $p_slice->coord_system()->version);
617
618 my $new_feature;
619 %$new_feature = %$self;
620 bless $new_feature, ref $self;
621 $new_feature->{'start'} = $p_slice->start();
622 $new_feature->{'end'} = $p_slice->end();
623 $new_feature->{'strand'} =
624 ($self->{'strand'} == 0) ? 0 : $p_slice->strand();
625 $new_feature->{'slice'} = $slice;
626 return $new_feature;
627  
628 }
629  
630  
631  
632 =head2 transfer
633  
634 Arg [1] : Bio::EnsEMBL::Slice $slice
635 The slice to transfer this feature to
636 Example : $feature = $feature->transfer($slice);
637 next if(!defined($feature));
638 Description: Returns a copy of this feature which has been shifted onto
639 another slice.
640  
641 If the new slice is in a different coordinate system the
642 feature is transformed first and then placed on the slice.
643 If the feature would be split across a coordinate system
644 boundary or mapped to a gap undef is returned instead.
645  
646 If the feature cannot be placed on the provided slice because
647 it maps to an entirely different location, undef is returned
648 instead.
649  
650 Returntype : Bio::EnsEMBL::Feature (or undef)
651 Exceptions : throw on incorrect argument
652 throw if feature does not have attached slice
653 Caller : general, transform()
654 Status : Stable
655  
656 =cut
657  
658  
659 sub transfer {
660 my $self = shift;
661 my $slice = shift;
662  
663 if(!$slice || !ref($slice) || (!$slice->isa('Bio::EnsEMBL::Slice') && !$slice->isa('Bio::EnsEMBL::LRGSlice'))) {
664 throw('Slice argument is required');
665 }
666  
667 #make a shallow copy of the feature to be transfered
668 my $feature;
669 %{$feature} = %{$self};
670 bless $feature, ref($self);
671 weaken $feature->{adaptor};
672  
673 my $current_slice = $self->{'slice'};
674  
675 if(!$current_slice) {
676 warning("Feature cannot be transfered without attached slice.");
677 return undef;
678 }
679  
680 my $cur_cs = $current_slice->coord_system();
681 my $dest_cs = $slice->coord_system();
682  
683 #if we are not in the same coord system a transformation step is needed first
684 if(!$dest_cs->equals($cur_cs)) {
685 $feature = $feature->transform($dest_cs->name, $dest_cs->version, $slice);
686 return undef if(!defined($feature));
687 $current_slice = $feature->{'slice'};
688 }
689  
690 # feature went to entirely different seq_region
691 if($current_slice->seq_region_name() ne $slice->seq_region_name()) {
692 return undef;
693 }
694  
695 #if the current feature positions are not relative to the start of the
696 #seq region, convert them so they are
697 my $cur_slice_start = $current_slice->start();
698 my $cur_slice_strand = $current_slice->strand();
699 if($cur_slice_start != 1 || $cur_slice_strand != 1) {
700 my $fstart = $feature->{'start'};
701 my $fend = $feature->{'end'};
702  
703 if($cur_slice_strand == 1) {
704 $feature->{'start'} = $fstart + $cur_slice_start - 1;
705 $feature->{'end'} = $fend + $cur_slice_start - 1;
706 } else {
707 my $cur_slice_end = $current_slice->end();
708 $feature->{'start'} = $cur_slice_end - $fend + 1;
709 $feature->{'end'} = $cur_slice_end - $fstart + 1;
710 $feature->{'strand'} *= -1;
711 }
712 }
713  
714 my $fstart = $feature->{'start'};
715 my $fend = $feature->{'end'};
716  
717 #convert to destination slice coords
718 if($slice->strand == 1) {
719 $feature->{'start'} = $fstart - $slice->start() + 1;
720 $feature->{'end'} = $fend - $slice->start() + 1;
721 } else {
722 $feature->{'start'} = $slice->end() - $fend + 1;
723 $feature->{'end'} = $slice->end() - $fstart + 1;
724 $feature->{'strand'} *= -1;
725 }
726  
727 $feature->{'slice'} = $slice;
728  
729 return $feature;
730 }
731  
732 =head2 project_to_slice
733  
734 Arg [1] : slice to project to
735  
736  
737 Example :
738 my $clone_projection = $feature->project_to_slice($slice);
739  
740 foreach my $seg (@$clone_projection) {
741 my $clone = $seg->to_Slice();
742 print "Features current coords ", $seg->from_start, '-',
743 $seg->from_end, " project onto clone coords " .
744 $clone->seq_region_name, ':', $clone->start, '-', $clone->end,
745 $clone->strand, "\n";
746 }
747 Description: Returns the results of 'projecting' this feature onto another
748 slice . This is useful to see where a feature
749 would lie in a coordinate system in which it
750 crosses a boundary.
751  
752 This method returns a reference to a list of
753 Bio::EnsEMBL::ProjectionSegment objects.
754 ProjectionSegments are blessed arrays and can also be used as
755 triplets [from_start,from_end,to_Slice]. The from_start and
756 from_end are the coordinates relative to the feature start.
757 For example, if a feature is current 100-200bp on a slice
758 then the triplets returned might be:
759 [1,50,$slice1],
760 [51,101,$slice2]
761  
762 The to_Slice is a slice spanning the region on the requested
763 coordinate system that this feature projected to.
764  
765 If the feature projects entirely into a gap then a reference to
766 an empty list is returned.
767  
768 Returntype : listref of Bio::EnsEMBL::ProjectionSegments
769 which can also be used as [$start,$end,$slice] triplets
770 Exceptions : slice does not have an adaptor
771 Caller : general
772 Status : At Risk
773  
774 =cut
775  
776 sub project_to_slice {
777 my $self = shift;
778 my $to_slice = shift;
779 my $slice = $self->{'slice'};
780  
781 if(!$slice) {
782 warning("Feature cannot be projected without attached slice.");
783 return [];
784 }
785  
786  
787 #get an adaptor from the attached slice because this feature may not yet
788 #be stored and may not have its own adaptor
789 my $slice_adaptor = $slice->adaptor();
790  
791 if(!$slice_adaptor) {
792 throw("Cannot project feature because associated slice does not have an " .
793 " adaptor");
794 }
795  
796 my $strand = $self->strand() * $slice->strand();
797 #fetch by feature always gives back forward strand slice:
798 $slice = $slice_adaptor->fetch_by_Feature($self);
799 $slice = $slice->invert if($strand == -1);
800 return $slice->project_to_slice($to_slice);
801 }
802  
803  
804 =head2 project
805  
806 Arg [1] : string $name
807 The name of the coordinate system to project this feature onto
808 Arg [2] : string $version (optional)
809 The version of the coordinate system (such as 'NCBI34') to
810 project this feature onto
811 Example :
812 my $clone_projection = $feature->project('clone');
813  
814 foreach my $seg (@$clone_projection) {
815 my $clone = $seg->to_Slice();
816 print "Features current coords ", $seg->from_start, '-',
817 $seg->from_end, " project onto clone coords " .
818 $clone->seq_region_name, ':', $clone->start, '-', $clone->end,
819 $clone->strand, "\n";
820 }
821 Description: Returns the results of 'projecting' this feature onto another
822 coordinate system. This is useful to see where a feature
823 would lie in a coordinate system in which it
824 crosses a boundary.
825  
826 This method returns a reference to a list of
827 Bio::EnsEMBL::ProjectionSegment objects.
828 ProjectionSegments are blessed arrays and can also be used as
829 triplets [from_start,from_end,to_Slice]. The from_start and
830 from_end are the coordinates relative to the feature start.
831 For example, if a feature is current 100-200bp on a slice
832 then the triplets returned might be:
833 [1,50,$slice1],
834 [51,101,$slice2]
835  
836 The to_Slice is a slice spanning the region on the requested
837 coordinate system that this feature projected to.
838  
839 If the feature projects entirely into a gap then a reference to
840 an empty list is returned.
841  
842 Returntype : listref of Bio::EnsEMBL::ProjectionSegments
843 which can also be used as [$start,$end,$slice] triplets
844 Exceptions : slice does not have an adaptor
845 Caller : general
846 Status : Stable
847  
848 =cut
849  
850 sub project {
851 my $self = shift;
852 my $cs_name = shift;
853 my $cs_version = shift;
854  
855 my $slice = $self->{'slice'};
856  
857 if(!$slice) {
858 warning("Feature cannot be projected without attached slice.");
859 return [];
860 }
861  
862  
863 #get an adaptor from the attached slice because this feature may not yet
864 #be stored and may not have its own adaptor
865 my $slice_adaptor = $slice->adaptor();
866  
867 if(!$slice_adaptor) {
868 throw("Cannot project feature because associated slice does not have an " .
869 " adaptor");
870 }
871  
872 my $strand = $self->strand() * $slice->strand();
873 #fetch by feature always gives back forward strand slice:
874 $slice = $slice_adaptor->fetch_by_Feature($self);
875 $slice = $slice->invert if($strand == -1);
876 return $slice->project($cs_name, $cs_version);
877 }
878  
879  
880  
881 =head2 seqname
882  
883 Arg [1] : (optional) $seqname
884 Example : $seqname = $feat->seqname();
885 Description: Getter/Setter for the name of the sequence that this feature
886 is on. Normally you can get away with not setting this value
887 and it will default to the name of the slice on which this
888 feature is on. It is useful to set this value on features which
889 do not ordinarily sit on features such as ProteinFeatures which
890 sit on peptides.
891 Returntype : string
892 Exceptions : none
893 Caller : general
894 Status : Stable
895  
896 =cut
897  
898 sub seqname {
899 my $self = shift;
900
901 if(@_) {
902 $self->{'seqname'} = shift;
903 }
904  
905 if(!$self->{'seqname'} && $self->slice()) {
906 return $self->slice->name();
907 }
908  
909 return $self->{'seqname'};
910 }
911  
912  
913  
914  
915 =head2 display_id
916  
917 Arg [1] : none
918 Example : print $f->display_id();
919 Description: This method returns a string that is considered to be
920 the 'display' identifier. It is overridden by subclasses to
921 return an appropriate value for objects of that particular
922 class. If no appropriate display id is available an empty
923 string is returned instead.
924 Returntype : string
925 Exceptions : none
926 Caller : web drawing code
927 Status : Stable
928  
929 =cut
930  
931 sub display_id {
932 my $self = shift;
933 return '';
934 }
935  
936 =head2 version
937  
938 Arg [1] : none
939 Example : print $f->version();
940 Description: This method returns a string that is considered to be
941 the identifier version. It is overridden by subclasses to
942 return an appropriate value for objects of that particular
943 class. If no appropriate version is available an empty
944 string is returned instead.
945 Returntype : string
946 Exceptions : none
947 Caller : general
948 Status : Stable
949  
950 =cut
951  
952 sub version {
953 my $self = shift;
954 return '';
955 }
956  
957  
958 =head2 feature_Slice
959  
960 Args : none
961 Example : $slice = $feature->feature_Slice()
962 Description: This is a convenience method to return a slice that covers the
963 Area of this feature. The feature start will be at 1 on it, and
964 it will have the length of this feature.
965 Returntype : Bio::EnsEMBL::Slice or undef if this feature has no attached
966 Slice.
967 Exceptions : warning if Feature does not have attached slice.
968 Caller : web drawing code
969 Status : Stable
970  
971 =cut
972  
973 sub feature_Slice {
974 my $self = shift;
975  
976 my $slice = $self->slice();
977  
978 if(!$slice) {
979 warning('Cannot obtain Feature_Slice for feature without attached slice');
980 return undef;
981 }
982  
983 return Bio::EnsEMBL::Slice->new
984 (-seq_region_name => $slice->seq_region_name,
985 -seq_region_length => $slice->seq_region_length,
986 -coord_system => $slice->coord_system,
987 -start => $self->seq_region_start(),
988 -end => $self->seq_region_end(),
989 -strand => $self->seq_region_strand(),
990 -adaptor => $slice->adaptor());
991 }
992  
993  
994 =head2 seq_region_name
995  
996 Arg [1] : none
997 Example : print $feature->seq_region_name();
998 Description: Gets the name of the seq_region which this feature is on.
999 Returns undef if this Feature is not on a slice.
1000 Returntype : string or undef
1001 Exceptions : none
1002 Caller : general
1003 Status : Stable
1004  
1005 =cut
1006  
1007 sub seq_region_name {
1008 my $self = shift;
1009 my $slice = $self->{'slice'};
1010  
1011 return ($slice) ? $slice->seq_region_name() : undef;
1012 }
1013  
1014  
1015 =head2 seq_region_length
1016  
1017 Arg [1] : none
1018 Example : print $feature->seq_region_length();
1019 Description: Returns the length of the seq_region which this feature is on
1020 Returns undef if this Feature is not on a slice.
1021 Returntype : int (unsigned) or undef
1022 Exceptions : none
1023 Caller : general
1024 Status : Stable
1025  
1026 =cut
1027  
1028  
1029 sub seq_region_length {
1030 my $self = shift;
1031 my $slice = $self->{'slice'};
1032  
1033 return ($slice) ? $slice->seq_region_length() : undef;
1034 }
1035  
1036  
1037 =head2 seq_region_strand
1038  
1039 Arg [1] : none
1040 Example : print $feature->seq_region_strand();
1041 Description: Returns the strand of the seq_region which this feature is on
1042 (i.e. feature_strand * slice_strand)
1043 Returns undef if this Feature is not on a slice.
1044 Returntype : 1,0,-1 or undef
1045 Exceptions : none
1046 Caller : general
1047 Status : Stable
1048  
1049 =cut
1050  
1051  
1052 sub seq_region_strand {
1053 my $self = shift;
1054 my $slice = $self->{'slice'};
1055  
1056 return ($slice) ? $slice->strand() * $self->{'strand'} : undef;
1057 }
1058  
1059  
1060 =head2 seq_region_start
1061  
1062 Arg [1] : none
1063 Example : print $feature->seq_region_start();
1064 Description: Convenience method which returns the absolute start of this
1065 feature on the seq_region, as opposed to the relative (slice)
1066 position.
1067  
1068 Returns undef if this feature is not on a slice or slice is
1069 circular and cannot determine the position of the feature from
1070 the db.
1071 Returntype : int or undef
1072 Exceptions : none
1073 Caller : general
1074 Status : Stable
1075  
1076 =cut
1077  
1078 sub seq_region_start {
1079 my ($self) = @_;
1080  
1081 my $slice = $self->slice();
1082
1083 if ( defined($slice) ) {
1084 if ($slice->is_circular()) {
1085 return $self->adaptor->_seq_region_boundary_from_db($self, 'start')
1086 if $self->adaptor();
1087 return undef;
1088 }
1089
1090 my $start;
1091 if ( $slice->strand() == 1 ) {
1092 $start = $slice->start() + $self->start() - 1
1093 if defined $self->start();
1094 } else {
1095 $start = $slice->end() - $self->end() + 1
1096 if defined $self->end();
1097 }
1098
1099 return $start;
1100 }
1101  
1102 return undef;
1103 } ## end sub seq_region_start
1104  
1105  
1106 =head2 seq_region_end
1107  
1108 Arg [1] : none
1109 Example : print $feature->seq_region_end();
1110 Description: Convenience method which returns the absolute end of this
1111 feature on the seq_region, as opposed to the relative (slice)
1112 position.
1113  
1114 Returns undef if this feature is not on a slice or slice is
1115 circular and cannot determine the position of the feature from
1116 the db.
1117 Returntype : int or undef
1118 Exceptions : none
1119 Caller : general
1120 Status : Stable
1121  
1122 =cut
1123  
1124 sub seq_region_end {
1125 my ($self) = @_;
1126  
1127 my $slice = $self->slice();
1128  
1129 if ( defined($slice) ) {
1130 if ($slice->is_circular()) {
1131 return $self->adaptor->_seq_region_boundary_from_db($self, 'end')
1132 if $self->adaptor();
1133 return undef;
1134 }
1135  
1136 my $end;
1137 if ( $slice->strand() == 1 ) {
1138 $end = $slice->start() + $self->end() - 1
1139 if defined $self->end();
1140 } else {
1141 $end = $slice->end() - $self->start() + 1
1142 if defined $self->start()
1143 }
1144  
1145 return $end;
1146 }
1147  
1148 return undef;
1149 } ## end sub seq_region_end
1150  
1151  
1152 =head2 coord_system_name
1153  
1154 Arg [1] : none
1155 Example : print $feature->coord_system_name()
1156 Description: Gets the name of the coord_system which this feature is on.
1157 Returns undef if this Feature is not on a slice.
1158 Returntype : string or undef
1159 Exceptions : none
1160 Caller : general
1161 Status : Stable
1162  
1163 =cut
1164  
1165 sub coord_system_name {
1166 my $self = shift;
1167 my $slice = $self->{'slice'};
1168 return ($slice) ? $slice->coord_system_name() : undef;
1169 }
1170  
1171  
1172 =head2 seq
1173  
1174 Args : none
1175 Example : my $dna_sequence = $simple_feature->seq();
1176 Description: Returns the dna sequence from the attached slice and
1177 attached database that overlaps with this feature.
1178 Returns undef if there is no slice or no database.
1179 Returns undef if this feature is unstranded (i.e. strand=0).
1180 Returntype : String or undef
1181 Exceptions : warning if this feature is not stranded
1182 Caller : general
1183 Status : Stable
1184  
1185 =cut
1186  
1187  
1188 sub seq {
1189 my $self = shift;
1190  
1191 if( ! defined $self->{'slice'} ) {
1192 return undef;
1193 }
1194  
1195 if(!$self->strand()) {
1196 warning("Cannot retrieve sequence for unstranded feature.");
1197 return undef;
1198 }
1199  
1200 return $self->{'slice'}->subseq($self->start(), $self->end(),
1201 $self->strand());
1202  
1203 }
1204  
1205  
1206  
1207  
1208 =head2 get_all_alt_locations
1209  
1210 Arg [1] : Boolean override flag to force the method to return all
1211 Features on the reference sequence as well.
1212
1213 Example : @features = @{$feature->get_all_alt_locations()};
1214 foreach $f (@features) {
1215 print $f->slice->seq_region_name,' ',$f->start, $f->end,"\n";
1216 }
1217  
1218 Description: Retrieves shallow copies of this feature in its alternate
1219 locations. A feature can be considered to have multiple
1220 locations when it sits on a alternative structural haplotype
1221 or when it is on a Pseudo Autosomal Region. Most features will
1222 just return a reference to an empty list though.
1223 The features returned by this method will be on a slice which
1224 covers the entire alternate region.
1225  
1226 Currently this method does not take into account alternate
1227 locations on the alternate locations (e.g. a reference
1228 sequence may have multiple alternate haplotypes. Asking
1229 for alternate locations of a feature on one of the alternate
1230 haplotypes will give you back the reference location, but not
1231 locations on the other alternate haplotypes).
1232  
1233 Returntype : listref of features of the same type of this feature.
1234 Exceptions : none
1235 Caller : general
1236 Status : Stable
1237  
1238 =cut
1239  
1240 sub get_all_alt_locations {
1241 my $self = shift;
1242 my $return_all = shift || 0;
1243  
1244 my $slice = $self->{'slice'} or return [];
1245 my $sa = $slice->adaptor() or return [];
1246  
1247 # get slice of entire region
1248 $slice = $sa->fetch_by_seq_region_id($slice->get_seq_region_id);
1249  
1250 my $axfa = $sa->db->get_AssemblyExceptionFeatureAdaptor();
1251 my $axfs = $axfa->fetch_all_by_Slice($slice);
1252  
1253 my (@haps, @alt);
1254  
1255 foreach my $axf (@$axfs) {
1256 if(uc($axf->type()) eq 'HAP') {
1257 push @haps, $axf;
1258 } elsif(uc($axf->type()) =~ 'PAR') {
1259 push @alt, $axf;
1260 } elsif( $axf->type() eq "PATCH_FIX"){
1261 push @haps, $axf;
1262 } elsif( $axf->type() eq "PATCH_FIX REF"){
1263 push @haps, $axf if $return_all > 0 ;
1264 } elsif( $axf->type() eq "HAP REF" ) {
1265 push @haps, $axf if $return_all > 0 ;
1266 # do nothing when you are on REF
1267 } elsif( $axf->type() eq "PATCH_NOVEL"){
1268 push @haps, $axf;
1269 }elsif( $axf->type() eq "PATCH_NOVEL REF"){
1270 push @haps, $axf if $return_all > 0 ;
1271 } else {
1272 warning("Unknown exception feature type ". $axf->type()."- ignoring.");
1273 }
1274 }
1275  
1276 # regions surrounding hap are those of interest, not hap itself
1277 # convert hap alt. exc. features to regions around haps instead
1278 foreach my $h (@haps) {
1279 my $haslice = $h->alternate_slice();
1280 my $hacs = $haslice->coord_system();
1281  
1282 if($h->start() > 1 && $haslice->start() > 1) {
1283 my $aslice = $sa->fetch_by_region($hacs->name(),
1284 $haslice->seq_region_name(),
1285 1,
1286 $haslice->start()-1,
1287 $haslice->strand(),
1288 $hacs->version());
1289  
1290 push @alt, Bio::EnsEMBL::AssemblyExceptionFeature->new
1291 (-start => 1,
1292 -end => $h->start()-1,
1293 -alternate_slice => $aslice);
1294 }
1295  
1296 if($h->end() < $slice->seq_region_length() &&
1297 $haslice->end < $haslice->seq_region_length()) {
1298 my $aslice = $sa->fetch_by_region($hacs->name(),
1299 $haslice->seq_region_name(),
1300 $haslice->end()+1,
1301 $haslice->seq_region_length(),
1302 $haslice->strand(),
1303 $hacs->version());
1304  
1305 push @alt, Bio::EnsEMBL::AssemblyExceptionFeature->new
1306 (-start => $h->end() + 1,
1307 -end => $slice->seq_region_length(),
1308 -alternate_slice => $aslice);
1309 }
1310 }
1311  
1312  
1313 # check if exception regions contain our feature
1314  
1315 my @features;
1316  
1317 foreach my $axf (@alt) {
1318 # ignore other region if feature is not entirely on it
1319 next if($self->seq_region_start() < $axf->start() ||
1320 $self->seq_region_end() > $axf->end());
1321  
1322 # quick shallow copy of the feature
1323 my $f;
1324 %$f = %$self;
1325 bless $f, ref($self);
1326  
1327 my $aslice = $axf->alternate_slice();
1328  
1329 # position feature on entire slice of other region
1330
1331 # Cache seq_region_* to prevent contamination when changing feature coordinates.
1332 my $seq_region_start = $f->seq_region_start();
1333 my $seq_region_end = $f->seq_region_end();
1334
1335 $f->{'start'} = $seq_region_start - $axf->start() + $aslice->start();
1336 $f->{'end'} = $seq_region_end - $axf->start() + $aslice->start();
1337 $f->{'strand'} *= $aslice->strand();
1338  
1339 $f->{'slice'} = $sa->fetch_by_seq_region_id($aslice->get_seq_region_id());
1340  
1341 push @features, $f;
1342 }
1343  
1344 return \@features;
1345 }
1346  
1347  
1348 =head2 overlaps
1349  
1350 Arg [1] : Bio::EnsEMBL::Feature $f
1351 The other feature you want to check overlap with this feature
1352 for.
1353 Description: This method does a range comparison of this feature's C<seq_region_start> and
1354 C<seq_region_end> and compares it with another feature's C<seq_region_start>
1355 and C<seq_region_end>. It will return true if these ranges overlap
1356 and the features are on the same seq_region.
1357  
1358 For local coordinate overlaps tests (those values returned from
1359 start and end) use C<overlaps_local()>.
1360 Returntype : TRUE if features overlap, FALSE if they don't
1361 Exceptions : warning if features are on different seq_regions
1362 Caller : general
1363 Status : Stable
1364  
1365 =cut
1366  
1367 sub overlaps {
1368 my ($self, $f) = @_;
1369 my ($sr1, $sr2) = ($self->seq_region_name, $f->seq_region_name);
1370 if($sr1 && $sr2 && ($sr1 ne $sr2)) {
1371 warning("Bio::EnsEMBL::Feature->overlaps(): features are on different seq regions. \$self is on $sr1 and \$feature is on $sr2");
1372 return 0;
1373 }
1374 return ($self->seq_region_end >= $f->seq_region_start and $self->seq_region_start <= $f->seq_region_end) ? 1 : 0;
1375 }
1376  
1377 =head2 overlaps_local
1378  
1379 Arg [1] : Bio::EnsEMBL::Feature $f
1380 The other feature you want to check overlap with this feature
1381 for.
1382 Description: This method does a range comparison of this feature's start and
1383 end and compares it with another feature's start and end. It
1384 will return true if these ranges overlap and the features are
1385 on the same seq_region.
1386  
1387 This method will not attempt to resolve starts and ends with
1388 reference to the feature's backing Slice.
1389  
1390 For global coordinate overlaps tests (with reference to the feature's
1391 backing sequence region) use C<overlaps()>.
1392 Returntype : TRUE if features overlap, FALSE if they don't
1393 Exceptions : warning if features are on different seq_regions
1394 Caller : general
1395 Status : Stable
1396  
1397 =cut
1398  
1399 sub overlaps_local {
1400 my ($self, $f) = @_;
1401 my ($sr1, $sr2) = ($self->seq_region_name, $f->seq_region_name);
1402 if($sr1 && $sr2 && ($sr1 ne $sr2)) {
1403 warning("Bio::EnsEMBL::Feature->overlaps_local(): features are on different seq regions. \$self is on $sr1 and \$feature is on $sr2");
1404 return;
1405 }
1406 return ($self->end >= $f->start and $self->start <= $f->end) ? 1 : 0;
1407 }
1408  
1409 =head2 get_overlapping_Genes
1410 Arg [1] : Optional Boolean: Stranded match i.e. match strand of Feature and Genes
1411 Arg [2] : Optional Boolean: Get Genes with an overlapping 5' end
1412 Arg [3] : Optional Boolean: Get Genes with an overlapping 3' end
1413 Description: Get all the genes that overlap this feature.
1414 Returntype : list ref of Bio::EnsEMBL::Gene
1415 Caller : general
1416 Status : UnStable
1417  
1418 =cut
1419  
1420 sub get_overlapping_Genes{
1421 my ($self, $match_strands, $five_prime, $three_prime) = @_;
1422 my $ga = Bio::EnsEMBL::Registry->get_adaptor($self->species,'core','Gene');
1423 my $list = $ga->fetch_all_nearest_by_Feature(-FEATURE => $self, -RANGE => 0, -THREE_PRIME => $three_prime, -FIVE_PRIME => $five_prime, -MATCH_STRAND => $match_strands);
1424 return [ map { $_->[0] } @$list ];
1425 }
1426  
1427 # query for absolute nearest.
1428  
1429 =head2 get_nearest_Gene
1430  
1431 Description: Get the nearest genes to the feature
1432 Returntype : Bio::EnsEMBL::Gene or undef if none can be found nearby
1433 Caller : general
1434 Status : At risk
1435  
1436 =cut
1437  
1438 sub get_nearest_Gene {
1439 my $self = shift;
1440 my $ga = Bio::EnsEMBL::Registry->get_adaptor($self->species,'core','Gene');
1441 my $list = $ga->fetch_nearest_by_Feature($self);
1442 if ($list && @$list >0) {
1443 my ($gene, $distance) = @{ $list };
1444 return $gene;
1445 } else {
1446 return;
1447 }
1448 }
1449  
1450 =head2 feature_so_acc
1451  
1452 Description: This method returns a string containing the SO accession number of the feature
1453 Define constant SEQUENCE_ONTOLOGY in classes that require it, or override it for multiple possible values for a class.
1454 Returntype : String (Sequence Ontology accession number)
1455 Exceptions : Thrown if caller SEQUENCE_ONTOLOGY is undefined and is not a Bio::EnsEMBL::Feature
1456  
1457 =cut
1458  
1459 sub feature_so_acc {
1460 my ($self) = @_;
1461  
1462 my $ref = ref $self;
1463 my $so_acc;
1464  
1465 # Get the caller class SO acc
1466 eval {
1467 $so_acc = $ref->SEQUENCE_ONTOLOGY->{'acc'};
1468 };
1469  
1470 if (!$so_acc && $ref ne 'Bio::EnsEMBL::Feature' ) {
1471 throw( "constant SEQUENCE_ONTOLOGY in ${ref} is not defined");
1472 }
1473  
1474 return $so_acc // 'SO:0000001';
1475 }
1476  
1477 =head2 feature_so_term
1478  
1479 Description: This method returns a string containing the SO term of the feature
1480 Define constant SEQUENCE_ONTOLOGY in classes that require it, or override it for multiple possible values for a class.
1481 Returntype : String (Sequence Ontology term)
1482 Exceptions : Thrown if caller SEQUENCE_ONTOLOGY is undefined and is not a Bio::EnsEMBL::Feature
1483  
1484 =cut
1485  
1486 sub feature_so_term {
1487 my ($self) = @_;
1488  
1489 my $ref = ref $self;
1490 my $so_term;
1491  
1492 # Get the caller class SO acc
1493 eval {
1494 $so_term = $ref->SEQUENCE_ONTOLOGY->{'term'};
1495 };
1496  
1497 if (!$so_term && $ref ne 'Bio::EnsEMBL::Feature' ) {
1498 throw( "constant SEQUENCE_ONTOLOGY in ${ref} is not defined");
1499 }
1500  
1501 return $so_term // 'region';
1502 }
1503  
1504 =head2 summary_as_hash
1505  
1506 Example : $feature_summary = $feature->summary_as_hash();
1507 Description : Retrieves a textual summary of this Feature.
1508 Should be overidden by subclasses for specific tweaking
1509 Returns : hashref of arrays of descriptive strings
1510 Status : Intended for internal use
1511 =cut
1512  
1513 sub summary_as_hash {
1514 my $self = shift;
1515 my %summary;
1516 $summary{'id'} = $self->display_id;
1517 $summary{'version'} = $self->version() if $self->version();
1518 $summary{'start'} = $self->seq_region_start;
1519 $summary{'end'} = $self->seq_region_end;
1520 $summary{'strand'} = $self->strand;
1521 $summary{'seq_region_name'} = $self->seq_region_name;
1522 return \%summary;
1523 }
1524  
1525 =head2 species
1526  
1527 Example : $feature->species();
1528 Description : Shortcut to the feature's DBAdaptor and returns its species name
1529 Returntype : String the species name
1530 Exceptions : Thrown if there is no attached adaptor
1531 Caller : Webcode
1532  
1533 =cut
1534  
1535 sub species {
1536 my ($self) = @_;
1537 throw "Can only call this method if you have attached an adaptor" if ! $self->adaptor();
1538 return $self->adaptor()->db()->species();
1539 }
1540  
1541  
1542  
1543 =head2 sub_SeqFeature
1544  
1545 Deprecated - For genebuild backwards compatibility.
1546 Avoid using it if possible
1547 =cut
1548 sub sub_SeqFeature{
1549 my ($self) = @_;
1550 return @{$self->{'_gsf_sub_array'}} if($self->{'_gsf_sub_array'});
1551 }
1552  
1553 =head2 add_sub_SeqFeature
1554  
1555 Deprecated - only for genebuild backward compatibility.
1556 Avoid using it if possible
1557 =cut
1558 sub add_sub_SeqFeature{
1559 my ($self,$feat,$expand) = @_;
1560 my ($p, $f, $l) = caller;
1561 if( $expand eq 'EXPAND' ) {
1562 # if this doesn't have start/end set - forget it!
1563 if( ! $self->start && ! $self->end ) {
1564
1565 $self->start($feat->start());
1566 $self->end($feat->end());
1567 $self->strand($feat->strand);
1568 } else {
1569 if( $feat->start < $self->start ) {
1570 $self->start($feat->start);
1571 }
1572  
1573 if( $feat->end > $self->end ) {
1574 $self->end($feat->end);
1575 }
1576 }
1577 } else {
1578 if($self->start > $feat->start || $self->end < $feat->end) {
1579 throw("$feat is not contained within parent feature, " .
1580 "and expansion is not valid");
1581 }
1582 }
1583  
1584 push(@{$self->{'_gsf_sub_array'}},$feat);
1585 }
1586  
1587 =head2 flush_sub_SeqFeature
1588  
1589 Deprecated - Only for genebuild backwards compatibility.
1590 Avoid using it if possible
1591 =cut
1592 sub flush_sub_SeqFeature {
1593 my ($self) = @_;
1594 $self->{'_gsf_sub_array'} = [];
1595 }
1596  
1597  
1598 1;