Use Perl to implement random simulation program code for biological mutation

Source: Internet
Author: User

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: \>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.