Program file: test.pl
Copy the code The code is as follows:
#! / bin / perl
# filename: test.pl
use strict;
use warnings;
#Just find a 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";
}
#Subroutine: define a subroutine with random positions according to the length of the sequence
sub randomposition
{
my ($ string) = @ _;
return int (rand (length ($ string)));
}
#Subroutine: randomly select an element from an array
sub randelement
{
my (@array) = @ _;
return $ array [rand @array];
}
#Subroutine: Refer to the above subroutine and randomly select one from the four bases of ATGC
sub randomnucleotide
{
my (@nucleotides) = qw / A T G C /;
return randelement (@nucleotides);
}
#Subroutine: Generate a mutant subroutine
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;
}
The results are as follows:
F: \> perl \ test.pl
Mutate
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Here is the original DNA:
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Here is the mutant DNA:
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAATAAAAAAAAAAAAAAA
Here are 10 more successive mutations:
ACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAATAAAAAAAAAAAAAAA
ACAAAAAAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAATAAAAAAAAAAAAAAA
ACAAAAAAAAACAAAAAAAAAAAAATAAAAAAAAAAAAAAATAAAAAAAAAAAAAAA
ACAAAAAAAAACAAAAAAAAAAAAATAAAAAAAAAAAAAAATAAAAAAAAAAAAAAA
ACAAAAAAAAACAAAAAAAAAAAAATAAAAAAAAAAAAAAATAAAAAAAAAAAAAAA
ACAAAAAAAAACAAAAAAAAAAAAATAAAAAAAAAAAAAAATGAAAAAAAAAAAAAA
ACTAAAAAAAACAAAAAAAAAAAAATAAAAAAAAAAAAAAATGAAAAAAAAAAAAAA
ACTAAAAAAAACAAAAAAAAAAAAATAATAAAAAAAAAAAAATGTGAAAAAAAAAAAAAA
ACTAAAAAAAACAAAAAAAAAAAAATAAGAAAAAAAAAAAATGTAAAAAAAAAAAAA
ACTAAAAAAAACAAAAAAAAAAAAATAAGAAAAAAAAAAAATGTAAAAAAAAAAAAA
F: \>