0
|
1 =head1 LICENSE
|
|
2
|
|
3 Copyright (c) 1999-2012 The European Bioinformatics Institute and
|
|
4 Genome Research Limited. All rights reserved.
|
|
5
|
|
6 This software is distributed under a modified Apache license.
|
|
7 For license details, please see
|
|
8
|
|
9 http://www.ensembl.org/info/about/code_licence.html
|
|
10
|
|
11 =head1 CONTACT
|
|
12
|
|
13 Please email comments or questions to the public Ensembl
|
|
14 developers list at <dev@ensembl.org>.
|
|
15
|
|
16 Questions may also be sent to the Ensembl help desk at
|
|
17 <helpdesk@ensembl.org>.
|
|
18
|
|
19 =cut
|
|
20
|
|
21 =head1 NAME
|
|
22
|
|
23 Bio::EnsEMBL::PaddedSlice
|
|
24
|
|
25 =head1 DESCRIPTION
|
|
26
|
|
27 Used when dumping Slices which represet a portion of the sequence region
|
|
28 they map to e.g. the first section of human Y. The code will return N
|
|
29 as sequence if an attempt is made to retrieve sequence not covered by the
|
|
30 Slice given. This makes the code very memory efficient if sequence dumping
|
|
31 is carried out using C<subseq()> calls.
|
|
32
|
|
33 =head1 METHODS
|
|
34
|
|
35 =cut
|
|
36
|
|
37 package Bio::EnsEMBL::PaddedSlice;
|
|
38
|
|
39 use Bio::EnsEMBL::Utils::Argument qw/rearrange/;
|
|
40 use Bio::EnsEMBL::Utils::Scalar qw/assert_ref assert_strand/;
|
|
41 use base qw/Bio::EnsEMBL::Utils::Proxy/;
|
|
42
|
|
43 =head2 new()
|
|
44
|
|
45 Arg [SLICE] : The Slice to proxy
|
|
46 Example : my $newobj = Bio::EnsEMBL::PaddedSlice->new($myobj);
|
|
47 Description : Provides a new instance of a padded slice
|
|
48 Returntype : Bio::EnsEMBL::PaddedSlice
|
|
49 Exceptions : None
|
|
50 Caller : public
|
|
51 Status : -
|
|
52
|
|
53 =cut
|
|
54
|
|
55 sub new {
|
|
56 my ($class, @args) = @_;
|
|
57 my ($slice) = rearrange([qw/slice/], @args);
|
|
58 return $class->SUPER::new($slice);
|
|
59 }
|
|
60
|
|
61 =head2 start()
|
|
62
|
|
63 Example : $slice->start();
|
|
64 Description : Always returns 1 since all padded slices start at 1
|
|
65 Returntype : Int
|
|
66 Exceptions : None
|
|
67 Caller : public
|
|
68 Status : -
|
|
69
|
|
70 =cut
|
|
71
|
|
72 sub start {
|
|
73 my ($self) = @_;
|
|
74 return 1;
|
|
75 }
|
|
76
|
|
77 =head2 end()
|
|
78
|
|
79 Example : $slice->end();
|
|
80 Description : Always returns the backing slice sequence region length
|
|
81 Returntype : Int
|
|
82 Exceptions : None
|
|
83 Caller : public
|
|
84 Status : -
|
|
85
|
|
86 =cut
|
|
87
|
|
88 sub end {
|
|
89 my ($self) = @_;
|
|
90 return $self->seq_region_length();
|
|
91 }
|
|
92
|
|
93 =head2 length()
|
|
94
|
|
95 Example : $slice->length();
|
|
96 Description : Delegates to C<end()>
|
|
97 Returntype : Int
|
|
98 Exceptions : None
|
|
99 Caller : public
|
|
100 Status : -
|
|
101
|
|
102 =cut
|
|
103
|
|
104 sub length {
|
|
105 my ($self) = @_;
|
|
106 return $self->end();
|
|
107 }
|
|
108
|
|
109 =head2 seq()
|
|
110
|
|
111 Example : my $seq = $slice->seq()
|
|
112 Description : Returns the entire sequence of the backing slice but padded
|
|
113 with N's at the beginning and the end of the slice where
|
|
114 applicable
|
|
115 Returntype : Scalar string
|
|
116 Exceptions : None
|
|
117 Caller : public
|
|
118 Status : -
|
|
119
|
|
120 =cut
|
|
121
|
|
122 sub seq {
|
|
123 my ($self) = @_;
|
|
124 my $parent_slice = $self->__proxy();
|
|
125 my $pad_start = 'N' x ( $parent_slice->start() - 1 );
|
|
126 my $pad_end = 'N' x ( $parent_slice->seq_region_length() - $parent_slice->end() );
|
|
127 my $seq = $parent_slice->seq();
|
|
128 return $pad_start . $seq . $pad_end;
|
|
129 }
|
|
130
|
|
131 =head2 subseq()
|
|
132
|
|
133 Arg [1] : Int; start position of the subslice
|
|
134 Arg [2] : Int; end position of the subslice
|
|
135 Arg [3] : Int; strand of the subslice
|
|
136 Example : my $subseq = $slice->subseq(1, 1_000_000);
|
|
137 Description : Returns a portion of the sequence padded with N's if required
|
|
138 Returntype : Scalar string
|
|
139 Exceptions : None
|
|
140 Caller : public
|
|
141 Status : -
|
|
142
|
|
143 =cut
|
|
144
|
|
145 sub subseq {
|
|
146 my ( $self, $start, $end, $strand ) = @_;
|
|
147
|
|
148 if ( $end+1 < $start ) {
|
|
149 throw("End coord + 1 is less than start coord");
|
|
150 }
|
|
151
|
|
152 return '' if( $start == $end + 1);
|
|
153
|
|
154 $strand = 1 unless(defined $strand);
|
|
155 assert_strand($strand, 'strand');
|
|
156
|
|
157 my $parent_slice = $self->__proxy();
|
|
158
|
|
159 #Coords relative to the SeqRegion i.e. huge
|
|
160 my $parent_start = $parent_slice->start();
|
|
161 my $parent_end = $parent_slice->end();
|
|
162
|
|
163 #Return if we were upstream of overlap
|
|
164 if($start < $parent_start && $end < $parent_start) {
|
|
165 return N x (( $end - $start )+1);
|
|
166 }
|
|
167 #Return if we were downstream of overlap
|
|
168 if($start > $parent_end && $end > $parent_end) {
|
|
169 return N x (( $end - $start )+1);
|
|
170 }
|
|
171
|
|
172 my $prefix = '';
|
|
173 my $suffix = '';
|
|
174 my $subslice_start = ($start - $parent_start)+1;
|
|
175 my $subslice_end = ($end - $parent_start) + 1;
|
|
176 if($start < $parent_start) {
|
|
177 $prefix = N x ($parent_start - $start);
|
|
178 $subslice_start = 1;
|
|
179 }
|
|
180 if($end > $parent_end) {
|
|
181 $suffix = N x ($end - $parent_end);
|
|
182 $subslice_end = (($parent_end - $parent_start)+1);
|
|
183 }
|
|
184
|
|
185 my $subseq = $parent_slice->subseq($subslice_start, $subslice_end, $strand);
|
|
186
|
|
187 return $prefix . $subseq . $suffix;
|
|
188 }
|
|
189
|
|
190 =head2 subseq()
|
|
191
|
|
192 Arg [1] : Int; start position of the subslice
|
|
193 Arg [2] : Int; end position of the subslice
|
|
194 Arg [3] : Int; strand of the subslice
|
|
195 Example : my $subseq = $slice->subseq(1, 1_000_000);
|
|
196 Description : Returns a portion of the sequence padded with N's if required
|
|
197 Returntype : Scalar string
|
|
198 Exceptions : None
|
|
199 Caller : public
|
|
200 Status : -
|
|
201
|
|
202 =cut
|
|
203
|
|
204 sub sub_Slice {
|
|
205 die "Unsupported";
|
|
206 }
|
|
207
|
|
208
|
|
209 =head2 __resolver()
|
|
210
|
|
211 Description : Delegates all non-overriden actions onto the backing slice
|
|
212 Returntype : CodeRef
|
|
213 Exceptions : None
|
|
214 Caller : public
|
|
215 Status : -
|
|
216
|
|
217 =cut
|
|
218
|
|
219 sub __resolver {
|
|
220 my ($self, $package_name, $method) = @_;
|
|
221 return sub {
|
|
222 my ($local_self, @args) = @_;
|
|
223 return $local_self->__proxy()->$method(@args);
|
|
224 };
|
|
225 }
|
|
226
|
|
227
|
|
228 1;
|