Using Perl to implement random simulation program code for biological mutation--application techniques

Source: Internet
Author: User
Tags rand

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

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.