ProgramFile: test. pl
CopyCode The Code is as follows :#! /Bin/perl
# Filename: Test. pl
Use strict;
Use warnings;
# Search for a sequence that is better recognized
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 ";
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 random position subroutine Based on the sequence length
Sub randomposition
{
My ($ string) = @_;
Return int (RAND (length ($ string )));
}
# Subroutine: randomly selects an element from an array
Sub randelement
{
My (@ array) = @_;
Return $ array [Rand @ array];
}
# Subroutine: reference the previous subroutine and randomly select one of the four bases of atgc.
Sub randomnucleotide
{
My (@ nucleus otides) = QW/a t g C /;
Return randelement (@ nucleus otides );
}
# Subroutine: a subroutine that generates a mutation
Sub mutate
{
My ($ DNA) = @_;
My (@ nucleus otides) = QW (a t g C );
My ($ position) = randomposition ($ DNA );
My ($ newbase) = randomnucleotide (@ nucleus otides );
Substr ($ DNA, $ position, 1, $ newbase); # substr ($ string, $ initial_position, $ length, replacement substring)
Return $ DNA;
}
The result is as follows:
F: \> Perl \ test. pl
Mutate
Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Here is the original DNA:
Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Here is the mutant DNA:
Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaataaaaaaaaaaaaaaaaa
Here are 10 more successive mutations:
Acaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaataaaaaaaaaaaaaaaaa
Acaaaaaaaaacaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaataaaaaaaaaaaaaaaaa
Acaaaaaaaaacaaaaaaaaaaaaataaaaaaaaaaaaaaaaataaaaaaaaaaaaaaa
Acaaaaaaaaacaaaaaaaaaaaaataaaaaaaaaaaaaaaaataaaaaaaaaaaaaaa
Acaaaaaaaaacaaaaaaaaaaaaataaaaaaaaaaaaaaaaataaaaaaaaaaaaaaa
Acaaaaaaaaacaaaaaaaaaaaaataaaaaaaaaaaaaaaaatgaaaaaaaaaaaaaa
Actaaaaaaaacaaaaaaaaaaaaataaaaaaaaaaaaaaaaatgaaaaaaaaaaaaaa
Actaaaaaaaacaaaaaaaaaaaaataagaaaaaaaaaaaatgaaaaaaaaaaaaaa
Actaaaaaaaacaaaaaaaaaaaaataagaaaaaaaaaaaatgtaaaaaaaaaaaaaaa
Actaaaaaaaacaaaaaaaaaaaaataagaaaaaaaaaaaatgtaaaaaaaaaaaaaaa
F: \>