Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use warnings;
- print "please type the filename of the sequence data ";
- $DNAfilename= <STDIN>;
- chomp $DNAfilename;
- open (DNAFILE,$DNAfilename);
- @DNA= <DNAFILE>;
- close DNAFILE;
- $DNA=join ('',@DNA);
- $DNA=~ s/\s//g;
- my $DNAname = 'Wolbachiagenoma.fasta';
- my $i;
- my $mutant;
- my $filename = 'report.txt';
- open(my $fh, '>', $filename) or die "Could not open file '$filename' $!";
- srand(time|$$);
- $mutant = mutate($DNA);
- print $fh "\nMutate DNA\n\n";
- print $fh "\nHere is the original DNA:\n\n";
- print $fh "$DNA\n";
- print $fh "\nHere is the mutant DNA:\n\n";
- print $fh "$mutant\n";
- print $fh "\nHere are 10 more successive mutations:\n\n";
- for ($i=0 ; $i < 10 ; ++$i) {
- $mutant = mutate($mutant);
- print $fh "$mutant\n";
- }
- close $fh;
- print "done\n";
- exit;
- sub mutate {
- my($dna) = @_;
- my(@nucleotides) = ('A', 'C', 'G', 'T');
- my($position) = randomposition($dna);
- my($newbase) = randomnucleotide(@nucleotides);
- substr($dna,$position,1,$newbase);
- return $dna;
- }
- sub randomelement {
- my(@array) = @_;
- return $array[rand @array];
- }
- sub randomnucleotide {
- my(@nucleotides) = ('A', 'C', 'G', 'T');
- # scalar returns the size of an array.
- # The elements of the array are numbered 0 to size-1
- return randomelement(@nucleotides);
- }
- sub randomposition {
- my($string) = @_;
- return int rand length $string;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement