blib/lib/Bio/Graphics/Glyph/transcript2.pm untested

filter: Statementstmt 0.0% 0 / 79 Branchbran 0.0% 0 / 50 Conditioncond 0.0% 0 / 29 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 175 CC 26 SCAR 40.1
CC
26
Cov
0%
draw_component
132.0
draw_connectors
42.0
extra_arrow_length
20.0
CRAP 55.1
1 package Bio::Graphics::Glyph::transcript2;
2  
3 use strict;
4 use base qw(Bio::Graphics::Glyph::transcript);
5  
6 use constant MIN_WIDTH_FOR_ARROW => 8;
7  
8 sub show_strand {
9 my $self = shift;
10 my $s = $self->SUPER::show_strand;
11 return $s if defined $s;
12 return 'ends';
13 }
14  
15 sub extra_arrow_length {
16 my $self = shift;
17 my $strand = $self->feature->strand || 0;
18 $strand *= -1 if $self->{flip};
19 my $first = $strand < 0 ? ($self->parts)[0]
20 : ($self->parts)[-1];
21 $first ||= $self;
22 my @rect = $first->bounds();
23 my $width = abs($rect[2] - $rect[0]);
24 return 0 if $width >= MIN_WIDTH_FOR_ARROW;
25 return $self->arrow_length;
26 }
27  
28 sub pad_left {
29 my $self = shift;
30 my $pad = $self->Bio::Graphics::Glyph::generic::pad_left;
31 return $pad if $self->feature->strand > 0;
32 my $extra_arrow_length = $self->extra_arrow_length;
33 if ($self->label_position eq 'left' && $self->label) {
34 return $extra_arrow_length+$pad;
35 } else {
36 return $extra_arrow_length > $pad ? $extra_arrow_length : $pad;
37 }
38 }
39  
40 sub pad_right {
41 my $self = shift;
42 my $pad = $self->Bio::Graphics::Glyph::generic::pad_right;
43 return $pad if $self->feature->strand < 0;
44 my $extra_arrow_length = $self->extra_arrow_length;
45 return $extra_arrow_length > $pad ? $extra_arrow_length : $pad;
46 }
47  
48 sub draw_connectors {
49 my $self = shift;
50 my ($gd,$dx,$dy) = @_;
51  
52 my $part;
53 my $strand = $self->feature->strand;
54 $strand *= -1 if $self->{flip}; #sigh
55 if (my @parts = $self->parts) {
56 $part = $strand >= 0 ? $parts[-1] : $parts[0];
57 } elsif ($self->feature_has_subparts) {
58 # no parts -- so draw an intron spanning whole thing
59 my($x1,$y1,$x2,$y2) = $self->bounds(0,0);
60 $self->_connector($gd,$dx,$dy,$x1,$y1,$x1,$y2,$x2,$y1,$x2,$y2);
61 $part = $self;
62 } else {
63 return;
64 }
65 my @rect = $part->bounds();
66 my $width = abs($rect[2] - $rect[0]);
67 my $filled = $width >= MIN_WIDTH_FOR_ARROW;
68  
69 if ($filled) {
70 $self->Bio::Graphics::Glyph::generic::draw_connectors(@_);
71 } else {
72 $self->SUPER::draw_connectors(@_);
73 }
74 }
75  
76 sub draw_component {
77 my $self = shift;
78 return unless $self->level > 0;
79  
80 my $gd = shift;
81 my ($left,$top) = @_;
82 my @rect = $self->bounds(@_);
83  
84 my $f = $self->feature;
85 my $strand = $f->strand;
86 my $str = $strand * ($self->{flip} ? -1 : 1);
87  
88 my $width = abs($rect[2] - $rect[0]);
89 my $filled = defined($self->{partno}) && $width >= MIN_WIDTH_FOR_ARROW;
90 my ($pwidth) = $gd->getBounds;
91 $filled = 0 if $str < 0 && $rect[0] < $self->panel->pad_left;
92 $filled = 0 if $str > 0 && $rect[2] > $pwidth - $self->panel->pad_right;
93  
94 if ($self->stranded && $filled) {
95 my ($first,$last) = ($self->{partno} == 0 , $self->{partno} == $self->{total_parts}-1);
96 ($first,$last) = ($last,$first) if $self->{flip};
97  
98 if ($strand < 0 && $first) { # first exon, minus strand transcript
99 $self->filled_arrow($gd,-1,@rect);
100 } elsif ($strand >= 0 && $last) { # last exon, plus strand
101 $self->filled_arrow($gd,+1,@rect);
102 } else {
103 $self->filled_box($gd,@rect);
104 }
105 }
106  
107 else {
108 $self->filled_box($gd,@rect);
109 }
110  
111 # copied from generic::draw_component
112 $self->draw_translation($gd,@_) if $self->{cds_translation}; # created earlier by calculate_cds()
113 $self->draw_sequence($gd,@_) if $self->option('draw_dna') && $self->dna_fits;
114 }
115  
116 sub bump {
117 my $self = shift;
118 return $self->SUPER::bump(@_) if $self->all_callbacks;
119 return 0; # never allow our components to bump
120 }
121  
122 1;
123  
124  
125 __END__