sync w/ main trunk
[bioperl-live.git] / Bio / Symbol / ProteinAlphabet.pm
blob2892723f1c7f4a550f3e48e7cf97911e333c8c2b
1 # $Id$
3 # BioPerl module for Bio::Symbol::ProteinAlphabet
5 # Please direct questions and support issues to <bioperl-l@bioperl.org>
7 # Cared for by Jason Stajich <jason@bioperl.org>
9 # Copyright Jason Stajich
11 # You may distribute this module under the same terms as perl itself
13 # POD documentation - main docs before the code
15 =head1 NAME
17 Bio::Symbol::ProteinAlphabet - A ready made Protein alphabet
19 =head1 SYNOPSIS
21 use Bio::Symbol::ProteinAlphabet;
22 my $alpha = Bio::Symbol::ProteinAlphabet->new();
23 foreach my $symbol ( $alpha->symbols ) {
24 print "symbol is $symbol\n";
27 =head1 DESCRIPTION
29 This object builds an Alphabet with Protein symbols.
31 =head1 FEEDBACK
33 =head2 Mailing Lists
35 User feedback is an integral part of the evolution of this and other
36 Bioperl modules. Send your comments and suggestions preferably to
37 the Bioperl mailing list. Your participation is much appreciated.
39 bioperl-l@bioperl.org - General discussion
40 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
42 =head2 Support
44 Please direct usage questions or support issues to the mailing list:
46 L<bioperl-l@bioperl.org>
48 rather than to the module maintainer directly. Many experienced and
49 reponsive experts will be able look at the problem and quickly
50 address it. Please include a thorough description of the problem
51 with code and data examples if at all possible.
53 =head2 Reporting Bugs
55 Report bugs to the Bioperl bug tracking system to help us keep track
56 of the bugs and their resolution. Bug reports can be submitted via the
57 web:
59 http://bugzilla.open-bio.org/
61 =head1 AUTHOR - Jason Stajich
63 Email jason@bioperl.org
65 =head1 APPENDIX
67 The rest of the documentation details each of the object methods.
68 Internal methods are usually preceded with a _
70 =cut
73 # Let the code begin...
76 package Bio::Symbol::ProteinAlphabet;
77 use strict;
79 use Bio::Symbol::Symbol;
80 use Bio::Tools::IUPAC;
81 use Bio::SeqUtils;
83 use base qw(Bio::Symbol::Alphabet);
85 =head2 new
87 Title : new
88 Usage : my $obj = Bio::Symbol::ProteinAlphabet->new();
89 Function: Builds a new Bio::Symbol::ProteinAlphabet object
90 Returns : Bio::Symbol::ProteinAlphabet
91 Args :
94 =cut
96 sub new {
97 my($class,@args) = @_;
98 my $self = $class->SUPER::new(@args);
99 my %aa = Bio::SeqUtils->valid_aa(2);
100 my %codes = Bio::Tools::IUPAC->iupac_iup();
101 my %symbols;
102 my @left;
104 foreach my $let ( keys %codes ) {
105 if( scalar @{$codes{$let}} != 1) { push @left, $let; next; }
106 $symbols{$let} = Bio::Symbol::Symbol->new(-name => $aa{$let},
107 -token => $let);
109 foreach my $l ( @left ) {
110 my @subsym;
111 foreach my $sym ( @{$codes{$l}} ) {
112 push @subsym, $symbols{$sym};
114 my $alpha = Bio::Symbol::Alphabet->new(-symbols => \@subsym);
115 $symbols{$l} = Bio::Symbol::Symbol->new(-name => $aa{$l},
116 -token => $l,
117 -matches => $alpha,
118 -symbols => \@subsym);
121 $self->symbols(values %symbols);
122 return $self;