模拟遗传漂变【PERL】

#!/usr/bin/perl -w 
use strict;

my $DNA="AAAAAAAAAAAAAAAAAAAAAA";
my ($i,$mutant);

srand(time|$$);
$mutant=mutate($DNA);
print "\nMutate DNA\n";
print "\nThe original DNA:\n$DNA\n";
print "\nThe mutant DNA:\n$mutant\n";

print "\nHere are 10 more successive mutations:\n";
for ($i=0;$i<10;++$i){
	$mutant = mutate($mutant);
	print "$mutant\n";
}

sub mutate{
	my ($dna) = @_;
	my (@nucleotides) = ('A','C','G','T');
	
	my($position) = randomposition($dna);
	my($newbase) = randomposition(@nucleotides);
	substr($dna,$position,1,$newbase);
	
	return $dna;
}

sub randomelement{
	my(@array) = @_;
	return $array[rand @array];
}

sub randomposition{
	my($string) = @_;
	return int rand length $string;
}

你可能感兴趣的:(Perl)