File Coverage

Bio/Symbol/ProteinAlphabet.pm
Criterion Covered Total %
statement 35 35 100.0
branch 2 2 100.0
condition n/a
subroutine 6 6 100.0
pod 1 1 100.0
total 44 44 100.0


line stmt bran cond sub pod time code
1             #
2             # BioPerl module for Bio::Symbol::ProteinAlphabet
3             #
4             # Please direct questions and support issues to
5             #
6             # Cared for by Jason Stajich
7             #
8             # Copyright Jason Stajich
9             #
10             # You may distribute this module under the same terms as perl itself
11              
12             # POD documentation - main docs before the code
13              
14             =head1 NAME
15              
16             Bio::Symbol::ProteinAlphabet - A ready made Protein alphabet
17              
18             =head1 SYNOPSIS
19              
20             use Bio::Symbol::ProteinAlphabet;
21             my $alpha = Bio::Symbol::ProteinAlphabet->new();
22             foreach my $symbol ( $alpha->symbols ) {
23             print "symbol is $symbol\n";
24             }
25              
26             =head1 DESCRIPTION
27              
28             This object builds an Alphabet with Protein symbols.
29              
30             =head1 FEEDBACK
31              
32             =head2 Mailing Lists
33              
34             User feedback is an integral part of the evolution of this and other
35             Bioperl modules. Send your comments and suggestions preferably to
36             the Bioperl mailing list. Your participation is much appreciated.
37              
38             bioperl-l@bioperl.org - General discussion
39             http://bioperl.org/wiki/Mailing_lists - About the mailing lists
40              
41             =head2 Support
42              
43             Please direct usage questions or support issues to the mailing list:
44              
45             I
46              
47             rather than to the module maintainer directly. Many experienced and
48             reponsive experts will be able look at the problem and quickly
49             address it. Please include a thorough description of the problem
50             with code and data examples if at all possible.
51              
52             =head2 Reporting Bugs
53              
54             Report bugs to the Bioperl bug tracking system to help us keep track
55             of the bugs and their resolution. Bug reports can be submitted via the
56             web:
57              
58             https://github.com/bioperl/bioperl-live/issues
59              
60             =head1 AUTHOR - Jason Stajich
61              
62             Email jason@bioperl.org
63              
64             =head1 APPENDIX
65              
66             The rest of the documentation details each of the object methods.
67             Internal methods are usually preceded with a _
68              
69             =cut
70              
71              
72             # Let the code begin...
73              
74              
75             package Bio::Symbol::ProteinAlphabet;
76 1     1   601 use strict;
  1         1  
  1         22  
77              
78 1     1   3 use Bio::Symbol::Symbol;
  1         1  
  1         13  
79 1     1   2 use Bio::Tools::IUPAC;
  1         1  
  1         13  
80 1     1   399 use Bio::SeqUtils;
  1         1  
  1         29  
81              
82 1     1   6 use base qw(Bio::Symbol::Alphabet);
  1         1  
  1         206  
83              
84             =head2 new
85              
86             Title : new
87             Usage : my $obj = Bio::Symbol::ProteinAlphabet->new();
88             Function: Builds a new Bio::Symbol::ProteinAlphabet object
89             Returns : Bio::Symbol::ProteinAlphabet
90             Args :
91              
92              
93             =cut
94              
95             sub new {
96 1     1 1 392 my($class,@args) = @_;
97 1         58 my $self = $class->SUPER::new(@args);
98 1         6 my %aa = Bio::SeqUtils->valid_aa(2);
99 1         9 my %codes = Bio::Tools::IUPAC->iupac_iup();
100 1         3 my %symbols;
101             my @left;
102            
103 1         5 foreach my $let ( keys %codes ) {
104 27 100       15 if( scalar @{$codes{$let}} != 1) { push @left, $let; next; }
  27         42  
  3         4  
  3         4  
105 24         52 $symbols{$let} = Bio::Symbol::Symbol->new(-name => $aa{$let},
106             -token => $let);
107             }
108 1         4 foreach my $l ( @left ) {
109 3         2 my @subsym;
110 3         2 foreach my $sym ( @{$codes{$l}} ) {
  3         16  
111 6         10 push @subsym, $symbols{$sym};
112             }
113 3         9 my $alpha = Bio::Symbol::Alphabet->new(-symbols => \@subsym);
114 3         19 $symbols{$l} = Bio::Symbol::Symbol->new(-name => $aa{$l},
115             -token => $l,
116             -matches => $alpha,
117             -symbols => \@subsym);
118             }
119            
120 1         6 $self->symbols(values %symbols);
121 1         10 return $self;
122             }
123              
124              
125             1;