maint: restructure to use Dist::Zilla
[bioperl-live.git] / lib / Bio / Symbol / ProteinAlphabet.pm
blob63274bfb4eca413ccf79fd75e2c75cf29ad84c6f
2 # BioPerl module for Bio::Symbol::ProteinAlphabet
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Jason Stajich <jason@bioperl.org>
8 # Copyright Jason Stajich
10 # You may distribute this module under the same terms as perl itself
12 # POD documentation - main docs before the code
14 =head1 NAME
16 Bio::Symbol::ProteinAlphabet - A ready made Protein alphabet
18 =head1 SYNOPSIS
20 use Bio::Symbol::ProteinAlphabet;
21 my $alpha = Bio::Symbol::ProteinAlphabet->new();
22 foreach my $symbol ( $alpha->symbols ) {
23 print "symbol is $symbol\n";
26 =head1 DESCRIPTION
28 This object builds an Alphabet with Protein symbols.
30 =head1 FEEDBACK
32 =head2 Mailing Lists
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.
38 bioperl-l@bioperl.org - General discussion
39 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
41 =head2 Support
43 Please direct usage questions or support issues to the mailing list:
45 I<bioperl-l@bioperl.org>
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.
52 =head2 Reporting Bugs
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:
58 https://github.com/bioperl/bioperl-live/issues
60 =head1 AUTHOR - Jason Stajich
62 Email jason@bioperl.org
64 =head1 APPENDIX
66 The rest of the documentation details each of the object methods.
67 Internal methods are usually preceded with a _
69 =cut
72 # Let the code begin...
75 package Bio::Symbol::ProteinAlphabet;
76 use strict;
78 use Bio::Symbol::Symbol;
79 use Bio::Tools::IUPAC;
80 use Bio::SeqUtils;
82 use base qw(Bio::Symbol::Alphabet);
84 =head2 new
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 :
93 =cut
95 sub new {
96 my($class,@args) = @_;
97 my $self = $class->SUPER::new(@args);
98 my %aa = Bio::SeqUtils->valid_aa(2);
99 my %codes = Bio::Tools::IUPAC->iupac_iup();
100 my %symbols;
101 my @left;
103 foreach my $let ( keys %codes ) {
104 if( scalar @{$codes{$let}} != 1) { push @left, $let; next; }
105 $symbols{$let} = Bio::Symbol::Symbol->new(-name => $aa{$let},
106 -token => $let);
108 foreach my $l ( @left ) {
109 my @subsym;
110 foreach my $sym ( @{$codes{$l}} ) {
111 push @subsym, $symbols{$sym};
113 my $alpha = Bio::Symbol::Alphabet->new(-symbols => \@subsym);
114 $symbols{$l} = Bio::Symbol::Symbol->new(-name => $aa{$l},
115 -token => $l,
116 -matches => $alpha,
117 -symbols => \@subsym);
120 $self->symbols(values %symbols);
121 return $self;