EnsEMBL/IntronSupportingEvidence.pm untested

filter: Statementstmt 0.0% 0 / 110 Branchbran 0.0% 0 / 58 Conditioncond 0.0% 0 / 10 Subroutinesub 0.0% 0 / 18 Podpod 0.0% 0 / 11 totaltotal 0.0% 0 / 207 CC 30 SCAR 35.3
CC
30
Cov
0%
find_previous_Exon
72.0
find_next_Exon
72.0
new
42.0
CRAP 34.3
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 package Bio::EnsEMBL::IntronSupportingEvidence;
21 $Bio::EnsEMBL::IntronSupportingEvidence::VERSION = '114.0.0_50'; # TRIAL
22 $Bio::EnsEMBL::IntronSupportingEvidence::VERSION = '114.0.050';
23 =pod
24  
25  
26 =head1 CONTACT
27  
28 Please email comments or questions to the public Ensembl
29 developers list at <http://lists.ensembl.org/mailman/listinfo/dev>.
30  
31 Questions may also be sent to the Ensembl help desk at
32 <http://www.ensembl.org/Help/Contact>.
33  
34 =head1 NAME
35  
36 Bio::EnsEMBL::IntronSupportingEvidence
37  
38 =head1 DESCRIPTION
39  
40 Formalises an Intron with information about why it is a believed Intron. This
41 serves as a parallel object to Bio::EnsEMBL::Intron which you can use
42 to populate values in this field from. They are different objects though
43 due to Intron's non-existence as a DB data structure.
44  
45 =head1 SYNOPSIS
46  
47 #Example setups a ISE from the first two Exons
48 my ($five_prime_exon, $three_prime_exon) = @{$transcript->get_all_Exons()}[0..1];
49 my $intron = Bio::EnsEMBL::Intron->new($five_prime_exon, $three_prime_exon);
50  
51 =head1 METHODS
52  
53 =cut
54  
55  
56 use strict;
57 use warnings;
58 use base qw/Bio::EnsEMBL::Feature/;
59  
60 use Bio::EnsEMBL::Intron;
61 use Bio::EnsEMBL::Utils::Argument qw/rearrange/;
62 use Bio::EnsEMBL::Utils::Exception qw/throw/;
63 use Bio::EnsEMBL::Utils::Scalar qw/assert_ref/;
64  
65 our %SUPPORTED_TYPES = map { $_ => 1 } qw/NONE DEPTH/;
66  
67 =head2 new
68  
69 Arg [-ANALYSIS] : Bio::EnsEMBL::Analysis The analysis this intron is linked to
70 Arg [-START] : int - start postion of the IntronSupportingEvidence
71 Arg [-END] : int - end position of the IntronSupportingEvidence
72 Arg [-STRAND] : int - strand the IntronSupportingEvidence is on
73 Arg [-SLICE] : Bio::EnsEMBL::Slice - the slice the IntronSupportingEvidence is on
74 Arg [-INTRON] : Bio::EnsEMBL::Intron Intron the evidence is based
75 on. Useful if you are not specifying the location
76 parameters as we will take them from this
77 Arg [-HIT_NAME] : String The name of the hit
78 Arg [-SCORE] : Double The score associated with the supporting evidence
79 Arg [-SCORE_TYPE] : String The type of score we are representing
80 Example : Bio::EnsEMBL::IntronSupportingEvidence->new(
81 -ANALYSIS => $analysis, -INTRON => $intron,
82 -SCORE => 100, -SCORE_TYPE => 'DEPTH');
83 Description : Returns a new instance of this object
84 Returntype : Bio::EnsEMBL::IntronSupportEvidence
85 Exceptions : Thrown if data is not as requested
86  
87 =cut
88  
89 sub new {
90 my ($class, @args) = @_;
91
92 my $self = $class->SUPER::new(@args);
93
94 my ($intron, $hit_name, $score, $score_type, $is_splice_canonical) =
95 rearrange([qw/intron hit_name score score_type is_splice_canonical/], @args);
96
97 if($intron) {
98 $self->set_values_from_Intron($intron);
99 }
100 $self->hit_name($hit_name) if $hit_name;
101 $self->score($score) if $score;
102 $self->score_type($score_type) if $score_type;
103 $self->is_splice_canonical($is_splice_canonical) if $is_splice_canonical;
104
105 return $self;
106 }
107  
108 =head2 set_values_from_Intron
109  
110 Arg [1] : Bio::EnsEMBL::Intron The intron to base this object on
111 Example : $ise->set_values_from_Intron($intron);
112 Description : Sets the start, end, strand and slice of this ISE instance
113 using values from the given Intron object.
114 Returntype : None
115 Exceptions : Thrown if data is not as requested
116  
117 =cut
118  
119 sub set_values_from_Intron {
120 my ($self, $intron) = @_;
121 assert_ref($intron, 'Bio::EnsEMBL::Intron', 'intron');
122 $self->start($intron->start());
123 $self->end($intron->end());
124 $self->strand($intron->strand());
125 $self->slice($intron->slice());
126 $self->is_splice_canonical($intron->is_splice_canonical());
127 return;
128 }
129  
130 =head2 is_splice_canonical
131  
132 Arg [1] : Boolean
133 Example : $ise->is_splice_canonical(1);
134 Description : Getter/setter for is_splice_canonical. Splice canonical
135 indicates those Introns which have a splice junction which
136 is structured as expected
137 Returntype : Boolean
138 Exceptions :
139  
140 =cut
141  
142 sub is_splice_canonical {
143 my ($self, $is_splice_canonical) = @_;
144 $self->{'is_splice_canonical'} = $is_splice_canonical if defined $is_splice_canonical;
145 return $self->{'is_splice_canonical'};
146 }
147  
148 =head2 get_Intron
149  
150 Arg [1] : Bio::EnsEMBL::Transcript
151 Example : my $intron = $ise->intron($transcript);
152 Description : Provides access to an Intron object by using a given transcript
153 object and its associcated array of Exons.
154 Returntype : Bio::EnsEMBL::Intron
155 Exceptions : None
156  
157 =cut
158  
159 sub get_Intron {
160 my ($self, $transcript) = @_;
161 assert_ref($transcript, 'Bio::EnsEMBL::Transcript', 'transcript');
162 my $five_prime = $self->find_previous_Exon($transcript);
163 my $three_prime = $self->find_next_Exon($transcript);
164 return Bio::EnsEMBL::Intron->new($five_prime, $three_prime);
165 }
166  
167 =head2 hit_name
168  
169 Arg [1] : String name of the hit
170 Example : $ise->hit_name('hit');
171 Description : Getter/setter for hit name i.e. an identifier for the alignments
172 Returntype : String
173 Exceptions : None
174  
175 =cut
176  
177 sub hit_name {
178 my ($self, $hit_name) = @_;
179 $self->{'hit_name'} = $hit_name if defined $hit_name;
180 return $self->{'hit_name'};
181 }
182  
183 =head2 score
184  
185 Arg [1] : Number; the score associated with this feature
186 Example : $ise->score(100);
187 Description : Getter/setter for score
188 Returntype : Number
189 Exceptions : None
190  
191 =cut
192  
193 sub score {
194 my ($self, $score) = @_;
195 $self->{'score'} = $score if defined $score;
196 return $self->{'score'};
197 }
198  
199 =head2 score_type
200  
201 Arg [1] : String the enum type. Currently only allowed NONE or DEPTH
202 Example : $ise->score_type('DEPTH');
203 Description : Gets and sets the type of score this instance represents
204 Returntype : String
205 Exceptions : Thrown if given an unsupported type of data
206  
207 =cut
208  
209 sub score_type {
210 my ($self, $score_type) = @_;
211 if(defined $score_type) {
212 if(! $SUPPORTED_TYPES{$score_type}) {
213 my $values = join(q{, }, keys %SUPPORTED_TYPES);
214 throw "The score_type '$score_type' is not allowed. Allowed values are [${values}]";
215 }
216 }
217 $self->{'score_type'} = $score_type if defined $score_type;
218 return $self->{'score_type'};
219 }
220  
221 =head2 has_linked_transcripts
222  
223 Example : $ise->has_linked_transcripts();
224 Description : Returns true if we have transcripts linked to this ISE
225 Returntype : Boolean
226 Exceptions : Thrown if we do not have an attached adaptor
227  
228 =cut
229  
230 sub has_linked_transcripts {
231 my ($self) = @_;
232 throw "No attached adaptor. Cannot find linked Transcripts unless this is a persisted object" unless $self->adaptor();
233 my $transcript_ids = $self->adaptor()->list_linked_transcript_ids($self);
234 return scalar(@{$transcript_ids}) ? 1 : 0;
235 }
236  
237 =head2 equals
238  
239 Arg [1] : Bio::EnsEMBL::IntronSupportEvidence Object to compare to
240 Example : $ise->equals($another_ise);
241 Description : Asserts if the given IntronSupportEvidence instance was equal to this
242 Returntype : Boolean
243 Exceptions : None
244  
245 =cut
246  
247 sub equals {
248 my ($self, $other) = @_;
249 my $equal = $self->SUPER::equals($other);
250 return 0 if ! $equal;
251 return (
252 ($self->hit_name()||q{}) eq ($other->hit_name()||q{}) &&
253 ($self->score_type() eq $other->score_type()) &&
254 ($self->score() == $other->score())) ? 1 : 0;
255 }
256  
257 =head2 find_previous_Exon
258  
259 Arg [1] : Bio::EnsEMBL::Transcript Transcript to search for the Exons from
260 Example : $ise->find_previous_Exon($transcript);
261 Description : Loops through those Exons available from the Transcript and
262 attempts to find one which was the 5' flanking exon. If the
263 object has already been persisted we will use dbIDs to
264 find the Exons
265 Returntype : Bio::EnsEMBL::Exon
266 Exceptions : None
267  
268 =cut
269  
270 sub find_previous_Exon {
271 my ($self, $transcript) = @_;
272
273 #Use DB IDs if we have them
274 my $exon_id;
275 if($self->adaptor()) {
276 my @ids = $self->adaptor()->fetch_flanking_exon_ids($self, $transcript);
277 $exon_id = $ids[0] if @ids;
278 }
279
280 my $exons = $transcript->get_all_Exons();
281
282 my $start = $self->start();
283 my $end = $self->end();
284 foreach my $exon (@{$exons}) {
285 if($exon_id) {
286 return $exon if $exon->dbID() == $exon_id;
287 next;
288 }
289 if($self->strand() == 1) {
290 return $exon if $exon->end() == $start-1;
291 }
292 else {
293 return $exon if $exon->start() == $end+1;
294 }
295 }
296 return;
297 }
298  
299 =head2 find_next_Exon
300  
301 Arg [1] : Bio::EnsEMBL::Transcript Transcript to search for the Exons from
302 Example : $ise->find_next_Exon($transcript);
303 Description : Loops through those Exons available from the Transcript and
304 attempts to find one which was the 3' flanking exon. If the
305 object has already been persisted we will use dbIDs to
306 find the Exons
307 Returntype : Bio::EnsEMBL::Exon
308 Exceptions : None
309  
310 =cut
311  
312 sub find_next_Exon {
313 my ($self, $transcript) = @_;
314
315 #Use DB IDs if we have them
316 my $exon_id;
317 if($self->adaptor()) {
318 my @ids = $self->adaptor()->fetch_flanking_exon_ids($self, $transcript);
319 $exon_id = $ids[1] if @ids;
320 }
321
322 my $exons = $transcript->get_all_Exons();
323 my $start = $self->start();
324 my $end = $self->end();
325 foreach my $exon (@{$exons}) {
326 if($exon_id) {
327 return $exon if $exon->dbID() == $exon_id;
328 next;
329 }
330 if($self->strand() == 1) {
331 return $exon if $exon->start() == $end+1;
332 }
333 else {
334 return $exon if $exon->end() == $start-1;
335 }
336 }
337 return;
338 }
339  
340 1;