~ubuntu-branches/ubuntu/raring/bioperl/raring

« back to all changes in this revision

Viewing changes to Bio/Graphics/Glyph/processed_transcript.pm

  • Committer: Bazaar Package Importer
  • Author(s): Charles Plessy
  • Date: 2008-03-18 14:44:57 UTC
  • mfrom: (4 hardy)
  • mto: This revision was merged to the branch mainline in revision 6.
  • Revision ID: james.westby@ubuntu.com-20080318144457-1jjoztrvqwf0gruk
* debian/control:
  - Removed MIA Matt Hope (dopey) from the Uploaders field.
    Thank you for your work, Matt. I hope you are doing well.
  - Downgraded some recommended package to the 'Suggests' priority,
    according to the following discussion on Upstream's mail list.
    http://bioperl.org/pipermail/bioperl-l/2008-March/027379.html
    (Closes: #448890)
* debian/copyright converted to machine-readable format.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
package Bio::Graphics::Glyph::processed_transcript;
2
2
 
3
 
# $Id: processed_transcript.pm,v 1.4 2003/09/17 17:11:30 lstein Exp $
 
3
# $Id: processed_transcript.pm,v 1.12.4.1 2006/10/02 23:10:20 sendu Exp $
4
4
 
5
5
use strict;
6
 
use Bio::Graphics::Glyph::transcript2;
7
 
use vars '@ISA';
8
 
@ISA = 'Bio::Graphics::Glyph::transcript2';
 
6
use base qw(Bio::Graphics::Glyph::transcript2);
9
7
use constant DEFAULT_UTR_COLOR => '#D0D0D0';
10
8
 
 
9
sub new {
 
10
  my $class = shift;
 
11
  my $self = $class->SUPER::new(@_);
 
12
  $self->guess_options if !defined $self->option('implied_utrs') 
 
13
    && !defined $self->option('adjust_exons');
 
14
  $self;
 
15
}
 
16
 
 
17
sub guess_options {
 
18
  my $self = shift;
 
19
  my ($exons,$utrs,$cds);
 
20
  foreach ($self->parts) {
 
21
    $exons++ if $_->feature->type =~ /exon/i;
 
22
    $utrs++  if $_->feature->type =~ /utr$/i;
 
23
    $cds++   if $_->feature->type =~ /^cds/i;
 
24
    $self->configure(implied_utrs=>1) if $exons && $cds && !$utrs;
 
25
    $self->configure(adjust_exons=>1) if $exons && $utrs;
 
26
  }
 
27
}
 
28
 
 
29
# this option will generate implied UTRs by subtracting the
 
30
# CDS features from the exons.
 
31
sub create_implied_utrs {
 
32
  my $self = shift;
 
33
  return if $self->{'.implied_utrs'}++;
 
34
 
 
35
  # parts should be ordered from left to right
 
36
  my @features = sort {$a->start <=> $b->start} map {$_->feature} $self->parts;
 
37
  my @exons   = grep {$_->type eq 'exon'} @features;
 
38
  my @cds     = grep {$_->type eq 'CDS'}  @features;
 
39
  my @old_utr = grep {$_->type =~ /UTR/}  @features;
 
40
 
 
41
  # if there are already UTRs then we don't modify anything
 
42
  return if @old_utr;
 
43
 
 
44
  # if exons or CDS features are missing, then we abandon ship
 
45
  return unless @exons && @cds;
 
46
 
 
47
  my $first_cds = $cds[0];
 
48
  my $last_cds  = $cds[-1];
 
49
  my $strand = $self->feature->strand;
 
50
 
 
51
  my $factory    = $self->factory;
 
52
 
 
53
  # make the left-hand UTRs
 
54
  for (my $i=0;$i<@exons;$i++) {
 
55
    my $start = $exons[$i]->start;
 
56
    last if $start >= $first_cds->start;
 
57
    my $end  = $first_cds->start > $exons[$i]->end ? $exons[$i]->end : $first_cds->start-1;
 
58
    my $utr = Bio::Graphics::Feature->new(-start=>$start,
 
59
                                          -end=>$end,
 
60
                                          -strand=>$strand,
 
61
                                          -type=>$strand >= 0 ? 'five_prime_UTR' : 'three_prime_UTR');
 
62
    unshift @{$self->{parts}},$factory->make_glyph($self->{level}+1,$utr);
 
63
  }
 
64
  # make the right-hand UTRs
 
65
  for (my $i=$#exons; $i>=0; $i--) {
 
66
    my $end = $exons[$i]->end;
 
67
    last if $end <= $last_cds->end;
 
68
    my $start = $last_cds->end < $exons[$i]->start ? $exons[$i]->start : $last_cds->end+1;
 
69
    my $utr = Bio::Graphics::Feature->new(-start=>$start,
 
70
                                          -end=>$end,
 
71
                                          -strand=>$strand,
 
72
                                          -type=>$strand >= 0 ? 'three_prime_UTR' : 'five_prime_UTR');
 
73
    push @{$self->{parts}},$factory->make_glyph($self->{level}+1,$utr);
 
74
  }
 
75
}
 
76
 
 
77
# Preprocess the glyph to remove overlaps between UTRs and
 
78
# exons.  The exons are clipped so that UTRs have precedence
 
79
sub adjust_exons {
 
80
  my $self = shift;
 
81
 
 
82
  return if $self->{'.adjust_exons'}++;
 
83
 
 
84
  # find everything that is not an exon (utrs and cds's)
 
85
  my @parts  = sort {$a->{left}<=>$b->{left}} $self->parts;
 
86
  my @exon   = grep {$_->feature->type =~ /exon/i} @parts;
 
87
  my %seen   = map {$_=>1} @exon;
 
88
  my @other  = grep {!$seen{$_}} @parts;
 
89
 
 
90
  my @clipped_parts;
 
91
  my %positions    = map {("$_->{left}:$_->{width}" =>1)} @other;
 
92
  my @unique_exons = grep {!$positions{"$_->{left}:$_->{width}"}} @exon;
 
93
 
 
94
  # the first and last exons may need to be clipped if they overlap
 
95
  # with another feature (CDS or UTR)
 
96
  my $first_exon = $unique_exons[0];
 
97
  my $last_exon  = $unique_exons[-1];
 
98
 
 
99
  # deal with left hand side first
 
100
  my $e_left    = $first_exon->{left};
 
101
  my $e_right   = $e_left + $first_exon->{width};
 
102
  for my $other (@other) {
 
103
    my $o_left  = $other->{left};
 
104
    my $o_right = $o_left + $other->{width};
 
105
    next if $e_left  > $o_right;
 
106
    last if $e_right < $o_left;
 
107
    #dgg- need to skip 3prime/right utr for 1exon; end same as exon
 
108
    last if (@unique_exons == 1 && $o_left > $e_left); #dgg- o_ is 3prime not 5
 
109
    # clip left hand side; may get clipped into oblivion!
 
110
    $first_exon->{left}  = $o_right + 1;
 
111
    $first_exon->{width} = $e_right - $first_exon->{left};
 
112
  }
 
113
 
 
114
  # deal with right hand side
 
115
  $e_left  = $last_exon->{left};
 
116
  $e_right = $e_left + $last_exon->{width};
 
117
  for (my $i=$#other; $i>=0; $i--) {
 
118
    my $o_left  = $other[$i]->{left};
 
119
    my $o_right = $o_left + $other[$i]->{width};
 
120
    next if $e_right < $o_left;
 
121
    last if $e_left  > $o_right;
 
122
    # clip right hand side; may get clipped into oblivion!
 
123
    #dgg- !! this always clips to oblivion: $last_exon->{width} = ($e_left - 1) - $last_exon->{left};
 
124
    $last_exon->{width} = $o_left - $last_exon->{left}; #dgg-
 
125
  }
 
126
 
 
127
  $self->{parts} =  [ grep {$_->width > 0} sort {$a->{left}<=>$b->{left}} (@other,@unique_exons)];
 
128
}
 
129
 
 
130
sub fixup_glyph {
 
131
  my $self = shift;
 
132
  return unless $self->level == 0;
 
133
  $self->create_implied_utrs if $self->option('implied_utrs');
 
134
  $self->adjust_exons        if $self->option('implied_utrs') || $self->option('adjust_exons');
 
135
}
 
136
 
 
137
sub draw {
 
138
  my $self = shift;
 
139
  $self->fixup_glyph();
 
140
  $self->SUPER::draw(@_);
 
141
}
 
142
 
 
143
sub boxes {
 
144
  my $self = shift;
 
145
  $self->fixup_glyph();
 
146
  $self->SUPER::boxes(@_);
 
147
}
 
148
 
11
149
sub is_utr {
12
150
  my $self = shift;
13
151
  return $self->feature->primary_tag =~ /UTR|untranslated_region/i;
51
189
}
52
190
 
53
191
 
 
192
sub _subfeat {
 
193
  my $self   = shift;
 
194
  return $self->SUPER::_subfeat(@_) unless ref($self) && $self->{level} == 0 && $self->option('one_cds');
 
195
  my $feature = shift;
 
196
 
 
197
  my @subparts = $feature->get_SeqFeatures(qw(CDS five_prime_UTR three_prime_UTR UTR));
 
198
 
 
199
  # The CDS and UTRs may be represented as a single feature with subparts or as several features
 
200
  # that have different IDs. We handle both cases transparently.
 
201
  my @result;
 
202
  foreach (@subparts) {
 
203
    if ($_->primary_tag =~ /CDS|UTR/i) {
 
204
      my @cds_seg = $_->get_SeqFeatures;
 
205
      if (@cds_seg > 0) { push @result,@cds_seg  } else { push @result,$_ }
 
206
    } else {
 
207
      push @result,$_;
 
208
    }
 
209
  }
 
210
  return @result;
 
211
}
 
212
 
54
213
1;
55
214
 
56
 
 
57
215
__END__
58
216
 
59
217
=head1 NAME
131
289
                 Draw strand with little arrows undef (false)
132
290
                 on the intron.
133
291
 
 
292
  -adjust_exons  Fix exons so that they don't   undef (false)
 
293
                 overlap UTRs
 
294
 
 
295
  -implied_utrs  Whether UTRs should be implied undef (false)
 
296
                 from exons and CDS features
 
297
 
 
298
  -one_cds       Some databases (e.g. FlyBase) represent their
 
299
                 transcripts as having a single CDS that is
 
300
                 broken up into multiple parts. Set this to
 
301
                 true to display this type of feature.
 
302
 
 
303
The B<-adjust_exons> option is needed to handle features in which the
 
304
exons (SO type "exon") overlaps with the UTRs (SO types
 
305
"five_prime_UTR" and "three_prime_UTR").  The exon parts of the glyph
 
306
will be clipped so that it doesn't overlap with the UTR parts.
 
307
 
 
308
The B<-implied_utrs> option is needed if there are no explicit UTR
 
309
features.  In this case, UTRs are derived by subtracting the positions
 
310
of "CDS" subfeatures from the positions of "exon" subfeatures.
 
311
B<-implied_utrs> implies the B<-adjust_exons> option.
 
312
 
134
313
=head1 BUGS
135
314
 
136
315
Please report them.