File Coverage

Bio/Variation/SeqDiff.pm
Criterion Covered Total %
statement 171 304 56.2
branch 91 168 54.1
condition 1 30 3.3
subroutine 27 31 87.1
pod 26 26 100.0
total 316 559 56.5


line stmt bran cond sub pod time code
1             # bioperl module for Bio::Variation::SeqDiff
2             #
3             # Please direct questions and support issues to
4             #
5             # Cared for by Heikki Lehvaslaiho
6             #
7             # Copyright Heikki Lehvaslaiho
8             #
9             # You may distribute this module under the same terms as perl itself
10             #
11             # POD documentation - main docs before the code
12              
13             # cds_end definition?
14              
15             =head1 NAME
16              
17             Bio::Variation::SeqDiff - Container class for mutation/variant descriptions
18              
19             =head1 SYNOPSIS
20              
21             $seqDiff = Bio::Variation::SeqDiff->new (
22             -id => $M20132,
23             -alphabet => 'rna',
24             -gene_symbol => 'AR'
25             -chromosome => 'X',
26             -numbering => 'coding'
27             );
28             # get a DNAMutation object somehow
29             $seqDiff->add_Variant($dnamut);
30             print $seqDiff->sys_name(), "\n";
31              
32             =head1 DESCRIPTION
33              
34             SeqDiff stores Bio::Variation::VariantI object references and
35             descriptive information common to all changes in a sequence. Mutations
36             are understood to be any kind of sequence markers and are expected to
37             occur in the same chromosome. See L for details.
38              
39             The methods of SeqDiff are geared towards describing mutations in
40             human genes using gene-based coordinate system where 'A' of the
41             initiator codon has number 1 and the one before it -1. This is
42             according to conventions of human genetics.
43              
44             There will be class Bio::Variation::Genotype to describe markers in
45             different chromosomes and diploid genototypes.
46              
47             Classes implementing Bio::Variation::VariantI interface are
48             Bio::Variation::DNAMutation, Bio::Variation::RNAChange, and
49             Bio::Variation::AAChange. See L,
50             L, L, and
51             L for more information.
52              
53             Variant objects can be added using two ways: an array passed to the
54             constructor or as individual Variant objects with add_Variant
55             method.
56              
57              
58             =head1 FEEDBACK
59              
60             =head2 Mailing Lists
61              
62             User feedback is an integral part of the evolution of this and other
63             Bioperl modules. Send your comments and suggestions preferably to the
64             Bioperl mailing lists Your participation is much appreciated.
65              
66             bioperl-l@bioperl.org - General discussion
67             http://bioperl.org/wiki/Mailing_lists - About the mailing lists
68              
69              
70             =head2 Support
71              
72             Please direct usage questions or support issues to the mailing list:
73              
74             I
75              
76             rather than to the module maintainer directly. Many experienced and
77             reponsive experts will be able look at the problem and quickly
78             address it. Please include a thorough description of the problem
79             with code and data examples if at all possible.
80              
81             =head2 Reporting Bugs
82              
83             Report bugs to the Bioperl bug tracking system to help us keep track
84             the bugs and their resolution. Bug reports can be submitted via the
85             web:
86              
87             https://github.com/bioperl/bioperl-live/issues
88              
89             =head1 AUTHOR - Heikki Lehvaslaiho
90              
91             Email: heikki-at-bioperl-dot-org
92              
93             =head1 CONTRIBUTORS
94              
95             Eckhard Lehmann, ecky@e-lehmann.de
96              
97             =head1 APPENDIX
98              
99             The rest of the documentation details each of the object
100             methods. Internal methods are usually preceded with a _
101              
102             =cut
103              
104             # Let the code begin...
105              
106             package Bio::Variation::SeqDiff;
107              
108 5     5   459 use strict;
  5         7  
  5         153  
109 5     5   1752 use Bio::Tools::CodonTable;
  5         9  
  5         126  
110 5     5   1607 use Bio::PrimarySeq;
  5         10  
  5         150  
111              
112 5     5   32 use base qw(Bio::Root::Root);
  5         8  
  5         11727  
