ensembl-hive  2.7.0
SubSlicedFeature.pm
Go to the documentation of this file.
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 
34 
35 =head1 SYNOPSIS
36 
37 my $truncated_gene = Bio::EnsEMBL::Utils::SubSlicedFeature->new(
38  -start => 300,
39  -end => 10000,
40  -feature => $gene);
41 my $transcripts = $truncated_gene->get_all_Transcripts();
42 # list of transcripts is limited to those within the coordinates, rather
43 # than the original feature Slice.
44 
45 =head1 DESCRIPTION
46 
47  Alters the behaviour of a normal Feature object to act within a user-specified
48  sub-slice of of its boundaries. As it stands, this only affects get_all_*
49  methods, meaning that seq_region_start() and project() will work on original
50  coordinates.
51 
52 =cut
53 
54 package Bio::EnsEMBL::SubSlicedFeature;
55 
56 use strict;
57 use warnings;
58 
59 use Bio::EnsEMBL::Utils::Argument qw/rearrange/;
60 use base qw/Bio::EnsEMBL::Utils::Proxy/;
61 
62 sub new {
63  my ($class, @args) = @_;
64  my ($start,$end,$original_feature) = rearrange([qw/start end feature/], @args);
65  my $self = $class->SUPER::new($original_feature);
66  $self->{'start'} = $start;
67  $self->{'end'} = $end;
68  return $self;
69 }
70 
71 # Required by Proxy to control scope of the autoloaded methods.
72 # Also intercepts calls to get methods that would access Slice
73 
74 sub __resolver {
75  my ($self, $package_name, $method) = @_;
76 
77  if ($method =~ /^get_all_/) {
78  # Call original method and filter results to Proxy coordinates
79  return sub {
80  my ($local_self, @args) = @_;
81  my $feature_list = $local_self->__proxy()->$method(@args);
82  my @short_list;
83  foreach my $feature (@$feature_list) {
84  if ($feature->start > $local_self->{'start'}
85  && $feature->end < $local_self->{'end'}) {
86  push @short_list,$feature;
87  }
88  }
89  return \@short_list;
90  }
91  } else {
92  # No intervention required, call original object method
93  return sub {
94  my ($local_self, @args) = @_;
95  return $local_self->__proxy()->$method(@args);
96  };
97  }
98 
99 }
100 
101 1;
EnsEMBL
Definition: Filter.pm:1
Bio::EnsEMBL::Feature
Definition: Feature.pm:47
Bio::EnsEMBL::SubSlicedFeature::new
public new()
Bio
Definition: AltAlleleGroup.pm:4
Bio::EnsEMBL::SubSlicedFeature
Definition: SubSlicedFeature.pm:24