decorated_gene.pm untested

filter: Statementstmt 0.0% 0 / 96 Branchbran 0.0% 0 / 56 Conditioncond 0.0% 0 / 27 MC/DCmcdc 0.0% 0 / 17 Subroutinesub 0.0% 0 / 18 Podpod 0.0% 0 / 15 totaltotal 0.0% 0 / 229 CC 29 SCAR 40.7
CC
29
Cov
0%
_subfeat
182.0
pad_right
30.0
label
12.0
CRAP 58.6
1 package Bio::Graphics::Glyph::decorated_gene;
2
3 use strict;
4 use vars qw($VERSION);
5 use base 'Bio::Graphics::Glyph::decorated_transcript';
6
7 $VERSION = '0.02';
8
9 sub my_descripton {
10 return <<END;
11 This glyph has the same functionality as Bio::Graphics::Glyph::gene, but uses
12 Bio::Graphics::Glyph::decorated_transcript instead of the
13 Bio::Graphics::Glyph::processed_transcript to render transcripts, which allows
14 sequence features to be highlighted on top of gene models. This functionality is for example
15 useful when one wants to assess how different splice forms of the same gene differ
16 in terms of encoded protein features, such as protein domains, signal peptides, or
17 transmembrane regions.
18
19 See Bio::Graphics::Glyph::decorated_transcript for a detailed description of how to
20 provide protein decorations for transcripts.
21 END
22 }
23
24 sub my_options {
25 {
26 label_transcripts => [
27 'boolean',
28 undef,
29 'If true, then the display_name of each transcript',
30 'will be drawn to the left of the transcript glyph.'],
31 thin_utr => [
32 'boolean',
33 undef,
34 'If true, UTRs will be drawn at 2/3 of the height of CDS segments.'],
35 utr_color => [
36 'color',
37 'grey',
38 'Color of UTR segments.'],
39 decorate_introns => [
40 'boolean',
41 undef,
42 'Draw chevrons on the introns to indicate direction of transcription.'
43 ],
44 }
45 }
46
47 sub extra_arrow_length {
48 my $self = shift;
49 return 0 unless $self->{level} == 1;
50 local $self->{level} = 0; # fake out superclass
51 return $self->SUPER::extra_arrow_length;
52 }
53
54 sub pad_left {
55 my $self = shift;
56 my $type = $self->feature->primary_tag;
57 return 0 unless $type =~ /gene|mRNA/;
58 $self->SUPER::pad_left;
59 }
60
61 sub pad_right {
62 my $self = shift;
63 return 0 unless $self->{level} < 2; # don't invoke this expensive call on exons
64 my $strand = $self->feature->strand;
65 $strand *= -1 if $self->{flip};
66 my $pad = $self->SUPER::pad_right;
67 return $pad unless defined($strand) && $strand > 0;
68 my $al = $self->arrow_length;
69 return $al > $pad ? $al : $pad;
70 }
71
72 sub pad_bottom {
73 my $self = shift;
74 return 0 unless $self->{level} < 2 || $self->is_utr; # don't invoke this expensive call on exons
75 return $self->SUPER::pad_bottom;
76 }
77
78 sub pad_top {
79 my $self = shift;
80 return 0 unless $self->{level} < 2 || $self->is_utr; # don't invoke this expensive call on exons
81 return $self->SUPER::pad_top;
82 }
83
84 sub bump {
85 my $self = shift;
86 my $bump;
87 if ($self->{level} == 0
88 && lc $self->feature->primary_tag eq 'gene'
89 && eval {($self->subfeat($self->feature))[0]->type =~ /RNA|pseudogene/i}) {
90 $bump = $self->option('bump');
91 } else {
92 $bump = $self->SUPER::bump;
93 }
94 return $bump;
95 }
96
97 sub label {
98 my $self = shift;
99 return unless $self->{level} < 2;
100 if ($self->label_transcripts && $self->{feature}->primary_tag =~ /RNA|pseudogene/i) {
101 return $self->_label;
102 } else {
103 return $self->SUPER::label;
104 }
105 }
106
107 sub label_position {
108 my $self = shift;
109 return 'top' if $self->{level} == 0;
110 return 'left';
111 }
112
113 sub label_transcripts {
114 my $self = shift;
115 return $self->{label_transcripts} if exists $self->{label_transcripts};
116 return $self->{label_transcripts} = $self->_label_transcripts;
117 }
118
119 sub _label_transcripts {
120 my $self = shift;
121 return $self->option('label_transcripts');
122 }
123
124 sub draw_connectors {
125 my $self = shift;
126 if ($self->feature->primary_tag eq 'gene') {
127 my @parts = $self->parts;
128 return if @parts && $parts[0]->feature->primary_tag =~ /rna|transcript|pseudogene/i;
129 }
130 $self->SUPER::draw_connectors(@_);
131 }
132
133 sub maxdepth {
134 my $self = shift;
135 my $md = $self->Bio::Graphics::Glyph::maxdepth;
136 return $md if defined $md;
137 return 2;
138 }
139
140
141 sub _subfeat {
142 my $class = shift;
143 my $feature = shift;
144
145 if ($feature->primary_tag =~ /^gene/i) {
146 my @transcripts;
147 # 2012-05-14 | CF | filtering for primary tag in get_SeqFeatures not working for GFF memory adaptor;
148 # all subfeatures are returned for every function call; using alternative function call
149 # to avoid duplication of transcripts
150 # for my $t (qw/mRNA tRNA snRNA snoRNA miRNA ncRNA pseudogene/) {
151 # push @transcripts, $feature->get_SeqFeatures($t);
152 # }
153 foreach my $t ($feature->get_SeqFeatures)
154 {
155 push(@transcripts, $t) if ($t->primary_tag =~ /mRNA|tRNA|snRNA|snoRNA|miRNA|ncRNA|pseudogene/);
156 }
157 # map { print " ".$_->id."\n" } @transcripts;
158 return @transcripts if @transcripts;
159 my @features = $feature->get_SeqFeatures; # no transcripts?! return whatever's there
160 return @features if @features;
161
162 # fall back to drawing a solid box if no subparts and level 0
163 return ($feature) if $class->{level} == 0;
164 }
165 elsif ($feature->primary_tag =~ /^CDS/i) {
166 my @parts = $feature->get_SeqFeatures();
167 return ($feature) if $class->{level} == 0 and !@parts;
168 return @parts;
169 }
170
171 my @subparts;
172 if ($class->option('sub_part')) {
173 @subparts = $feature->get_SeqFeatures($class->option('sub_part'));
174 }
175 elsif ($feature->primary_tag =~ /^mRNA/i) {
176 @subparts = $feature->get_SeqFeatures(qw(CDS five_prime_UTR three_prime_UTR UTR));
177 }
178 else {
179 @subparts = $feature->get_SeqFeatures('exon');
180 }
181
182 # The CDS and UTRs may be represented as a single feature with subparts or as several features
183 # that have different IDs. We handle both cases transparently.
184 my @result;
185 foreach (@subparts) {
186 if ($_->primary_tag =~ /CDS|UTR/i) {
187 my @cds_seg = $_->get_SeqFeatures;
188 if (@cds_seg > 0) { push @result,@cds_seg } else { push @result,$_ }
189 } else {
190 push @result,$_;
191 }
192 }
193 # fall back to drawing a solid box if no subparts and level 0
194 return ($feature) if $class->{level} == 0 && !@result;
195
196 return @result;
197 }
198
199 #sub _subfeat {
200 # my $class = shift;
201 # my $feature = shift;
202 # return $feature->get_SeqFeatures('mRNA') if $feature->primary_tag eq 'gene';
203 #
204 # my @subparts;
205 # if ($class->option('sub_part')) {
206 # @subparts = $feature->get_SeqFeatures($class->option('sub_part'));
207 # }
208 # else {
209 #
210 # @subparts = $feature->get_SeqFeatures(qw(CDS five_prime_UTR three_prime_UTR UTR));
211 # }
212 #
213 # # The CDS and UTRs may be represented as a single feature with subparts or as several features
214 # # that have different IDs. We handle both cases transparently.
215 # my @result;
216 # foreach (@subparts) {
217 # if ($_->primary_tag =~ /CDS|UTR/i) {
218 # my @cds_seg = $_->get_SeqFeatures;
219 # if (@cds_seg > 0) { push @result,@cds_seg } else { push @result,$_ }
220 # } else {
221 # push @result,$_;
222 # }
223 # }
224 # return @result;
225 #}
226
227 1;
228
229 __END__