113              
114              
115             =head2 new
116              
117             Title : new
118             Usage : $seqDiff = Bio::Variation::SeqDiff->new;
119             Function: generates a new Bio::Variation::SeqDiff
120             Returns : reference to a new object of class SeqDiff
121             Args :
122              
123             =cut
124              
125             sub new {
126 30     30 1 377 my($class,@args) = @_;
127 30         111 my $self = $class->SUPER::new(@args);
128              
129 30         178 my($id, $sysname, $trivname, $chr, $gene_symbol,
130             $desc, $alphabet, $numbering, $offset, $rna_offset, $rna_id, $cds_end,
131             $dna_ori, $dna_mut, $rna_ori, $rna_mut, $aa_ori, $aa_mut
132             #@variants, @genes
133             ) =
134             $self->_rearrange([qw(ID
135             SYSNAME
136             TRIVNAME
137             CHR
138             GENE_SYMBOL
139             DESC
140             ALPHABET
141             NUMBERING
142             OFFSET
143             RNA_OFFSET
144             RNA_ID
145             CDS_END
146             DNA_ORI
147             DNA_MUT
148             RNA_ORI
149             AA_ORI
150             AA_MUT
151             )],
152             @args);
153            
154             #my $make = $self->SUPER::_initialize(@args);
155            
156 30 100       111 $id && $self->id($id);
157 30 50       55 $sysname && $self->sysname($sysname);
158 30 50       49 $trivname && $self->trivname($trivname);
159 30 50       49 $chr && $self->chromosome($chr);
160 30 50       55 $gene_symbol && $self->gene_symbol($chr);
161 30 50       60 $desc && $self->description($desc);
162 30 50       43 $alphabet && $self->alphabet($alphabet);
163 30 50       46 $numbering && $self->numbering($numbering);
164 30 100       59 $offset && $self->offset($offset);
165 30 50       42 $rna_offset && $self->rna_offset($rna_offset);
166 30 50       51 $rna_id && $self->rna_id($rna_id);
167 30 50       42 $cds_end && $self->cds_end($cds_end);
168              
169 30 50       44 $dna_ori && $self->dna_ori($dna_ori);
170 30 50       47 $dna_mut && $self->dna_mut($dna_mut);
171 30 50       55 $rna_ori && $self->rna_ori($rna_ori);
172 30 50       78 $rna_mut && $self->rna_mut($rna_mut);
173 30 50       48 $aa_ori && $self->aa_ori ($aa_ori);
174 30 50       60 $aa_mut && $self->aa_mut ($aa_mut);
175              
176 30         85 $self->{ 'variants' } = [];
177             #@variants && push(@{$self->{'variants'}},@variants);
178              
179 30         54 $self->{ 'genes' } = [];
180             #@genes && push(@{$self->{'genes'}},@genes);
181              
182 30         80 return $self; # success - we hope!
183             }
184              
185              
186             =head2 id
187              
188             Title : id
189             Usage : $obj->id(H0001); $id = $obj->id();
190             Function:
191              
192             Sets or returns the id of the seqDiff.
193             Should be used to give the collection of variants a UID
194             without semantic associations.
195              
196             Example :
197             Returns : value of id, a scalar
198             Args : newvalue (optional)
199              
200             =cut
201              
202              
203             sub id {
204 66     66 1 108 my ($self,$value) = @_;
205 66 100       113 if (defined $value) {
206 28         65 $self->{'id'} = $value;
207             }
208             else {
209 38         106 return $self->{'id'};
210             }
211             }
212              
213              
214             =head2 sysname
215              
216             Title : sysname
217             Usage : $obj->sysname('5C>G'); $sysname = $obj->sysname();
218             Function:
219              
220             Sets or returns the systematic name of the seqDiff. The
221             name should follow the HUGO Mutation Database Initiative
222             approved nomenclature. If called without first setting the
223             value, will generate it from L
224             objects attached.
225              
226             Example :
227             Returns : value of sysname, a scalar
228             Args : newvalue (optional)
229              
230             =cut
231              
232              
233             sub sysname {
234 34     34 1 51 my ($self,$value) = @_;
235 34 100       77 if (defined $value) {
    100          
236 1         2 $self->{'sysname'} = $value;
237             }
238             elsif (not defined $self->{'sysname'}) {
239              
240 16         19 my $sysname = '';
241 16         19 my $c = 0;
242 16         33 foreach my $mut ($self->each_Variant) {
243 47 100       146 if( $mut->isa('Bio::Variation::DNAMutation') ) {
244 17         19 $c++;
245 17 100       31 if ($c == 1 ) {
246 16         43 $sysname = $mut->sysname ;
247             }
248             else {
249 1         4 $sysname .= ";". $mut->sysname;
250             }
251             }
252             }
253 16 100       29 $sysname = "[". $sysname. "]" if $c > 1;
254 16         32 $self->{'sysname'} = $sysname;
255             }
256 34         87 return $self->{'sysname'};
257             }
258              
259              
260             =head2 trivname
261              
262             Title : trivname
263             Usage : $obj->trivname('[A2G;T56G]'); $trivname = $obj->trivname();
264             Function:
265              
266             Sets or returns the trivial name of the seqDiff.
267             The name should follow the HUGO Mutation Database Initiative
268             approved nomenclature. If called without first setting the
269             value, will generate it from L
270             objects attached.
271              
272             Example :
273             Returns : value of trivname, a scalar
274             Args : newvalue (optional)
275              
276             =cut
277              
278              
279             sub trivname {
280 34     34 1 1870 my ($self,$value) = @_;
281 34 100       96 if (defined $value) {
    100          
282 1         2 $self->{'trivname'} = $value;
283             }
284             elsif (not defined $self->{'trivname'}) {
285            
286 20         25 my $trivname = '';
287 20         27 my $c = 0;
288 20         45 foreach my $mut ($self->each_Variant) {
289 59 100       146 if( $mut->isa('Bio::Variation::AAChange') ) {
290 17         20 $c++;
291 17 100       36 if ($c == 1 ) {
292 16         53 $trivname = $mut->trivname ;
293             }
294             else {
295 1         3 $trivname .= ";". $mut->trivname;
296             }
297             }
298             }
299 20 100       53 $trivname = "[". $trivname. "]" if $c > 1;
300 20         103 $self->{'trivname'} = $trivname;
301             }
302              
303             else {
304 13         32 return $self->{'trivname'};
305             }
306             }
307              
308              
309             =head2 chromosome
310              
311             Title : chromosome
312             Usage : $obj->chromosome('X'); $chromosome = $obj->chromosome();
313             Function:
314              
315             Sets or returns the chromosome ("linkage group") of the seqDiff.
316              
317             Example :
318             Returns : value of chromosome, a scalar
319             Args : newvalue (optional)
320              
321             =cut
322              
323              
324             sub chromosome {
325 3     3 1 8 my ($self,$value) = @_;
326 3 100       8 if (defined $value) {
327 2         8 $self->{'chromosome'} = $value;
328             }
329             else {
330 1         5 return $self->{'chromosome'};
331             }
332             }
333              
334              
335             =head2 gene_symbol
336              
337             Title : gene_symbol
338             Usage : $obj->gene_symbol('FOS'); $gene_symbol = $obj->gene_symbol;
339             Function:
340              
341             Sets or returns the gene symbol for the studied CDS.
342              
343             Example :
344             Returns : value of gene_symbol, a scalar
345             Args : newvalue (optional)
346              
347             =cut
348              
349              
350             sub gene_symbol {
351 2     2 1 272 my ($self,$value) = @_;
352 2 100       6 if (defined $value) {
353 1         5 $self->{'gene_symbol'} = $value;
354             }
355             else {
356 1         4 return $self->{'gene_symbol'};
357             }
358             }
359              
360              
361              
362             =head2 description
363              
364             Title : description
365             Usage : $obj->description('short description'); $descr = $obj->description();
366             Function:
367              
368             Sets or returns the short description of the seqDiff.
369              
370             Example :
371             Returns : value of description, a scalar
372             Args : newvalue (optional)
373              
374             =cut
375              
376              
377             sub description {
378 2     2 1 3 my ($self,$value) = @_;
379 2 100       7 if (defined $value) {
380 1         5 $self->{'description'} = $value;
381             }
382             else {
383 1         6 return $self->{'description'};
384             }
385             }
386              
387              
388             =head2 alphabet
389              
390             Title : alphabet
391             Usage : if( $obj->alphabet eq 'dna' ) { /Do Something/ }
392             Function: Returns the type of primary reference sequence being one of
393             'dna', 'rna' or 'protein'. This is case sensitive.
394              
395             Returns : a string either 'dna','rna','protein'.
396             Args : none
397              
398              
399             =cut
400              
401             sub alphabet {
402 152     152 1 475 my ($self,$value) = @_;
403 152         253 my %type = (dna => 1,
404             rna => 1,
405             protein => 1);
406 152 100       214 if( defined $value ) {
407 20 50       34 if ($type{$value}) {
408 20         41 $self->{'alphabet'} = $value;
409             } else {
410 0         0 $self->throw("$value is not valid alphabet value!");
411             }
412             }
413 152         482 return $self->{'alphabet'};
414             }
415              
416              
417             =head2 numbering
418              
419             Title : numbering
420             Usage : $obj->numbering('coding'); $numbering = $obj->numbering();
421             Function:
422              
423             Sets or returns the string giving the numbering schema used
424             to describe the variants.
425              
426             Example :
427             Returns : value of numbering, a scalar
428             Args : newvalue (optional)
429              
430             =cut
431              
432              
433              
434             sub numbering {
435 18     18 1 34 my ($self,$value) = @_;
436 18 100       37 if (defined $value) {
437 6         20 $self->{'numbering'} = $value;
438             }
439             else {
440 12         49 return $self->{'numbering'};
441             }
442             }
443              
444              
445             =head2 offset
446              
447             Title : offset
448             Usage : $obj->offset(124); $offset = $obj->offset();
449             Function:
450              
451             Sets or returns the offset from the beginning of the DNA sequence
452             to the coordinate start used to describe variants. Typically
453             the beginning of the coding region of the gene.
454             The cds_start should be 1 + offset.
455              
456             Example :
457             Returns : value of offset, a scalar
458             Args : newvalue (optional)
459              
460             =cut
461              
462              
463              
464             sub offset {
465 85     85 1 126 my ($self,$value) = @_;
466 85 100       186 if (defined $value) {
    50          
467 21         40 $self->{'offset'} = $value;
468             }
469             elsif (not defined $self->{'offset'} ) {
470 0         0 return $self->{'offset'} = 0;
471             }
472             else {
473 64         148 return $self->{'offset'};
474             }
475             }
476              
477              
478             =head2 cds_start
479              
480             Title : cds_start
481             Usage : $obj->cds_start(123); $cds_start = $obj->cds_start();
482             Function:
483              
484             Sets or returns the cds_start from the beginning of the DNA
485             sequence to the coordinate start used to describe
486             variants. Typically the beginning of the coding region of
487             the gene. Needs to be and is implemented as 1 + offset.
488              
489             Example :
490             Returns : value of cds_start, a scalar
491             Args : newvalue (optional)
492              
493             =cut
494              
495              
496              
497             sub cds_start {
498 0     0 1 0 my ($self,$value) = @_;
499 0 0       0 if (defined $value) {
500 0         0 $self->{'offset'} = $value - 1;
501             }
502             else {
503 0         0 return $self->{'offset'} + 1;
504             }
505             }
506              
507              
508             =head2 cds_end
509              
510             Title : cds_end
511             Usage : $obj->cds_end(321); $cds_end = $obj->cds_end();
512             Function:
513              
514             Sets or returns the position of the last nucleotitide of the
515             termination codon. The coordinate system starts from cds_start.
516              
517             Example :
518             Returns : value of cds_end, a scalar
519             Args : newvalue (optional)
520              
521             =cut
522              
523              
524              
525             sub cds_end {
526 20     20 1 34 my ($self,$value) = @_;
527 20 100       32 if (defined $value) {
528 5         16 $self->{'cds_end'} = $value;
529             }
530             else {
531 15         36 return $self->{'cds_end'};
532             #$self->{'cds_end'} = CORE::length($self->SeqDiff->rna_ori)/3;
533             }
534             }
535              
536              
537             =head2 rna_offset
538              
539             Title : rna_offset
540             Usage : $obj->rna_offset(124); $rna_offset = $obj->rna_offset();
541             Function:
542              
543             Sets or returns the rna_offset from the beginning of the RNA sequence
544             to the coordinate start used to describe variants. Typically
545             the beginning of the coding region of the gene.
546              
547             Example :
548             Returns : value of rna_offset, a scalar
549             Args : newvalue (optional)
550              
551             =cut
552              
553              
554              
555             sub rna_offset {
556 2     2 1 4 my ($self,$value) = @_;
557 2 100       7 if (defined $value) {
    50          
558 1         4 $self->{'rna_offset'} = $value;
559             }
560             elsif (not defined $self->{'rna_offset'} ) {
561 0         0 return $self->{'rna_offset'} = 0;
562             }
563             else {
564 1         3 return $self->{'rna_offset'};
565             }
566             }
567              
568              
569             =head2 rna_id
570              
571             Title : rna_id
572             Usage : $obj->rna_id('transcript#3'); $rna_id = $obj->rna_id();
573             Function:
574              
575             Sets or returns the ID for original RNA sequence of the seqDiff.
576              
577             Example :
578             Returns : value of rna_id, a scalar
579             Args : newvalue (optional)
580              
581             =cut
582              
583              
584             sub rna_id {
585 6     6 1 10 my ($self,$value) = @_;
586 6 100       9 if (defined $value) {
587 1         3 $self->{'rna_id'} = $value;
588             }
589             else {
590 5         11 return $self->{'rna_id'};
591             }
592             }
593              
594              
595              
596             =head2 add_Variant
597              
598             Title : add_Variant
599             Usage : $obj->add_Variant($variant)
600             Function:
601              
602             Pushes one Bio::Variation::Variant into the list of variants.
603             At the same time, creates a link from the Variant to SeqDiff
604             using its SeqDiff method.
605              
606             Example :
607             Returns : 1 when succeeds, 0 for failure.
608             Args : Variant object
609              
610             =cut
611              
612             sub add_Variant {
613 61     61 1 103 my ($self,$value) = @_;
614 61 50       99 if (defined $value) {
615 61 50       177 if( ! $value->isa('Bio::Variation::VariantI') ) {
616 0         0 $self->throw("Is not a VariantI complying object but a [$self]");
617 0         0 return 0;
618             }
619             else {
620 61         67 push(@{$self->{'variants'}},$value);
  61         124  
621 61         159 $value->SeqDiff($self);
622 61         90 return 1;
623             }
624             }
625             else {
626 0         0 return 0;
627             }
628             }
629              
630              
631             =head2 each_Variant
632              
633             Title : each_Variant
634             Usage : $obj->each_Variant();
635             Function:
636              
637             Returns a list of Variants.
638              
639             Example :
640             Returns : list of Variants
641             Args : none
642              
643             =cut
644              
645             sub each_Variant{
646 99     99 1 120 my ($self,@args) = @_;
647            
648 99         95 return @{$self->{'variants'}};
  99         218  
649             }
650              
651              
652              
653             =head2 add_Gene
654              
655             Title : add_Gene
656             Usage : $obj->add_Gene($gene)
657             Function:
658              
659             Pushes one L into the list of genes.
660              
661             Example :
662             Returns : 1 when succeeds, 0 for failure.
663             Args : Bio::LiveSeq::Gene object
664              
665             See L for more information.
666              
667             =cut
668              
669              
670             sub add_Gene {
671 0     0 1 0 my ($self,$value) = @_;
672 0 0       0 if (defined $value) {
673 0 0       0 if( ! $value->isa('Bio::LiveSeq::Gene') ) {
674 0         0 $value->throw("Is not a Bio::LiveSeq::Gene object but a [$value]");
675 0         0 return 0;
676             }
677             else {
678 0         0 push(@{$self->{'genes'}},$value);
  0         0  
679 0         0 return 1;
680             }
681             }
682             else {
683 0         0 return 0;
684             }
685             }
686              
687              
688             =head2 each_Gene
689              
690             Title : each_Gene
691             Usage : $obj->each_Gene();
692             Function:
693              
694             Returns a list of Ls.
695              
696             Example :
697             Returns : list of Genes
698             Args : none
699              
700             =cut
701              
702             sub each_Gene{
703 0     0 1 0 my ($self,@args) = @_;
704              
705 0         0 return @{$self->{'genes'}};
  0         0  
706             }
707              
708              
709             =head2 dna_ori
710              
711             Title : dna_ori
712             Usage : $obj->dna_ori('atgctgctgctgct'); $dna_ori = $obj->dna_ori();
713             Function:
714              
715             Sets or returns the original DNA sequence string of the seqDiff.
716              
717             Example :
718             Returns : value of dna_ori, a scalar
719             Args : newvalue (optional)
720              
721             =cut
722              
723              
724             sub dna_ori {
725 7     7 1 25 my ($self,$value) = @_;
726 7 100       33 if (defined $value) {
727 6         58 $self->{'dna_ori'} = $value;
728             }
729             else {
730 1         4 return $self->{'dna_ori'};
731             }
732             }
733              
734              
735             =head2 dna_mut
736              
737             Title : dna_mut
738             Usage : $obj->dna_mut('atgctggtgctgct'); $dna_mut = $obj->dna_mut();
739             Function:
740              
741             Sets or returns the mutated DNA sequence of the seqDiff.
742             If sequence has not been set generates it from the
743             original sequence and DNA mutations.
744              
745             Example :
746             Returns : value of dna_mut, a scalar
747             Args : newvalue (optional)
748              
749             =cut
750              
751              
752             sub dna_mut {
753 6     6 1 24 my ($self,$value) = @_;
754 6 100       24 if (defined $value) {
755 5         33 $self->{'dna_mut'} = $value;
756             }
757             else {
758 1 50       5 $self->_set_dnamut() unless $self->{'dna_mut'};
759 1         4 return $self->{'dna_mut'};
760             }
761             }
762              
763             sub _set_dnamut {
764 1     1   1 my $self = shift;
765              
766 1 50 33     4 return unless $self->{'dna_ori'} && $self->each_Variant;
767              
768 1         2 $self->{'dna_mut'} = $self->{'dna_ori'};
769 1         3 foreach ($self->each_Variant) {
770 2 50       6 next unless $_->isa('Bio::Variation::DNAMutation');
771 2 50       3 next unless $_->isMutation;
772              
773 2         3 my ($s, $la, $le);
774             #lies the mutation less than 25 bases after the start of sequence?
775 2 50       5 if ($_->start < 25) {
776 2         2 $s = 0; $la = $_->start - 1;
  2         4  
777             } else {
778 0         0 $s = $_->start - 25; $la = 25;
  0         0  
779             }
780              
781             #is the mutation an insertion?
782 2 50       3 $_->end($_->start) unless $_->allele_ori->seq;
783              
784             #does the mutation end greater than 25 bases before the end of
785             #sequence?
786 2 50       3 if (($_->end + 25) > length($self->{'dna_mut'})) {
787 2         5 $le = length($self->{'dna_mut'}) - $_->end;
788             } else {
789 0         0 $le = 25;
790             }
791              
792 2         10 $_->dnStreamSeq(substr($self->{'dna_mut'}, $s, $la));
793 2         5 $_->upStreamSeq(substr($self->{'dna_mut'}, $_->end, $le));
794              
795 2         4 my $s_ori = $_->dnStreamSeq . $_->allele_ori->seq . $_->upStreamSeq;
796 2         4 my $s_mut = $_->dnStreamSeq . $_->allele_mut->seq . $_->upStreamSeq;
797              
798 2         24 (my $str = $self->{'dna_mut'}) =~ s/$s_ori/$s_mut/;
799 2         7 $self->{'dna_mut'} = $str;
800             }
801             }
802              
803              
804             =head2 rna_ori
805              
806             Title : rna_ori
807             Usage : $obj->rna_ori('atgctgctgctgct'); $rna_ori = $obj->rna_ori();
808             Function:
809              
810             Sets or returns the original RNA sequence of the seqDiff.
811              
812             Example :
813             Returns : value of rna_ori, a scalar
814             Args : newvalue (optional)
815              
816             =cut
817              
818              
819             sub rna_ori {
820 7     7 1 19 my ($self,$value) = @_;
821 7 100       26 if (defined $value) {
822 6         32 $self->{'rna_ori'} = $value;
823             }
824             else {
825 1         4 return $self->{'rna_ori'};
826             }
827             }
828              
829              
830             =head2 rna_mut
831              
832             Title : rna_mut
833             Usage : $obj->rna_mut('atgctggtgctgct'); $rna_mut = $obj->rna_mut();
834             Function:
835              
836             Sets or returns the mutated RNA sequence of the seqDiff.
837              
838             Example :
839             Returns : value of rna_mut, a scalar
840             Args : newvalue (optional)
841              
842             =cut
843              
844              
845             sub rna_mut {
846 7     7 1 24 my ($self,$value) = @_;
847 7 100       22 if (defined $value) {
848 6         30 $self->{'rna_mut'} = $value;
849             }
850             else {
851 1         3 return $self->{'rna_mut'};
852             }
853             }
854              
855              
856             =head2 aa_ori
857              
858             Title : aa_ori
859             Usage : $obj->aa_ori('MAGVLL*'); $aa_ori = $obj->aa_ori();
860             Function:
861              
862             Sets or returns the original protein sequence of the seqDiff.
863              
864             Example :
865             Returns : value of aa_ori, a scalar
866             Args : newvalue (optional)
867              
868             =cut
869              
870              
871             sub aa_ori {
872 7     7 1 23 my ($self,$value) = @_;
873 7 100       20 if (defined $value) {
874 6         27 $self->{'aa_ori'} = $value;
875             }
876             else {
877 1         3 return $self->{'aa_ori'};
878             }
879             }
880              
881              
882             =head2 aa_mut
883              
884             Title : aa_mut
885             Usage : $obj->aa_mut('MA*'); $aa_mut = $obj->aa_mut();
886             Function:
887              
888             Sets or returns the mutated protein sequence of the seqDiff.
889              
890             Example :
891             Returns : value of aa_mut, a scalar
892             Args : newvalue (optional)
893              
894             =cut
895              
896              
897             sub aa_mut {
898 8     8 1 26 my ($self,$value) = @_;
899 8 100       24 if (defined $value) {
900 7         30 $self->{'aa_mut'} = $value;
901             }
902             else {
903 1         3 return $self->{'aa_mut'};
904             }
905             }
906              
907              
908             =head2 seqobj
909              
910             Title : seqobj
911             Usage : $dnaobj = $obj->seqobj('dna_mut');
912             Function:
913              
914             Returns the any original or mutated sequences as a
915             Bio::PrimarySeq object.
916              
917             Example :
918             Returns : Bio::PrimarySeq object for the requested sequence
919             Args : string, method name for the sequence requested
920              
921             See L for more information.
922              
923             =cut
924              
925             sub seqobj {
926 3     3 1 224 my ($self,$value) = @_;
927 3         4 my $out;
928             my %valid_obj =
929 3         5 map {$_, 1} qw(dna_ori rna_ori aa_ori dna_mut rna_mut aa_mut);
  18         25  
930 3 100       25 $valid_obj{$value} ||
931             $self->throw("Sequence type '$value' is not a valid type (".
932             join(',', map "'$_'", sort keys %valid_obj) .") lowercase");
933 2         11 my ($alphabet) = $value =~ /([^_]+)/;
934 2         5 my $id = $self->id;
935 2 50       4 $id = $self->rna_id if $self->rna_id;
936 2 100       6 $alphabet = 'protein' if $alphabet eq 'aa';
937             $out = Bio::PrimarySeq->new
938             ( '-seq' => $self->{$value},
939             '-display_id' => $id,
940             '-accession_number' => $self->id,
941             '-alphabet' => $alphabet
942 2 100       5 ) if $self->{$value} ;
943 2         8 return $out;
944             }
945              
946             =head2 alignment
947              
948             Title : alignment
949             Usage : $obj->alignment
950             Function:
951              
952             Returns a pretty RNA/AA sequence alignment from linked
953             objects. Under construction: Only simple coding region
954             point mutations work.
955              
956             Example :
957             Returns :
958             Args : none
959              
960             =cut
961              
962              
963             sub alignment {
964 0     0 1   my $self = shift;
965 0           my (@entry, $text);
966              
967 0           my $maxflanklen = 12;
968              
969 0           foreach my $mut ($self->each_Variant) {
970 0 0         if( $mut->isa('Bio::Variation::RNAChange') ) {
971              
972 0           my $upflank = $mut->upStreamSeq;
973 0           my $dnflank = $mut->dnStreamSeq;
974 0           my $cposd = $mut->codon_pos;
975 0           my $rori = $mut->allele_ori->seq;
976 0           my $rmut = $mut->allele_mut->seq;
977 0           my $rseqoriu = '';
978 0           my $rseqmutu = '';
979 0           my $rseqorid = '';
980 0           my $rseqmutd = '';
981 0           my $aaseqmutu = '';
982 0           my (@rseqori, @rseqmut );
983              
984             # point
985 0 0         if ($mut->DNAMutation->label =~ /point/) {
    0          
986 0 0         if ($cposd == 1 ) {
    0          
    0          
987 0           my $nt2d = substr($dnflank, 0, 2);
988 0           push @rseqori, $rori. $nt2d;
989 0           push @rseqmut, uc ($rmut). $nt2d;
990 0           $dnflank = substr($dnflank, 2);
991             }
992             elsif ($cposd == 2) {
993 0           my $ntu = chop $upflank;
994 0           my $ntd = substr($dnflank, 0, 1);
995 0           push @rseqori, $ntu. $rori. $ntd;
996 0           push @rseqmut, $ntu. uc ($rmut). $ntd;
997 0           $dnflank = substr($dnflank, 1);
998             }
999             elsif ($cposd == 3) {
1000 0           my $ntu1 = chop $upflank;
1001 0           my $ntu2 = chop $upflank;
1002 0           push (@rseqori, $ntu2. $ntu1. $rori);
1003 0           push (@rseqmut, $ntu2. $ntu1. uc $rmut);
1004             }
1005             }
1006             #deletion
1007             elsif ($mut->DNAMutation->label =~ /deletion/) {
1008 0 0         if ($cposd == 2 ) {
1009 0           $rseqorid = chop $upflank;
1010 0           $rseqmutd = $rseqorid;
1011             }
1012 0           for (my $i=1; $i<=$mut->length; $i++) {
1013 0           my $ntd .= substr($mut->allele_ori, $i-1, 1);
1014 0           $rseqorid .= $ntd;
1015 0 0         if (length($rseqorid) == 3 ) {
1016 0           push (@rseqori, $rseqorid);
1017 0           push (@rseqmut, " ");
1018 0           $rseqorid = '';
1019             }
1020             }
1021              
1022 0 0         if ($rseqorid) {
1023 0           $rseqorid .= substr($dnflank, 0, 3-$rseqorid);
1024 0           push (@rseqori, $rseqorid);
1025 0           push (@rseqmut, " ");
1026 0           $dnflank = substr($dnflank,3-$rseqorid);
1027             }
1028             }
1029 0           $upflank = reverse $upflank;
1030             # loop throught the flanks
1031 0           for (my $i=1; $i<=length($dnflank); $i++) {
1032            
1033 0 0         last if $i > $maxflanklen;
1034              
1035 0           my $ntd .= substr($dnflank, $i-1, 1);
1036 0           my $ntu .= substr($upflank, $i-1, 1);
1037              
1038 0           $rseqmutd .= $ntd;
1039 0           $rseqorid .= $ntd;
1040 0           $rseqmutu = $ntu. $rseqmutu;
1041 0           $rseqoriu = $ntu. $rseqoriu;
1042            
1043 0 0 0       if (length($rseqorid) == 3 and length($rseqorid) == 3) {
1044 0           push (@rseqori, $rseqorid);
1045 0           push (@rseqmut, $rseqmutd);
1046 0           $rseqorid = $rseqmutd ='';
1047             }
1048 0 0 0       if (length($rseqoriu) == 3 and length($rseqoriu) == 3) {
1049 0           unshift (@rseqori, $rseqoriu);
1050 0           unshift (@rseqmut, $rseqmutu);
1051 0           $rseqoriu = $rseqmutu ='';
1052             }
1053              
1054             #print "|i=$i, $cposd, $rseqmutd, $rseqorid\n";
1055             #print "|i=$i, $cposu, $rseqmutu, $rseqoriu\n\n";
1056              
1057             }
1058              
1059 0           push (@rseqori, $rseqorid);
1060 0           unshift (@rseqori, $rseqoriu);
1061 0           push (@rseqmut, $rseqmutd);
1062 0           unshift (@rseqmut, $rseqmutu);
1063            
1064 0 0         return unless $mut->AAChange;
1065             #translate
1066 0           my $tr = Bio::Tools::CodonTable->new('-id' => $mut->codon_table);
1067 0           my $apos = $mut->AAChange->start;
1068 0           my $aposmax = CORE::length($self->aa_ori); #terminator codon no
1069 0           my $rseqori;
1070             my $rseqmut;
1071 0           my $aaseqori;
1072 0           my $aaseqmut = "";
1073 0           for (my $i = 0; $i <= $#rseqori; $i++) {
1074 0           my $a = '';
1075              
1076 0 0         $a = $tr->translate($rseqori[$i]) if length($rseqori[$i]) == 3;
1077            
1078 0 0 0       if (length($a) != 1 or
      0        
1079             $apos - ( $maxflanklen/2 -1) + $i < 1 or
1080             $apos - ( $maxflanklen/2 -1) + $i > $aposmax ) {
1081 0           $aaseqori .= " ";
1082             } else {
1083 0           $aaseqori .= " ". $a. " ";
1084             }
1085 0           my $b = '';
1086 0 0         if (length($rseqmut[$i]) == 3) {
1087 0 0         if ($rseqmut[$i] eq ' ') {
1088 0           $b = "_";
1089             } else {
1090 0           $b = $tr->translate($rseqmut[$i]);
1091             }
1092             }
1093 0 0 0       if (( $b ne $a and
      0        
      0        
      0        
1094             length($b) == 1 and
1095             $apos - ( $maxflanklen/2 -1) + $i >= 1 ) or
1096             ( $apos - ( $maxflanklen/2 -1) + $i >= $aposmax and
1097             $mut->label =~ 'termination')
1098             ) {
1099 0           $aaseqmut .= " ". $b. " ";
1100             } else {
1101 0           $aaseqmut .= " ";
1102             }
1103            
1104 0 0 0       if ($i == 0 and length($rseqori[$i]) != 3) {
1105 0           my $l = 3 - length($rseqori[$i]);
1106 0           $rseqori[$i] = (" " x $l). $rseqori[$i];
1107 0           $rseqmut[$i] = (" " x $l). $rseqmut[$i];
1108             }
1109 0 0         $rseqori .= $rseqori[$i]. " " if $rseqori[$i] ne '';
1110 0 0         $rseqmut .= $rseqmut[$i]. " " if $rseqmut[$i] ne '';
1111             }
1112            
1113             # collect the results
1114 0           push (@entry,
1115             "\n"
1116             );
1117 0           $text = " ". $aaseqmut;
1118 0           push (@entry,
1119             $text
1120             );
1121 0           $text = "Variant : ". $rseqmut;
1122 0           push (@entry,
1123             $text
1124             );
1125 0           $text = "Reference: ". $rseqori;
1126 0           push (@entry,
1127             $text
1128             );
1129 0           $text = " ". $aaseqori;
1130 0           push (@entry,
1131             $text
1132             );
1133 0           push (@entry,
1134             "\n"
1135             );
1136             }
1137              
1138             }
1139              
1140 0           my $res;
1141 0           foreach my $line (@entry) {
1142 0           $res .= "$line\n";
1143             }
1144 0           return $res;
1145             }
1146              
1147             1;