2 # BioPerl module for Bio::SeqEvolution::Factory
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Heikki Lehvaslaiho <heikki at bioperl dot org>
8 # Copyright Heikki Lehvaslaiho
10 # You may distribute this module under the same terms as perl itself
12 # POD documentation - main docs before the code
16 Bio::SeqEvolution::Factory - Factory object to instantiate sequence evolving classes
20 # not an instantiable class
24 This is the factory class that can be used to call for a specific
25 model to mutate a sequence.
27 Bio::SeqEvolution::DNAPoint is the default for nucleotide sequences
28 and the only implementation at this point.
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
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.
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
58 https://github.com/bioperl/bioperl-live/issues
62 Heikki Lehvaslaiho E<lt>heikki at bioperl dot orgE<gt>
66 Additional contributor's names and emails here
70 The rest of the documentation details each of the object methods.
71 Internal methods are usually preceded with a _
76 # Let the code begin...
79 package Bio
::SeqEvolution
::Factory
;
82 use Bio
::SeqEvolution
::EvolutionI
;
83 use base
qw(Bio::Root::Root Bio::SeqEvolution::EvolutionI);
88 Usage : my $obj = Bio::SeqEvolution::Factory->new();
89 Function: Builds a new Bio:SeqEvolution::EvolutionI object
90 Returns : Bio:SeqEvolution::EvolutionI object
91 Args : -type => class name
93 See L<Bio:SeqEvolution::EvolutionI>
98 my($caller,@args) = @_;
99 my $class = ref($caller) || $caller;
102 @param{ map { lc $_ } keys %param } = values %param; # lowercase keys
104 if ( $class eq 'Bio::SeqEvolution::Factory') {
106 #@param{ map { lc $_ } keys %param } = values %param; # lowercase keys
108 if (exists $param{'-type'}) {
109 # $self->type($param{'-type'});
111 $param{'-type'} = 'Bio::SeqEvolution::DNAPoint';
112 #$self->type('Bio::SeqEvolution::DNAPoint'} unless $seq->alphabet == 'protein'
114 my $type = $param{'-type'};
115 return unless( $class->_load_format_module($param{'-type'}) );
116 return $type->new(%param);
118 my ($self) = $class->SUPER::new
(%param);
119 $self->_initialize(%param);
125 my($self, @args) = @_;
127 $self->SUPER::_initialize
(@args);
129 @param{ map { lc $_ } keys %param } = values %param; # lowercase keys
131 exists $param{'-seq'} && $self->seq($param{'-seq'});
132 exists $param{'-set_mutated_seq'} && $self->set_mutated_seq($param{'-set_mutated_seq'});
133 exists $param{'-identity'} && $self->identity($param{'-identity'});
134 exists $param{'-pam'} && $self->pam($param{'-pam'});
135 exists $param{'-mutation_count'} && $self->mutation_count($param{'-mutation_count'});
140 =head2 _load_format_module
142 Title : _load_format_module
143 Usage : *INTERNAL SeqIO stuff*
144 Function: Loads up (like use) a module at run time on demand
151 sub _load_format_module
{
152 my ($self, $format) = @_;
153 my $module = $format;
157 $ok = $self->_load_module($module);
161 $self: $format cannot be found
173 Usage : $obj->type($newval)
174 Function: Set used evolution model. It is set by giving a
175 valid Bio::SeqEvolution::* class name
176 Returns : value of type
177 Args : newvalue (optional)
179 Defaults to Bio::SeqEvolution::DNAPoint.
186 $self->{'_type'} = shift @_;
187 $self->_load_module($self->{'_type'});
189 return $self->{'_type'} || 'Bio::SeqEvolution::DNAPoint';
192 =head1 mutation counters
194 The next three methods set a value to limit the number of mutations
195 introduced the the input sequence.
202 Usage : $obj->identity($newval)
203 Function: Set the desired identity between original and mutated sequence
204 Returns : value of identity
205 Args : newvalue (optional)
211 $self->{'_identity'} = shift @_ if @_;
212 return $self->{'_identity'};
219 Usage : $obj->pam($newval)
220 Function: Set the wanted Percentage of Accepted Mutations, PAM
221 Returns : value of PAM
222 Args : newvalue (optional)
224 When you are measuring sequence divergence, PAM needs to be
225 estimated. When you are generating sequences, PAM is simply the count
226 of mutations introduced to the reference sequence normalised to the
227 original sequence length.
233 $self->{'_pam'} = shift @_ if @_;
234 return $self->{'_pam'};
237 =head2 mutation_count
239 Title : mutation_count
240 Usage : $obj->mutation_count($newval)
241 Function: Set the number of wanted mutations to the sequence
242 Returns : value of mutation_count
243 Args : newvalue (optional)
249 $self->{'_mutation_count'} = shift @_ if @_;
250 return $self->{'_mutation_count'};
258 Usage : $obj->seq($newval)
259 Function: Set the sequence object for the original sequence
260 Returns : The sequence object
261 Args : newvalue (optional)
263 Setting this will reset mutation and generated mutation counters.
270 $self->{'_seq'} = shift @_ ;
271 return $self->{'_seq'};
272 $self->reset_mutation_counter;
273 $self->reset_sequence_counter;
275 return $self->{'_seq'};
281 Usage : $obj->seq_type($newval)
282 Function: Set the returned seq_type to one needed
283 Returns : value of seq_type
284 Args : newvalue (optional)
286 Defaults to Bio::PrimarySeq.
293 $self->{'_seq_type'} = shift @_;
294 $self->_load_module($self->{'_seq_type'});
296 return $self->{'_seq_type'} || 'Bio::PrimarySeq';
300 =head2 get_mutation_counter
302 Title : get_mutation_counter
303 Usage : $obj->get_mutation_counter()
304 Function: Get the count of sequences created
305 Returns : value of counter
310 sub get_mutation_counter
{
311 return shift->{'_mutation_counter'};
315 =head2 reset_mutation_counter
317 Title : reset_mutation_counter
318 Usage : $obj->reset_mutation_counter()
319 Function: Resert the counter of mutations
320 Returns : value of counter
325 sub reset_mutation_counter
{
326 shift->{'_mutation_counter'} = 0;
331 =head2 get_sequence_counter
333 Title : get_sequence_counter
334 Usage : $obj->get_sequence_counter()
335 Function: Get the count of sequences created
336 Returns : value of counter
341 sub get_sequence_counter
{
342 return shift->{'_sequence_counter'};
345 =head2 reset_sequence_counter
347 Title : reset_sequence_counter
348 Usage : $obj->reset_sequence_counter()
349 Function: Resert the counter of sequences created
350 Returns : value of counter
353 This is called when ever mutated sequences are reassigned new values
354 using methods seq() and mutated_seq(). As a side affect, this method
355 also recreates the intermal alignment that is used to calculate the
360 sub reset_sequence_counter
{
362 $self->{'_sequence_counter'} = 0;
363 $self->_init_alignment;
372 Usage : $obj->each_seq($int)
374 Returns : an array of sequences mutated from the reference sequence
375 according to evolutionary parameters given
384 $self->throw("[$number] ". ' should be a positive integer')
385 unless $number =~ /^[+\d]+$/;
388 for (my $count=1; $count<$number; $count++) {
389 push @array, $self->next_seq();
399 Title : each_mutation
400 Usage : $obj->each_mutation
401 Function: return the mutations leading to the last generated
403 Returns : an array of Bio::Variation::DNAMutation objects
404 Args : optional argument to return an array of stringified names
412 return @
{$self->{'_mutations'}} if $string;
417 my $dnamut = Bio
::Variation
::DNAMutation
->new
423 $dnamut->allele_ori( Bio
::Variation
::Allele
->new(-seq
=> $2,
424 -alphabet
=> 'dna') );
425 $dnamut->add_Allele( Bio
::Variation
::Allele
->new(-seq
=> $3,
426 -alphabet
=> 'dna') );
428 } @
{$self->{'_mutations'}}
432 sub get_alignment_identity
{
434 return $self->{'_align'}->overall_percentage_identity;
440 return $self->{'_align'}->remove_gaps('-', 'all-gaps');
444 =head1 Internal methods
449 =head2 _increase_mutation_counter
451 Title : _increase_mutation_counter
452 Usage : $obj->_increase_mutation_counter()
453 Function: Internal method to increase the counter of mutations performed
454 Returns : value of counter
459 sub _increase_mutation_counter
{
460 return shift->{'_mutation_counter'}++;
465 =head2 _increase_sequence_counter
467 Title : _increase_sequence_counter
468 Usage : $obj->_increase_sequence_counter()
469 Function: Internal method to increase the counter of sequences created
470 Returns : value of counter
475 sub _increase_sequence_counter
{
476 return shift->{'_sequence_counter'}++;