EnsEMBL/Map/DitagFeature.pm untested

filter: Statementstmt 0.0% 0 / 123 Branchbran 0.0% 0 / 62 Conditioncond 0.0% 0 / 36 MC/DCmcdc 0.0% 0 / 20 Subroutinesub 0.0% 0 / 22 Podpod 0.0% 0 / 17 totaltotal 0.0% 0 / 280 CC 32 SCAR 36.1
CC
32
Cov
0%
new
132.0
get_ditag_location
42.0
ditag
20.0
CRAP 36.8
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::Map::DitagFeature
34  
35 =head1 SYNOPSIS
36  
37 my $feature = Bio::EnsEMBL::Map::DitagFeature->new(
38 -slice => $slice,
39 -start => $qstart,
40 -end => $qend,
41 -strand => $qstrand,
42 -hit_start => $tstart,
43 -hit_end => $tend,
44 -hit_strand => $tstrand,
45 -ditag_id => $ditag_id,
46 -ditag_side => $ditag_side,
47 -ditag_pair_id => $ditag_pair_id,
48 -cigar_line => $cigar_line,
49 -analysis => $analysis,
50 );
51  
52 =head1 DESCRIPTION
53  
54 Represents a mapped ditag object in the EnsEMBL database. These are
55 the original tags separated into start ("L") and end ("R") parts if
56 applicable, successfully aligned to the genome. Two DitagFeatures
57 usually relate to one parent Ditag. Alternatively there are CAGE tags
58 e.g. which only have a 5\'tag ("F").
59  
60 =head1 METHODS
61  
62 =cut
63  
64 package Bio::EnsEMBL::Map::DitagFeature;
65 $Bio::EnsEMBL::Map::DitagFeature::VERSION = '114.0.0';
66 use strict;
67 use vars qw(@ISA);
68  
69  
70 use Bio::EnsEMBL::Feature;
71 use Bio::EnsEMBL::Utils::Exception qw( throw );
72 use Bio::EnsEMBL::Utils::Argument qw( rearrange );
73  
74 @ISA = qw(Bio::EnsEMBL::Feature);
75  
76 =head2 new
77  
78 Arg [1] : (optional) int dbID
79 Arg [2] : (optional) Bio::EnsEMBL::DitagFeatureAdaptor $adaptor
80 Arg [3] : int start
81 Arg [4] : int end
82 Arg [5] : int strand
83 Arg [6] : Bio::EnsEMBL::Slice $slice
84 Arg [7] : (optional) Bio::EnsEMBL::Analysis
85 Arg [8] : int hit_start
86 Arg [9] : int hit_end
87 Arg [10] : int hit_strand
88 Arg [11] : int ditag_id
89 Arg [12] : string ditag_side
90 Arg [13] : (optional) sring cigar_line
91 Arg [14] : (optional) int ditag_pair_id
92 Arg [15] : (optional) int tag_count, only used for imported mappings where
93 identical positions where collapsed into into one feature.
94 Default: 1
95 Arg [16] : (optional) ditag object
96  
97 Example : $ditag = Bio::EnsEMBL::Map::DitagFeature->new
98 (-dbID => 123, -adaptor => $adaptor, ...);
99 Description: Creates a new DitagFeature
100 Returntype : Bio::EnsEMBL::Map::DitagFeature
101 Caller : general
102 Status : At Risk
103  
104 =cut
105  
106 sub new {
107 my ($caller, @args) = @_;
108 my ( $dbID, $adaptor, $start, $end, $strand, $slice, $analysis, $hit_start, $hit_end,
109 $hit_strand, $ditag_id, $ditag_side, $cigar_line, $ditag_pair_id, $tag_count, $ditag ) =
110 rearrange( [ 'dbid', 'adaptor' ,'start', 'end', 'strand', 'slice', 'analysis', 'hit_start',
111 'hit_end', 'hit_strand', 'ditag_id', 'ditag_side', 'cigar_line', 'ditag_pair_id' ,'tag_count', 'ditag'],
112 @args );
113 my $class = ref($caller) || $caller;
114  
115 if($analysis) {
116 if(!ref($analysis) || !$analysis->isa('Bio::EnsEMBL::Analysis')) {
117 throw('-ANALYSIS argument must be a Bio::EnsEMBL::Analysis not '.
118 $analysis);
119 }
120 }
121 if(defined($strand)) {
122 if(!($strand =~ /^-?\d$/) or !($strand == 1) && !($strand == -1) && !($strand == 0)) {
123 throw('-STRAND argument must be 1, -1, or 0');
124 }
125 }
126 if(defined($hit_strand)) {
127 if(!($hit_strand == 1) && !($hit_strand == -1) && !($hit_strand == 0)) {
128 throw('-HIT_STRAND argument must be 1, -1, or 0 not '.$hit_strand);
129 }
130 }
131 if(defined($start) && defined($end)) {
132 if($end+1 < $start) {
133 throw('Start must be less than or equal to end+1.');
134 }
135 }
136 else{
137 throw('Need start and end location.');
138 }
139 if(!(defined($hit_start) && defined($hit_end))) {
140 throw('Need hit start and hit end location.');
141 }
142 if(!defined($tag_count) or (!$tag_count =~ /^[\d]+$/)){
143 $tag_count = 1;
144 }
145  
146 my $self = bless( {'dbID' => $dbID,
147 'analysis' => $analysis,
148 'slice' => $slice,
149 'start' => $start,
150 'end' => $end,
151 'strand' => $strand,
152 'hit_start' => $hit_start,
153 'hit_end' => $hit_end,
154 'hit_strand' => $hit_strand,
155 'ditag_id' => $ditag_id,
156 'ditag_pair_id' => $ditag_pair_id,
157 'ditag_side' => $ditag_side,
158 'cigar_line' => $cigar_line,
159 'tag_count' => $tag_count,
160 'ditag' => $ditag,
161 }, $class);
162  
163 $self->adaptor($adaptor);
164 return $self;
165 }
166  
167  
168 =head2 ditag
169  
170 Arg [1] : (optional) ditag object
171 Description: Get/Set the ditag object of this DitagFeature
172 Returntype : Bio::EnsEMBL::Map::Ditag
173 Exceptions : none
174 Caller : general
175 Status : At Risk
176  
177 =cut
178  
179 sub ditag {
180 my $self = shift;
181  
182 if(@_) {
183 $self->{'ditag'} = shift;
184 } elsif(!$self->{'ditag'}) {
185 if($self->{'ditag_id'}) {
186 #lazy load the ditag
187 my $ditag_adaptor = $self->analysis->adaptor->db->get_DitagAdaptor;
188 $self->{'ditag'} = $ditag_adaptor->fetch_by_dbID($self->ditag_id);
189 }
190 else{
191 throw "Could not get Ditag for DitagFeature ".$self->dbID;
192 }
193 }
194  
195 return($self->{'ditag'});
196 }
197  
198  
199 =head2 get_ditag_location
200  
201 Arg [1] : none
202 Description: Get the start and end location (and strand ) of the start-end pair
203 this DitagFeature belongs to.
204 If it is not a paired ditag, these will be identical
205 to DitagFeature->start() & DitagFeature->end().
206 Please note that the returned start/end are min/max locations.
207 Returntype : int (start, end, strand)
208 Exceptions : throws if the 2 features of a pair are found on different strands
209 or if the second one cannot be found.
210 Caller : general
211 Status : At Risk
212  
213 =cut
214  
215 sub get_ditag_location {
216 my $self = shift;
217  
218 my ($start, $end, $strand);
219 if($self->ditag_side eq "F"){
220 $start = $self->start;
221 $end = $self->end;
222 }
223 else{
224 my ($ditag_a, $ditag_b, $more);
225 eval{
226 ($ditag_a, $ditag_b, $more) = @{$self->adaptor->fetch_all_by_ditagID($self->ditag_id,
227 $self->ditag_pair_id,
228 $self->analysis->dbID)};
229 };
230 if($@ or !defined($ditag_a) or !defined($ditag_b)){
231 throw("Cannot find 2nd tag of pair (".$self->dbID.", ".$self->ditag_id.", ".
232 $self->ditag_pair_id.", ".$self->analysis->dbID.")\n".$@);
233 }
234 else{
235 # if(defined $more){
236 # throw("More than two DitagFeatures were returned for ".$self->dbID.", ".$self->ditag_id
237 # .", ".$self->ditag_pair_id);
238 # }
239  
240 ($ditag_a->start < $ditag_b->start) ? ($start = $ditag_a->start) : ($start = $ditag_b->start);
241 ($ditag_a->end > $ditag_b->end) ? ($end = $ditag_a->end) : ($end = $ditag_b->end);
242 if($ditag_a->strand != $ditag_b->strand){
243 throw('the strands of the two ditagFeatures are different! '.$ditag_a->strand.'/'.$ditag_b->strand);
244 }
245 }
246 }
247  
248 return($start, $end, $self->strand);
249 }
250  
251  
252 =head2 ditag_id
253  
254 Arg [1] : (optional) value
255 Description: Getter/Setter for the ditag_id
256 of this DitagFeature
257 Returntype : int
258 Exceptions : none
259 Caller : general
260 Status : At Risk
261  
262 =cut
263  
264 sub ditag_id {
265 my $self = shift;
266  
267 if(@_) {
268 $self->{'ditag_id'} = shift;
269 }
270  
271 return $self->{'ditag_id'};
272 }
273  
274 =head2 slice
275  
276 Arg [1] : (optional) value
277 Description: Getter/Setter for the slice
278 of this DitagFeature
279 Returntype : slice object
280 Exceptions : none
281 Caller : general
282 Status : At Risk
283  
284 =cut
285  
286 sub slice {
287 my $self = shift;
288  
289 if(@_) {
290 $self->{'slice'} = shift;
291 }
292  
293 return $self->{'slice'};
294 }
295  
296 =head2 ditag_pair_id
297  
298 Arg [1] : (optional) value
299 Description: Getter/Setter for the ditag_pair_id
300 of this DitagFeature
301 Returntype : int
302 Exceptions : none
303 Caller : general
304 Status : At Risk
305  
306 =cut
307 sub ditag_pair_id {
308 my $self = shift;
309  
310 if(@_) {
311 $self->{'ditag_pair_id'} = shift;
312 }
313  
314 return $self->{'ditag_pair_id'};
315 }
316  
317 =head2 ditag_side
318  
319 Arg [1] : (optional) value
320 Description: Getter/Setter for the ditag_side
321 of this DitagFeature
322 Returntype : string
323 Exceptions : none
324 Caller : general
325 Status : At Risk
326  
327 =cut
328  
329 sub ditag_side {
330 my $self = shift;
331  
332 if(@_) {
333 $self->{'ditag_side'} = shift;
334 }
335  
336 return $self->{'ditag_side'};
337 }
338  
339 =head2 hit_start
340  
341 Arg [1] : (optional) value
342 Description: Getter/Setter for the hit_start
343 of this DitagFeature
344 Returntype : int
345 Exceptions : none
346 Caller : general
347 Status : At Risk
348  
349 =cut
350  
351 sub hit_start {
352 my $self = shift;
353  
354 if(@_) {
355 $self->{'hit_start'} = shift;
356 }
357  
358 return $self->{'hit_start'};
359 }
360  
361 =head2 hit_end
362  
363 Arg [1] : (optional) value
364 Description: Getter/Setter for the hit_end
365 of this DitagFeature
366 Returntype : int
367 Exceptions : none
368 Caller : general
369 Status : At Risk
370  
371 =cut
372  
373 sub hit_end {
374 my $self = shift;
375  
376 if(@_) {
377 $self->{'hit_end'} = shift;
378 }
379  
380 return $self->{'hit_end'};
381 }
382  
383 =head2 hit_strand
384  
385 Arg [1] : (optional) value
386 Description: Getter/Setter for the hit_strand
387 of this DitagFeature
388 Returntype : 1/-1/0
389 Exceptions : none
390 Caller : general
391 Status : At Risk
392  
393 =cut
394  
395 sub hit_strand {
396 my $self = shift;
397  
398 if(@_) {
399 $self->{'hit_strand'} = shift;
400 }
401  
402 return $self->{'hit_strand'};
403 }
404  
405 =head2 cigar_line
406  
407 Arg [1] : (optional) value
408 Description: Getter/Setter for the cigar_line
409 of this DitagFeature
410 Returntype : string
411 Exceptions : none
412 Caller : general
413 Status : At Risk
414  
415 =cut
416  
417 sub cigar_line {
418 my $self = shift;
419  
420 if(@_) {
421 $self->{'cigar_line'} = shift;
422 }
423  
424 return $self->{'cigar_line'};
425 }
426  
427 =head2 start
428  
429 Arg [1] : (optional) value
430 Description: Getter/Setter for the start
431 of this DitagFeature
432 Returntype : int
433 Exceptions : none
434 Caller : general
435 Status : At Risk
436  
437 =cut
438  
439 sub start {
440 my $self = shift;
441  
442 if(@_) {
443 $self->{'start'} = shift;
444 }
445  
446 return $self->{'start'};
447 }
448  
449 =head2 end
450  
451 Arg [1] : (optional) value
452 Description: Getter/Setter for the end
453 of this DitagFeature
454 Returntype : int or string
455 Exceptions : none
456 Caller : general
457 Status : At Risk
458  
459 =cut
460  
461 sub end {
462 my $self = shift;
463  
464 if(@_) {
465 $self->{'end'} = shift;
466 }
467  
468 return $self->{'end'};
469 }
470  
471 =head2 strand
472  
473 Arg [1] : (optional) value
474 Description: Getter/Setter for the strand
475 of this DitagFeature
476 Returntype : 1/-1/0
477 Exceptions : none
478 Caller : general
479 Status : At Risk
480  
481 =cut
482  
483 sub strand {
484 my $self = shift;
485  
486 if(@_) {
487 $self->{'strand'} = shift;
488 }
489  
490 return $self->{'strand'};
491 }
492  
493 =head2 dbID
494  
495 Arg [1] : (optional) value
496 Description: Getter/Setter for the dbID
497 of this DitagFeature
498 Returntype : int
499 Exceptions : none
500 Caller : general
501 Status : At Risk
502  
503 =cut
504  
505 sub dbID {
506 my $self = shift;
507  
508 if(@_) {
509 $self->{'dbID'} = shift;
510 }
511  
512 return $self->{'dbID'};
513 }
514  
515 =head2 sequence
516  
517 Arg [1] : (optional) value
518 Description: Getter/Setter for the sequence
519 of this DitagFeature
520 Returntype : string
521 Exceptions : none
522 Caller : general
523 Status : At Risk
524  
525 =cut
526  
527 sub sequence {
528 my $self = shift;
529  
530 $self->{'sequence'} = $self->adaptor->sequence($self->dbID());
531  
532 return $self->{'sequence'};
533 }
534  
535  
536 =head2 tag_count
537  
538 Arg [1] : (optional) value
539 Description: Getter/Setter for the tag_count
540 of this DitagFeature
541 Returntype : string
542 Exceptions : none
543 Caller : general
544 Status : At Risk
545  
546 =cut
547  
548 sub tag_count {
549 my $self = shift;
550  
551 if(@_) {
552 $self->{'tag_count'} = shift;
553 }
554  
555 return $self->{'tag_count'};
556 }
557  
558 1;