EnsEMBL/Map/DitagFeature.pm untested

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