EnsEMBL/PaddedSlice.pm untested

filter: Statementstmt 0.0% 0 / 67 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 6 Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 8 totaltotal 0.0% 0 / 108 CC 8 SCAR 34.0
CC
8
Cov
0%
subseq
72.0
new
2.0
start
2.0
CRAP 30.0
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::PaddedSlice
34  
35 =head1 DESCRIPTION
36  
37 Used when dumping Slices which represet a portion of the sequence region
38 they map to e.g. the first section of human Y. The code will return N
39 as sequence if an attempt is made to retrieve sequence not covered by the
40 Slice given. This makes the code very memory efficient if sequence dumping
41 is carried out using C<subseq()> calls.
42  
43 =head1 METHODS
44  
45 =cut
46  
47 package Bio::EnsEMBL::PaddedSlice;
48 $Bio::EnsEMBL::PaddedSlice::VERSION = '114.0.0_50'; # TRIAL
49 $Bio::EnsEMBL::PaddedSlice::VERSION = '114.0.050';
50 use strict;
51 use warnings;
52  
53 use Bio::EnsEMBL::Utils::Argument qw/rearrange/;
54 use Bio::EnsEMBL::Utils::Scalar qw/assert_ref assert_strand/;
55 use base qw/Bio::EnsEMBL::Utils::Proxy/;
56  
57 =head2 new()
58  
59 Arg [SLICE] : The Slice to proxy
60 Example : my $newobj = Bio::EnsEMBL::PaddedSlice->new($myobj);
61 Description : Provides a new instance of a padded slice
62 Returntype : Bio::EnsEMBL::PaddedSlice
63 Exceptions : None
64 Caller : public
65 Status : -
66  
67 =cut
68  
69 sub new {
70 my ($class, @args) = @_;
71 my ($slice) = rearrange([qw/slice/], @args);
72 return $class->SUPER::new($slice);
73 }
74  
75 =head2 start()
76  
77 Example : $slice->start();
78 Description : Always returns 1 since all padded slices start at 1
79 Returntype : Int
80 Exceptions : None
81 Caller : public
82 Status : -
83  
84 =cut
85  
86 sub start {
87 my ($self) = @_;
88 return 1;
89 }
90  
91 =head2 end()
92
93 Example : $slice->end();
94 Description : Always returns the backing slice sequence region length
95 Returntype : Int
96 Exceptions : None
97 Caller : public
98 Status : -
99  
100 =cut
101  
102 sub end {
103 my ($self) = @_;
104 return $self->seq_region_length();
105 }
106  
107 =head2 length()
108
109 Example : $slice->length();
110 Description : Delegates to C<end()>
111 Returntype : Int
112 Exceptions : None
113 Caller : public
114 Status : -
115  
116 =cut
117  
118 sub length {
119 my ($self) = @_;
120 return $self->end();
121 }
122  
123 =head2 seq()
124
125 Example : my $seq = $slice->seq()
126 Description : Returns the entire sequence of the backing slice but padded
127 with N's at the beginning and the end of the slice where
128 applicable
129 Returntype : Scalar string
130 Exceptions : None
131 Caller : public
132 Status : -
133  
134 =cut
135  
136 sub seq {
137 my ($self) = @_;
138 my $parent_slice = $self->__proxy();
139 my $pad_start = 'N' x ( $parent_slice->start() - 1 );
140 my $pad_end = 'N' x ( $parent_slice->seq_region_length() - $parent_slice->end() );
141 my $seq = $parent_slice->seq();
142 return $pad_start . $seq . $pad_end;
143 }
144  
145 =head2 subseq()
146
147 Arg [1] : Int; start position of the subslice
148 Arg [2] : Int; end position of the subslice
149 Arg [3] : Int; strand of the subslice
150 Example : my $subseq = $slice->subseq(1, 1_000_000);
151 Description : Returns a portion of the sequence padded with N's if required
152 Returntype : Scalar string
153 Exceptions : None
154 Caller : public
155 Status : -
156  
157 =cut
158  
159 sub subseq {
160 my ( $self, $start, $end, $strand ) = @_;
161  
162 if ( $end+1 < $start ) {
163 throw("End coord + 1 is less than start coord");
164 }
165
166 return '' if( $start == $end + 1);
167
168 $strand = 1 unless(defined $strand);
169 assert_strand($strand, 'strand');
170
171 my $parent_slice = $self->__proxy();
172
173 #Coords relative to the SeqRegion i.e. huge
174 my $parent_start = $parent_slice->start();
175 my $parent_end = $parent_slice->end();
176
177 #Return if we were upstream of overlap
178 if($start < $parent_start && $end < $parent_start) {
179 return 'N' x (( $end - $start )+1);
180 }
181 #Return if we were downstream of overlap
182 if($start > $parent_end && $end > $parent_end) {
183 return 'N' x (( $end - $start )+1);
184 }
185
186 my $prefix = '';
187 my $suffix = '';
188 my $subslice_start = ($start - $parent_start)+1;
189 my $subslice_end = ($end - $parent_start) + 1;
190 if($start < $parent_start) {
191 $prefix = 'N' x ($parent_start - $start);
192 $subslice_start = 1;
193 }
194 if($end > $parent_end) {
195 $suffix = 'N' x ($end - $parent_end);
196 $subslice_end = (($parent_end - $parent_start)+1);
197 }
198
199 my $subseq = $parent_slice->subseq($subslice_start, $subslice_end, $strand);
200
201 return $prefix . $subseq . $suffix;
202 }
203  
204 =head2 subseq()
205
206 Arg [1] : Int; start position of the subslice
207 Arg [2] : Int; end position of the subslice
208 Arg [3] : Int; strand of the subslice
209 Example : my $subseq = $slice->subseq(1, 1_000_000);
210 Description : Returns a portion of the sequence padded with N's if required
211 Returntype : Scalar string
212 Exceptions : None
213 Caller : public
214 Status : -
215  
216 =cut
217  
218 sub sub_Slice {
219 die "Unsupported";
220 }
221  
222  
223 =head2 __resolver()
224  
225 Description : Delegates all non-overriden actions onto the backing slice
226 Returntype : CodeRef
227 Exceptions : None
228 Caller : public
229 Status : -
230  
231 =cut
232  
233 sub __resolver {
234 my ($self, $package_name, $method) = @_;
235 return sub {
236 my ($local_self, @args) = @_;
237 return $local_self->__proxy()->$method(@args);
238 };
239 }
240  
241  
242 1;