#!/bin/perl
# filename:
use strict;
use warnings;
#Search for any sequence that is easier to identify
my $DNA="AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n";
my $i;
my $mutant;
srand(time|$$);
$mutant=mutate($DNA);
print "Mutate \n". $DNA;
print "Here is the original DNA:\n";
print "$DNA\n";
print "Here is the mutant DNA:\n\n";
print "$mutant\n";
print "Here are 10 more successive mutations:\n";
for ($i=0;$i<10;++$i)
{
$mutant=mutate($mutant);
print "$mutant\n";
}
#Subprogram: Define a random position subroutine based on the length of the sequence.
sub randomposition
{
my($string)=@_;
return int(rand(length($string)));
}
#Subprogram: Randomly select an element from an array
sub randelement
{
my(@array)=@_;
return $array[rand @array];
}
#Subprogram: Refer to the above subprogram and randomly select one from the four bases of ATGC.
sub randomnucleotide
{
my (@nucleotides)=qw/A T G C/;
return randelement(@nucleotides);
}
#Subprogram: Subprogram that generates mutations
sub mutate
{
my($dna)=@_;
my(@nucleotides)=qw(A T G C);
my($position)=randomposition($dna);
my($newbase)=randomnucleotide(@nucleotides);
substr($dna,$position,1,$newbase);#substr($string,$initial_position,$length,replacement substring)
return $dna;
}