EnsEMBL/IntronSupportingEvidence.pm untested

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