Advertisement
Guest User

mutaciones

a guest
Feb 28th, 2015
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.40 KB | None | 0 0
  1. use warnings;
  2.  
  3. print "please type the filename of the sequence data ";
  4. $DNAfilename= <STDIN>;
  5. chomp $DNAfilename;
  6. open (DNAFILE,$DNAfilename);
  7. @DNA= <DNAFILE>;
  8. close DNAFILE;
  9.  
  10. $DNA=join ('',@DNA);
  11. $DNA=~ s/\s//g;
  12.  
  13. my $DNAname = 'Wolbachiagenoma.fasta';
  14. my $i;
  15. my $mutant;
  16. my $filename = 'report.txt';
  17. open(my $fh, '>', $filename) or die "Could not open file '$filename' $!";
  18.  
  19. srand(time|$$);
  20. $mutant = mutate($DNA);
  21.  
  22. print $fh "\nMutate DNA\n\n";
  23.  
  24. print $fh "\nHere is the original DNA:\n\n";
  25. print $fh "$DNA\n";
  26.  
  27. print $fh "\nHere is the mutant DNA:\n\n";
  28. print $fh "$mutant\n";
  29.  
  30. print $fh "\nHere are 10 more successive mutations:\n\n";
  31.  
  32. for ($i=0 ; $i < 10 ; ++$i) {
  33.     $mutant = mutate($mutant);
  34.     print $fh "$mutant\n";
  35. }
  36.  
  37. close $fh;
  38. print "done\n";
  39.  
  40. exit;
  41.  
  42. sub mutate {
  43.  
  44.     my($dna) = @_;
  45.  
  46.     my(@nucleotides) = ('A', 'C', 'G', 'T');
  47.  
  48. my($position) = randomposition($dna);
  49. my($newbase) = randomnucleotide(@nucleotides);
  50.  
  51. substr($dna,$position,1,$newbase);
  52.  
  53.     return $dna;
  54. }
  55.  
  56.  
  57. sub randomelement {
  58.  
  59.     my(@array) = @_;
  60.  
  61.     return $array[rand @array];
  62. }
  63.  
  64. sub randomnucleotide {
  65.  
  66.     my(@nucleotides) = ('A', 'C', 'G', 'T');
  67.  
  68.     # scalar returns the size of an array.
  69.     # The elements of the array are numbered 0 to size-1
  70.     return randomelement(@nucleotides);
  71. }
  72.  
  73.  
  74. sub randomposition {
  75.  
  76.     my($string) = @_;
  77. return int rand length $string;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement