2 # bioperl module for Bio::LiveSeq::AARange
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Joseph Insana <insana@ebi.ac.uk> <jinsana@gmx.net>
8 # Copyright Joseph Insana
10 # You may distribute this module under the same terms as perl itself
12 # POD documentation - main docs before the code
16 Bio::LiveSeq::AARange - AARange abstract class for LiveSeq
24 This is used as possible parent for aminoacid range object classes.
25 Or it can be used straight away to define aminoacid ranges. The idea
26 is that the ranges defined are attached to a Translation object and
27 they refer to its coordinate-system when they are first created (via
28 the new() method). When they are created they are anyway linked to
29 the underlying DNA LiveSeq by way of the LiveSeq labels. This allows
30 to preserve the ranges even if the numbering changes in the
31 Translation due to deletions or insertions.
33 The protein sequence associated with the AARange can be accessed via
34 the usual seq() or subseq() methods.
36 The start and end of the AARange in protein coordinate system can be
37 fetched with aa_start() and aa_end() methods. Note: the behaviour of
38 these methods would be influenced by the coordinate_start set in the
39 corresponding Translation object. This can be desirable but can also
40 lead to confusion if the coordinate_start had been changed and the
41 original position of the AARange was to be retrieved.
43 start() and end() methods of the AARange will point to the labels
44 identifying the first nucleotide of the first and last triplet coding
45 for the start and end of the AminoAcidRange.
47 The underlying nucleotide sequence of the AARange can be retrieved
48 with the labelsubseq() method. This would retrieve the whole DNA
49 sequence, including possible introns. This is called "DNA_sequence".
51 To fetch the nucleotide sequence of the Transcript, without introns,
52 the labelsubseq() of the attached Transcript (the Transcript the
53 Translation comes from) has to be accessed. This is called
56 Here are the operations to retrieve these latter two kinds of
59 $startlabel=$AARange->start;
60 $endtripletlabel=$AARange->end;
61 $endlabel=$AARange->{'seq'}->label(3,$endtripletlabel,$AARange->strand);
63 $dnaseq=$AARange->labelsubseq($startlabel,undef,$endlabel));
65 $cdnaseq=$AARange->get_Transcript->labelsubseq($startlabel,undef,$endlabel);
67 To simplify, these operations have been included in two additional
68 methods: dna_seq() and cdna_seq().
70 These would return the whole sequence, as in the examples above. But
71 the above general scheme can be used by specifying different labels,
72 to retrieve hypothetical subsequences of interest.
74 =head1 AUTHOR - Joseph A.L. Insana
76 Email: Insana@ebi.ac.uk, jinsana@gmx.net
80 The rest of the documentation details each of the object
81 methods. Internal methods are usually preceded with a _
85 # Let the code begin...
87 package Bio
::LiveSeq
::AARange
;
90 use base
qw(Bio::LiveSeq::SeqI);
95 Usage : $aarange = Bio::LiveSeq::AARange->new(-translation => $obj_ref,
99 -description => "DCBA",
100 -translength => $length);
102 Function: generates a new AminoAcidRange LiveSeq object
103 Returns : reference to a new object of class AARange
105 Args : two positions in AminoAcid coordinate numbering
106 an object reference specifying to which translation the aminoacid
108 a name and a description (optional)
109 an optional "translength" argument: this can be given when
110 a lot of AARanges are to be created at the same time for the same
111 Translation object, calculating it with $translation->length
112 This would increase the speed, avoiding the new() function to
113 calculate everytime the same length again and again for every obj.
118 my ($thing, %args) = @_;
119 my $class = ref($thing) || $thing;
123 $obj = bless $obj, $class;
126 my ($translation,$start,$end,$name,$description,$translength)=($args{-translation
},$args{-start
},$args{-end
},$args{-name
},$args{-description
},$args{-translength
});
128 unless (($translation)&&(ref($translation) eq "Bio::LiveSeq::Translation")) {
129 $self->warn("No -translation or wrong type given");
132 unless ($translength) { # if it's not given, fetch it
133 $translength=$translation->length;
135 my $seq=$translation->{'seq'};
137 if (($start < 1)&&($start > $translength)) {
138 $self->warn("$class not initialised because start aminoacid position not valid");
141 if (($end < 1)&&($end > $translength)) {
142 $self->warn("$class not initialised because end aminoacid position not valid");
146 $self->warn("$class not initialised because start position > end position!");
150 my ($starttripletlabel,$endtripletlabel);
151 if ($start == $end) { # trick to increase speed
152 $starttripletlabel=$endtripletlabel=$translation->label($start);
154 ($starttripletlabel,$endtripletlabel)=($translation->label($start),$translation->label($end));
156 unless (($starttripletlabel > 0)&&($endtripletlabel > 0)) {
157 $self->warn("$class not initialised because of problems in retrieving start or end label!");
162 #my $endlabel=$seq->label(3,$endtripletlabel); # to get the real end
163 #unless ($endlabel > 0) {
164 #carp "$class not initialised because of problems retrieving the last nucleotide of the triplet coding for the end aminoacid";
168 $self->{'start'}=$starttripletlabel;
169 $self->{'end'}=$endtripletlabel;
170 $self->{'strand'}=$translation->strand;
171 $self->{'translation'}=$translation;
172 $self->{'name'}=$name;
173 $self->{'description'}=$description;
174 $self->{'alphabet'}="protein";
179 sub coordinate_start
{
181 $self->warn("Cannot perform this operation in an AminoAcidRange object!");
187 $self->warn("Cannot perform this operation in an AminoAcidRange object!");
193 $self->warn("Cannot perform this operation in an AminoAcidRange object!");
197 =head2 get_Transcript
200 Usage : $transcript = $obj->get_Transcript()
201 Function: retrieves the reference to the object of class Transcript (if any)
202 attached to a LiveSeq object
203 Returns : object reference
210 return ($self->get_Translation->get_Transcript);
213 =head2 get_Translation
216 Usage : $translation = $obj->get_Translation()
217 Function: retrieves the reference to the object of class Translation (if any)
218 attached to a LiveSeq object
219 Returns : object reference
224 sub get_Translation
{
226 return ($self->{'translation'});
231 $self->warn("Cannot change an AminoAcidRange object!");
236 $self->warn("Cannot change an AminoAcidRange object!");
241 $self->warn("Cannot change an AminoAcidRange object!");
246 my ($self,$pos1,$pos2,$length) = @_;
247 if (defined ($length)) {
249 $self->warn("No sense asking for a subseq of length < 1");
253 unless (defined ($pos1)) {
255 } elsif ($pos1 < 1) { # if position out of boundaries
256 $self->warn("Starting position for AARange cannot be < 1!"); return (-1);
257 if ((defined ($pos2))&&($pos1>$pos2)) {
258 $self->warn("1st position($pos1) cannot be > 2nd position($pos2)!"); return (-1);
262 my $objlength=length($seq);
263 unless (defined ($length)) {
264 $length=$objlength-$pos1+1;
266 if (defined ($pos2)) {
267 if ($pos2 > $objlength) { # if position out of boundaries
268 $self->warn("Ending position for AARange cannot be > length of AARange!"); return (-1);
270 $length=$pos2-$pos1+1;
271 if ((defined ($pos1))&&($pos1>$pos2)) {
272 $self->warn("1st position($pos1) cannot be > 2nd position($pos2)!"); return (-1);
275 my $str=substr($seq,$pos1-1,$length);
276 if (length($str) < $length) {
277 $self->warn("Attention, cannot return the length requested for subseq",1);
284 my ($aa_start,$aa_end)=($self->aa_start,$self->aa_end);
285 unless (($aa_start)&&($aa_end)) { # they must both exist
286 $self->warn("Not able to find start or end of the AminoAcid Range");
289 my $translseq=$self->get_Translation->seq;
290 return substr($translseq,$aa_start-1,$aa_end-$aa_start+1);
291 # Note: it will return "undef" if the translation stops before the start
292 # of the aarange (because of upstream nonsense mutation creating STOP).
293 # For the same reason it would return uncomplete (up to the STOP) string
294 # if the stop happens in between aarange's start and stop
300 my $length=length($seq);
305 my ($self,$position)=@_;
306 my $translation=$self->get_Translation;
307 my $origstart=$translation->coordinate_start; # preserve it
308 $translation->coordinate_start($self->start); # change it
309 my $label=$translation->label($position);
310 $translation->coordinate_start($origstart); # restore it
315 my ($self,$label)=@_;
316 my $translation=$self->get_Translation;
317 my $origstart=$translation->coordinate_start; # preserve it
318 $translation->coordinate_start($self->start); # change it
319 my $position=$translation->position($label);
320 $translation->coordinate_start($origstart); # restore it
327 Usage : $end = $aarange->aa_start()
328 Returns : integer (position, according to Translation coordinate system) of
329 the start of an AminoAcidRange object
336 my $aastart=$self->get_Translation->position($self->{'start'});
342 Usage : $end = $aarange->aa_end()
343 Returns : integer (position, according to Translation coordinate system) of
344 the end of an AminoAcidRange object
351 my $aastart=$self->get_Translation->position($self->{'end'});
357 Usage : $end = $aarange->dna_seq()
358 Returns : the sequence at DNA level of the entire AminoAcidRange
359 this would include introns (if present)
366 my $startlabel=$self->start;
367 my $endtripletlabel=$self->end;
368 my $endlabel=$self->{'seq'}->label(3,$endtripletlabel,$self->strand);
369 return ($self->labelsubseq($startlabel,undef,$endlabel));
375 Usage : $end = $aarange->cdna_seq()
376 Returns : the sequence at cDNA level of the entire AminoAcidRange
377 i.e. this is the part of the Transcript that codes for the
378 AminoAcidRange. It would be composed just of exonic DNA.
385 my $startlabel=$self->start;
386 my $endtripletlabel=$self->end;
387 my $endlabel=$self->{'seq'}->label(3,$endtripletlabel,$self->strand);
388 return ($self->get_Transcript->labelsubseq($startlabel,undef,$endlabel));
391 # this checks if the attached Transcript has a Gene object attached
393 my ($self,$value) = @_;
394 if (defined $value) {
395 $self->{'gene'} = $value;
397 unless (exists $self->{'gene'}) {
398 unless (exists $self->get_Transcript->{'gene'}) {
401 return ($self->get_Transcript->{'gene'});
404 return $self->{'gene'};