3 # bioperl module for Bio::LiveSeq::AARange
5 # Cared for by Joseph Insana <insana@ebi.ac.uk> <jinsana@gmx.net>
7 # Copyright Joseph Insana
9 # You may distribute this module under the same terms as perl itself
11 # POD documentation - main docs before the code
15 Bio::LiveSeq::AARange - AARange abstract class for LiveSeq
23 This is used as possible parent for aminoacid range object classes.
24 Or it can be used straight away to define aminoacid ranges. The idea
25 is that the ranges defined are attached to a Translation object and
26 they refer to its coordinate-system when they are first created (via
27 the new() method). When they are created they are anyway linked to
28 the underlying DNA LiveSeq by way of the LiveSeq labels. This allows
29 to preserve the ranges even if the numbering changes in the
30 Translation due to deletions or insertions.
32 The protein sequence associated with the AARange can be accessed via
33 the usual seq() or subseq() methods.
35 The start and end of the AARange in protein coordinate system can be
36 fetched with aa_start() and aa_end() methods. Note: the behaviour of
37 these methods would be influenced by the coordinate_start set in the
38 corresponding Translation object. This can be desirable but can also
39 lead to confusion if the coordinate_start had been changed and the
40 original position of the AARange was to be retrieved.
42 start() and end() methods of the AARange will point to the labels
43 identifying the first nucleotide of the first and last triplet coding
44 for the start and end of the AminoAcidRange.
46 The underlying nucleotide sequence of the AARange can be retrieved
47 with the labelsubseq() method. This would retrieve the whole DNA
48 sequence, including possible introns. This is called "DNA_sequence".
50 To fetch the nucleotide sequence of the Transcript, without introns,
51 the labelsubseq() of the attached Transcript (the Transcript the
52 Translation comes from) has to be accessed. This is called
55 Here are the operations to retrieve these latter two kinds of
58 $startlabel=$AARange->start;
59 $endtripletlabel=$AARange->end;
60 $endlabel=$AARange->{'seq'}->label(3,$endtripletlabel,$AARange->strand);
62 $dnaseq=$AARange->labelsubseq($startlabel,undef,$endlabel));
64 $cdnaseq=$AARange->get_Transcript->labelsubseq($startlabel,undef,$endlabel);
66 To simplify, these operations have been included in two additional
67 methods: dna_seq() and cdna_seq().
69 These would return the whole sequence, as in the examples above. But
70 the above general scheme can be used by specifying different labels,
71 to retrieve hypothetical subsequences of interest.
73 =head1 AUTHOR - Joseph A.L. Insana
75 Email: Insana@ebi.ac.uk, jinsana@gmx.net
79 The rest of the documentation details each of the object
80 methods. Internal methods are usually preceded with a _
84 # Let the code begin...
86 package Bio
::LiveSeq
::AARange
;
89 use base
qw(Bio::LiveSeq::SeqI);
94 Usage : $aarange = Bio::LiveSeq::AARange->new(-translation => $obj_ref,
98 -description => "DCBA",
99 -translength => $length);
101 Function: generates a new AminoAcidRange LiveSeq object
102 Returns : reference to a new object of class AARange
104 Args : two positions in AminoAcid coordinate numbering
105 an object reference specifying to which translation the aminoacid
107 a name and a description (optional)
108 an optional "translength" argument: this can be given when
109 a lot of AARanges are to be created at the same time for the same
110 Translation object, calculating it with $translation->length
111 This would increase the speed, avoiding the new() function to
112 calculate everytime the same length again and again for every obj.
117 my ($thing, %args) = @_;
118 my $class = ref($thing) || $thing;
122 $obj = bless $obj, $class;
125 my ($translation,$start,$end,$name,$description,$translength)=($args{-translation
},$args{-start
},$args{-end
},$args{-name
},$args{-description
},$args{-translength
});
127 unless (($translation)&&(ref($translation) eq "Bio::LiveSeq::Translation")) {
128 $self->warn("No -translation or wrong type given");
131 unless ($translength) { # if it's not given, fetch it
132 $translength=$translation->length;
134 my $seq=$translation->{'seq'};
136 if (($start < 1)&&($start > $translength)) {
137 $self->warn("$class not initialised because start aminoacid position not valid");
140 if (($end < 1)&&($end > $translength)) {
141 $self->warn("$class not initialised because end aminoacid position not valid");
145 $self->warn("$class not initialised because start position > end position!");
149 my ($starttripletlabel,$endtripletlabel);
150 if ($start == $end) { # trick to increase speed
151 $starttripletlabel=$endtripletlabel=$translation->label($start);
153 ($starttripletlabel,$endtripletlabel)=($translation->label($start),$translation->label($end));
155 unless (($starttripletlabel > 0)&&($endtripletlabel > 0)) {
156 $self->warn("$class not initialised because of problems in retrieving start or end label!");
161 #my $endlabel=$seq->label(3,$endtripletlabel); # to get the real end
162 #unless ($endlabel > 0) {
163 #carp "$class not initialised because of problems retrieving the last nucleotide of the triplet coding for the end aminoacid";
167 $self->{'start'}=$starttripletlabel;
168 $self->{'end'}=$endtripletlabel;
169 $self->{'strand'}=$translation->strand;
170 $self->{'translation'}=$translation;
171 $self->{'name'}=$name;
172 $self->{'description'}=$description;
173 $self->{'alphabet'}="protein";
178 sub coordinate_start
{
180 $self->warn("Cannot perform this operation in an AminoAcidRange object!");
186 $self->warn("Cannot perform this operation in an AminoAcidRange object!");
192 $self->warn("Cannot perform this operation in an AminoAcidRange object!");
196 =head2 get_Transcript
199 Usage : $transcript = $obj->get_Transcript()
200 Function: retrieves the reference to the object of class Transcript (if any)
201 attached to a LiveSeq object
202 Returns : object reference
209 return ($self->get_Translation->get_Transcript);
212 =head2 get_Translation
215 Usage : $translation = $obj->get_Translation()
216 Function: retrieves the reference to the object of class Translation (if any)
217 attached to a LiveSeq object
218 Returns : object reference
223 sub get_Translation
{
225 return ($self->{'translation'});
230 $self->warn("Cannot change an AminoAcidRange object!");
235 $self->warn("Cannot change an AminoAcidRange object!");
240 $self->warn("Cannot change an AminoAcidRange object!");
245 my ($self,$pos1,$pos2,$length) = @_;
246 if (defined ($length)) {
248 $self->warn("No sense asking for a subseq of length < 1");
252 unless (defined ($pos1)) {
254 } elsif ($pos1 < 1) { # if position out of boundaries
255 $self->warn("Starting position for AARange cannot be < 1!"); return (-1);
256 if ((defined ($pos2))&&($pos1>$pos2)) {
257 $self->warn("1st position($pos1) cannot be > 2nd position($pos2)!"); return (-1);
261 my $objlength=length($seq);
262 unless (defined ($length)) {
263 $length=$objlength-$pos1+1;
265 if (defined ($pos2)) {
266 if ($pos2 > $objlength) { # if position out of boundaries
267 $self->warn("Ending position for AARange cannot be > length of AARange!"); return (-1);
269 $length=$pos2-$pos1+1;
270 if ((defined ($pos1))&&($pos1>$pos2)) {
271 $self->warn("1st position($pos1) cannot be > 2nd position($pos2)!"); return (-1);
274 my $str=substr($seq,$pos1-1,$length);
275 if (length($str) < $length) {
276 $self->warn("Attention, cannot return the length requested for subseq",1);
283 my ($aa_start,$aa_end)=($self->aa_start,$self->aa_end);
284 unless (($aa_start)&&($aa_end)) { # they must both exist
285 $self->warn("Not able to find start or end of the AminoAcid Range");
288 my $translseq=$self->get_Translation->seq;
289 return substr($translseq,$aa_start-1,$aa_end-$aa_start+1);
290 # Note: it will return "undef" if the translation stops before the start
291 # of the aarange (because of upstream nonsense mutation creating STOP).
292 # For the same reason it would return uncomplete (up to the STOP) string
293 # if the stop happens in between aarange's start and stop
299 my $length=length($seq);
304 my ($self,$position)=@_;
305 my $translation=$self->get_Translation;
306 my $origstart=$translation->coordinate_start; # preserve it
307 $translation->coordinate_start($self->start); # change it
308 my $label=$translation->label($position);
309 $translation->coordinate_start($origstart); # restore it
314 my ($self,$label)=@_;
315 my $translation=$self->get_Translation;
316 my $origstart=$translation->coordinate_start; # preserve it
317 $translation->coordinate_start($self->start); # change it
318 my $position=$translation->position($label);
319 $translation->coordinate_start($origstart); # restore it
326 Usage : $end = $aarange->aa_start()
327 Returns : integer (position, according to Translation coordinate system) of
328 the start of an AminoAcidRange object
335 my $aastart=$self->get_Translation->position($self->{'start'});
341 Usage : $end = $aarange->aa_end()
342 Returns : integer (position, according to Translation coordinate system) of
343 the end of an AminoAcidRange object
350 my $aastart=$self->get_Translation->position($self->{'end'});
356 Usage : $end = $aarange->dna_seq()
357 Returns : the sequence at DNA level of the entire AminoAcidRange
358 this would include introns (if present)
365 my $startlabel=$self->start;
366 my $endtripletlabel=$self->end;
367 my $endlabel=$self->{'seq'}->label(3,$endtripletlabel,$self->strand);
368 return ($self->labelsubseq($startlabel,undef,$endlabel));
374 Usage : $end = $aarange->cdna_seq()
375 Returns : the sequence at cDNA level of the entire AminoAcidRange
376 i.e. this is the part of the Transcript that codes for the
377 AminoAcidRange. It would be composed just of exonic DNA.
384 my $startlabel=$self->start;
385 my $endtripletlabel=$self->end;
386 my $endlabel=$self->{'seq'}->label(3,$endtripletlabel,$self->strand);
387 return ($self->get_Transcript->labelsubseq($startlabel,undef,$endlabel));
390 # this checks if the attached Transcript has a Gene object attached
392 my ($self,$value) = @_;
393 if (defined $value) {
394 $self->{'gene'} = $value;
396 unless (exists $self->{'gene'}) {
397 unless (exists $self->get_Transcript->{'gene'}) {
400 return ($self->get_Transcript->{'gene'});
403 return $self->{'gene'};