in reply to Help regarding the outout of the program
Here's a reformed version. Your main problem seemed to be the extra increment of $i down at the bottom. There is no reason to do this with a loop if you already know the position so I removed it and inlined one of the subs. Give it a shot.
use warnings; use strict; my $seq = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'; print "The DNA sequence is : $seq\n"; mutate($seq); exit; sub mutate { my $dna = shift; my $position = int(rand(length($dna))); print " mutation at base position ". ($position+1) . "\n"; my $nucleotide; do { $nucleotide = randombase(); } until ( $nucleotide ne substr($dna,$position,1) ); substr($dna, $position, 1, $nucleotide); print "$dna\n"; } sub randombase { my ( @nucleo ) = qw ( A T C G ); return $nucleo[rand(@nucleo)]; }
|
|---|