0
|
1 # $Id: Alphabet.pm,v 1.6 2002/10/22 07:45:21 lapp Exp $
|
|
2 #
|
|
3 # BioPerl module for Bio::Symbol::Alphabet
|
|
4 #
|
|
5 # Cared for by Jason Stajich <jason@bioperl.org>
|
|
6 #
|
|
7 # Copyright Jason Stajich
|
|
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 =head1 NAME
|
|
14
|
|
15 Bio::Symbol::Alphabet - DESCRIPTION of Object
|
|
16
|
|
17 =head1 SYNOPSIS
|
|
18
|
|
19 {
|
|
20 my $alphabet = new Bio::Symbols::Alphabet(-symbols => [ @s ],
|
|
21 -subalphabets => [ @alphas ] );
|
|
22
|
|
23 my @symbols = $alphabet->symbols;
|
|
24 my @subalphas = $alphabet->alphabets;
|
|
25 if( $alphabet->contains($symbol) ) {
|
|
26 # do something
|
|
27 }
|
|
28 }
|
|
29
|
|
30 =head1 DESCRIPTION
|
|
31
|
|
32 Alphabet contains set of symbols, which can be concatenated to
|
|
33 form symbol lists. Sequence string, for example, is stringified
|
|
34 representation of the symbol list (tokens of symbols).
|
|
35
|
|
36 This module was implemented for the purposes of meeting the
|
|
37 BSANE/BioCORBA spec 0.3 only.
|
|
38
|
|
39 =head1 FEEDBACK
|
|
40
|
|
41 =head2 Mailing Lists
|
|
42
|
|
43 User feedback is an integral part of the evolution of this and other
|
|
44 Bioperl modules. Send your comments and suggestions preferably to
|
|
45 the Bioperl mailing list. Your participation is much appreciated.
|
|
46
|
|
47 bioperl-l@bioperl.org - General discussion
|
|
48 http://bioperl.org/MailList.shtml - About the mailing lists
|
|
49
|
|
50 =head2 Reporting Bugs
|
|
51
|
|
52 Report bugs to the Bioperl bug tracking system to help us keep track
|
|
53 of the bugs and their resolution. Bug reports can be submitted via
|
|
54 email or the web:
|
|
55
|
|
56 bioperl-bugs@bioperl.org
|
|
57 http://bugzilla.bioperl.org/
|
|
58
|
|
59 =head1 AUTHOR - Jason Stajich
|
|
60
|
|
61 Email jason@bioperl.org
|
|
62
|
|
63 Describe contact details here
|
|
64
|
|
65 =head1 CONTRIBUTORS
|
|
66
|
|
67 Additional contributors names and emails here
|
|
68
|
|
69 =head1 APPENDIX
|
|
70
|
|
71 The rest of the documentation details each of the object methods.
|
|
72 Internal methods are usually preceded with a _
|
|
73
|
|
74 =cut
|
|
75
|
|
76
|
|
77 # Let the code begin...
|
|
78
|
|
79
|
|
80 package Bio::Symbol::Alphabet;
|
|
81 use vars qw(@ISA);
|
|
82 use strict;
|
|
83
|
|
84 # Object preamble - inherits from Bio::Root::Root
|
|
85
|
|
86 use Bio::Root::Root;
|
|
87 use Bio::Symbol::AlphabetI;
|
|
88
|
|
89 @ISA = qw(Bio::Root::Root Bio::Symbol::AlphabetI );
|
|
90
|
|
91 =head2 new
|
|
92
|
|
93 Title : new
|
|
94 Usage : my $obj = new Bio::Symbol::Alphabet();
|
|
95 Function: Builds a new Bio::Symbol::Alphabet object
|
|
96 Returns : Bio::Symbol::Alphabet
|
|
97 Args : -symbols => Array ref of Bio::Symbol::SymbolI objects
|
|
98 -subalphas=> Array ref of Bio::Symbol::AlphabetI objects
|
|
99 representing sub alphabets
|
|
100 =cut
|
|
101
|
|
102 sub new {
|
|
103 my($class,@args) = @_;
|
|
104
|
|
105 my $self = $class->SUPER::new(@args);
|
|
106 $self->{'_symbols'} = [];
|
|
107 $self->{'_alphabets'} = [];
|
|
108 my ($symbols, $subalphas) = $self->_rearrange([qw(SYMBOLS SUBALPHAS)],
|
|
109 @args);
|
|
110
|
|
111 defined $symbols && ref($symbols) =~ /array/i && $self->symbols(@$symbols);
|
|
112 defined $subalphas && ref($subalphas) =~ /array/i && $self->alphabets(@$subalphas);
|
|
113 return $self;
|
|
114 }
|
|
115
|
|
116 =head2 AlphabetI Interface methods
|
|
117
|
|
118 =cut
|
|
119
|
|
120 =head2 symbols
|
|
121
|
|
122 Title : symbols
|
|
123 Usage : my @symbols = $alphabet->symbols();
|
|
124 Function: Get/Set Symbol list for an alphabet
|
|
125 List of symbols, which make up this alphabet.
|
|
126 Returns : Array of Bio::Symbol::SymbolI objects
|
|
127 Args : (optionalalphabets) Array of Bio::Symbol::SymbolI objects
|
|
128
|
|
129 =cut
|
|
130
|
|
131 sub symbols {
|
|
132 my ($self,@args) = @_;
|
|
133 if( @args ) {
|
|
134 $self->{'_symbols'} = [];
|
|
135 foreach my $symbol ( @args ) {
|
|
136 if( ! defined $symbol || ! ref($symbol) ||
|
|
137 ! $symbol->isa('Bio::Symbol::SymbolI') ) {
|
|
138 $self->warn("Did not provide a proper Bio::Symbol::SymbolI to method 'symbols' (got $symbol)");
|
|
139 } else {
|
|
140 push @{$self->{'_symbols'}}, $symbol;
|
|
141 }
|
|
142 }
|
|
143 }
|
|
144 return @{$self->{'_symbols'}};
|
|
145 }
|
|
146
|
|
147 =head2 alphabets
|
|
148
|
|
149 Title : alphabets
|
|
150 Usage : my @alphabets = $alphabet->alphabets();
|
|
151 Function: Get/Set Sub Alphabet list for an alphabet
|
|
152 Sub-alphabets. E.g. codons made from DNAxDNAxDNA alphabets
|
|
153 Returns : Array of Bio::Symbol::AlphabetI objects
|
|
154 Args : (optional) Array of Bio::Symbol::AlphabetI objects
|
|
155
|
|
156 =cut
|
|
157
|
|
158 sub alphabets {
|
|
159 my ($self,@args) = @_;
|
|
160 if( @args ) {
|
|
161 $self->{'_alphabets'} = [];
|
|
162 foreach my $alpha ( @args ) {
|
|
163 if( ! $alpha->isa('Bio::Symbol::AlphabetI') ) {
|
|
164 $self->warn("Did not provide a proper Bio::Symbol::AlphabetI to method 'alphabets' (got $alpha)");
|
|
165 } else {
|
|
166 push @{$self->{'_alphabets'}}, $alpha;
|
|
167 }
|
|
168 }
|
|
169 }
|
|
170 return @{$self->{'_alphabets'}};
|
|
171 }
|
|
172
|
|
173 =head2 contains
|
|
174
|
|
175 Title : contains
|
|
176 Usage : if($alphabet->contains($symbol)) { }
|
|
177 Function: Tests of Symbol is contained in this alphabet
|
|
178 Returns : Boolean
|
|
179 Args : Bio::Symbol::SymbolI
|
|
180
|
|
181 =cut
|
|
182
|
|
183 sub contains{
|
|
184 my ($self,$testsymbol) = @_;
|
|
185 foreach my $symbol ( $self->symbols ) {
|
|
186 return 1 if( $symbol->equals($testsymbol) );
|
|
187 }
|
|
188 return 0;
|
|
189 }
|
|
190
|
|
191 1;
|