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

filter: Statementstmt 0.0% 0 / 89 Branchbran 0.0% 0 / 52 Conditioncond 0.0% 0 / 24 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 17 Podpod 0.0% 0 / 15 totaltotal 0.0% 0 / 197 CC 27 SCAR 39.0
CC
27
Cov
0%
_subfeat
156.0
extra_arrow_length
20.0
label
12.0
CRAP 49.5
1 package Bio::Graphics::Glyph::gene;
2  
3 use strict;
4 use base 'Bio::Graphics::Glyph::processed_transcript';
5  
6 sub my_descripton {
7 return <<END;
8 This glyph is used for drawing genes that may have
9 alternatively-spliced transcripts. The various isoforms are stacked on
10 top of each other and given a single label and description that apply
11 to the entire stack. Each individual transcript\'s name is optionally
12 printed to the left of the transcript glyph.
13  
14 Transcripts (splice isoforms) are drawn using the processed_transcript
15 glyph. CDS features are drawn in the background color, and the UTRs
16 are drawn in an alternate color selected by the utr_color option. In
17 addition, you can make the UTRs thinner than the CDS by setting the
18 "thin_utr" option.
19  
20 This glyph is designed to work properly with GFF3-style three-tier
21 genes, in which the top level feature has the Sequence Ontology type
22 of "gene", the second level feature(s) have the SO type "mRNA", and
23 the third level feature(s) have the SO type "CDS", "five_prime_utr"
24 and "three_prime_utr." Subparts named "UTR" are also honored. The
25 feature can contain other subparts as well (e.g. exon, intron,
26 translation), but they are currently ignored unless the option
27 sub_part is supplied. If the sub_part option is used that feature
28 type will be used and CDS and UTR features will be excluded.
29 This could be used for specifying that exons be used instead,
30 for example.
31  
32 This glyph is a subclass of processed_transcript, and recognizes the
33 same options.
34 END
35 }
36  
37 sub my_options {
38 {
39 label_transcripts => [
40 'boolean',
41 undef,
42 'If true, then the display_name of each transcript',
43 'will be drawn to the left of the transcript glyph.'],
44 thin_utr => [
45 'boolean',
46 undef,
47 'If true, UTRs will be drawn at 2/3 of the height of CDS segments.'],
48 utr_color => [
49 'color',
50 'grey',
51 'Color of UTR segments.'],
52 decorate_introns => [
53 'boolean',
54 undef,
55 'Draw chevrons on the introns to indicate direction of transcription.'
56 ],
57 }
58 }
59  
60 sub extra_arrow_length {
61 my $self = shift;
62 return 0 if $self->feature->primary_tag =~ /exon|utr/i;
63 return $self->SUPER::extra_arrow_length
64 unless $self->feature->primary_tag =~ /gene/;
65 return 0 unless $self->{level} == 1;
66 local $self->{level} = 0; # fake out superclass
67 return $self->SUPER::extra_arrow_length;
68 }
69  
70 sub pad_left {
71 my $self = shift;
72 my $type = $self->feature->primary_tag;
73 return 0 unless $type =~ /gene|mRNA|transcript/;
74 $self->SUPER::pad_left;
75 }
76  
77 sub pad_right {
78 my $self = shift;
79 return 0 unless $self->{level} < 2; # don't invoke this expensive call on exons
80 return $self->SUPER::pad_right;
81 }
82  
83 sub pad_bottom {
84 my $self = shift;
85 return 0 unless $self->{level} < 2 || $self->is_utr; # don't invoke this expensive call on exons
86 return $self->SUPER::pad_bottom;
87 }
88  
89 sub pad_top {
90 my $self = shift;
91 return 0 unless $self->{level} < 2 || $self->is_utr; # don't invoke this expensive call on exons
92 return $self->SUPER::pad_top;
93 }
94  
95 sub bump {
96 my $self = shift;
97 my $bump;
98 if ($self->{level} == 0
99 && lc $self->feature->primary_tag eq 'gene'
100 && eval {($self->subfeat($self->feature))[0]->type =~ /RNA|pseudogene/i}) {
101 $bump = $self->option('bump');
102 } else {
103 $bump = $self->SUPER::bump;
104 }
105 return $bump;
106 }
107  
108 sub label {
109 my $self = shift;
110 return unless $self->{level} < 2;
111 if ($self->{feature}->primary_tag =~ /rna|transcript|pseudogene/i && $self->label_transcripts) {
112 return $self->_label;
113 } else {
114 return $self->SUPER::label;
115 }
116 }
117  
118 sub label_position {
119 my $self = shift;
120 return 'top' if $self->{level} == 0;
121 return 'left';
122 }
123  
124 sub label_transcripts {
125 my $self = shift;
126 return $self->{label_transcripts} if exists $self->{label_transcripts};
127 return $self->{label_transcripts} = $self->_label_transcripts;
128 }
129  
130 sub _label_transcripts {
131 my $self = shift;
132 return $self->option('label_transcripts');
133 }
134  
135 sub draw_connectors {
136 my $self = shift;
137 if ($self->feature->primary_tag eq 'gene') {
138 my @parts = $self->parts;
139 return if @parts && $parts[0]->feature->primary_tag =~ /rna|transcript|pseudogene/i;
140 }
141 $self->SUPER::draw_connectors(@_);
142 }
143  
144 sub maxdepth {
145 my $self = shift;
146 my $md = $self->Bio::Graphics::Glyph::maxdepth;
147 return $md if defined $md;
148 return 2;
149 }
150  
151  
152 sub _subfeat {
153 my $class = shift;
154 my $feature = shift;
155  
156 if ($feature->primary_tag =~ /^gene/i) {
157 my @transcripts;
158 for my $t (qw/mRNA tRNA snRNA snoRNA miRNA ncRNA pseudogene/) {
159 push @transcripts, $feature->get_SeqFeatures($t);
160 }
161 return @transcripts if @transcripts;
162 my @features = $feature->get_SeqFeatures; # no transcripts?! return whatever's there
163 return @features if @features;
164  
165 # fall back to drawing a solid box if no subparts and level 0
166 return ($feature) if $class->{level} == 0;
167 }
168 elsif ($feature->primary_tag =~ /^CDS/i) {
169 my @parts = $feature->get_SeqFeatures();
170 return ($feature) if $class->{level} == 0 and !@parts;
171 return @parts;
172 }
173  
174 my @subparts;
175 if ($class->option('sub_part')) {
176 @subparts = $feature->get_SeqFeatures($class->option('sub_part'));
177 }
178 elsif ($feature->primary_tag =~ /^mRNA/i) {
179 @subparts = $feature->get_SeqFeatures(qw(CDS five_prime_UTR three_prime_UTR UTR));
180 }
181 else {
182 @subparts = $feature->get_SeqFeatures('exon');
183 }
184
185 # The CDS and UTRs may be represented as a single feature with subparts or as several features
186 # that have different IDs. We handle both cases transparently.
187 my @result;
188 foreach (@subparts) {
189 if ($_->primary_tag =~ /CDS|UTR/i) {
190 my @cds_seg = $_->get_SeqFeatures;
191 if (@cds_seg > 0) { push @result,@cds_seg } else { push @result,$_ }
192 } else {
193 push @result,$_;
194 }
195 }
196 # fall back to drawing a solid box if no subparts and level 0
197 return ($feature) if $class->{level} == 0 && !@result;
198  
199 return @result;
200 }
201  
202 1;
203  
204 __END__