| 1 | package Bio::Graphics::Glyph::decorated_gene; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use base 'Bio::Graphics::Glyph::decorated_transcript'; | ||
| 5 | |||
| 6 | sub extra_arrow_length { | ||
| 7 | my $self = shift; | ||
| 8 | return 0 unless $self->{level} == 1; | ||
| 9 | local $self->{level} = 0; # fake out superclass | ||
| 10 | return $self->SUPER::extra_arrow_length; | ||
| 11 | } | ||
| 12 | |||
| 13 | sub pad_left { | ||
| 14 | my $self = shift; | ||
| 15 | my $type = $self->feature->primary_tag; | ||
| 16 | return 0 unless $type =~ /gene|mRNA/; | ||
| 17 | $self->SUPER::pad_left; | ||
| 18 | } | ||
| 19 | |||
| 20 | sub pad_right { | ||
| 21 | my $self = shift; | ||
| 22 | return 0 unless $self->{level} < 2; # don't invoke this expensive call on exons | ||
| 23 | my $strand = $self->feature->strand; | ||
| 24 | $strand *= -1 if $self->{flip}; | ||
| 25 | my $pad = $self->SUPER::pad_right; | ||
| 26 | return $pad unless defined($strand) && $strand > 0; | ||
| 27 | my $al = $self->arrow_length; | ||
| 28 | return $al > $pad ? $al : $pad; | ||
| 29 | } | ||
| 30 | |||
| 31 | sub pad_bottom { | ||
| 32 | my $self = shift; | ||
| 33 | return 0 unless $self->{level} < 2; # don't invoke this expensive call on exons | ||
| 34 | return $self->SUPER::pad_bottom; | ||
| 35 | } | ||
| 36 | |||
| 37 | sub pad_top { | ||
| 38 | my $self = shift; | ||
| 39 | return 0 unless $self->{level} < 2; # don't invoke this expensive call on exons | ||
| 40 | return $self->SUPER::pad_top; | ||
| 41 | } | ||
| 42 | |||
| 43 | sub bump { | ||
| 44 | my $self = shift; | ||
| 45 | return 1 if $self->{level} == 0; # top level bumps, other levels don't unless specified in config | ||
| 46 | return $self->SUPER::bump; | ||
| 47 | } | ||
| 48 | |||
| 49 | sub label { | ||
| 50 | my $self = shift; | ||
| 51 | return unless $self->{level} < 2; | ||
| 52 | if ($self->label_transcripts && $self->{feature}->primary_tag eq 'mRNA') { # the mRNA | ||
| 53 | return $self->_label; | ||
| 54 | } else { | ||
| 55 | return $self->SUPER::label; | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 | sub label_position { | ||
| 60 | my $self = shift; | ||
| 61 | return 'top' if $self->{level} == 0; | ||
| 62 | return 'left'; | ||
| 63 | } | ||
| 64 | |||
| 65 | sub label_transcripts { | ||
| 66 | my $self = shift; | ||
| 67 | return $self->{label_transcripts} if exists $self->{label_transcripts}; | ||
| 68 | return $self->{label_transcripts} = $self->_label_transcripts; | ||
| 69 | } | ||
| 70 | |||
| 71 | sub _label_transcripts { | ||
| 72 | my $self = shift; | ||
| 73 | return $self->option('label_transcripts'); | ||
| 74 | } | ||
| 75 | |||
| 76 | sub draw_connectors { | ||
| 77 | my $self = shift; | ||
| 78 | return if $self->feature->primary_tag eq 'gene'; | ||
| 79 | $self->SUPER::draw_connectors(@_); | ||
| 80 | } | ||
| 81 | |||
| 82 | sub maxdepth { | ||
| 83 | my $self = shift; | ||
| 84 | my $md = $self->Bio::Graphics::Glyph::maxdepth; | ||
| 85 | return $md if defined $md; | ||
| 86 | return 2; | ||
| 87 | } | ||
| 88 | |||
| 89 | |||
| 90 | sub _subfeat { | ||
| 91 | my $class = shift; | ||
| 92 | my $feature = shift; | ||
| 93 | return $feature->get_SeqFeatures('mRNA') if $feature->primary_tag eq 'gene'; | ||
| 94 | |||
| 95 | my @subparts; | ||
| 96 | if ($class->option('sub_part')) { | ||
| 97 | @subparts = $feature->get_SeqFeatures($class->option('sub_part')); | ||
| 98 | } | ||
| 99 | else { | ||
| 100 | |||
| 101 | @subparts = $feature->get_SeqFeatures(qw(CDS five_prime_UTR three_prime_UTR UTR)); | ||
| 102 | } | ||
| 103 | |||
| 104 | # The CDS and UTRs may be represented as a single feature with subparts or as several features | ||
| 105 | # that have different IDs. We handle both cases transparently. | ||
| 106 | my @result; | ||
| 107 | foreach (@subparts) { | ||
| 108 | if ($_->primary_tag =~ /CDS|UTR/i) { | ||
| 109 | my @cds_seg = $_->get_SeqFeatures; | ||
| 110 | if (@cds_seg > 0) { push @result,@cds_seg } else { push @result,$_ } | ||
| 111 | } else { | ||
| 112 | push @result,$_; | ||
| 113 | } | ||
| 114 | } | ||
| 115 | return @result; | ||
| 116 | } | ||
| 117 | |||
| 118 | 1; | ||
| 119 | |||
| 120 | __END__ |