Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mutate DNA probleem

Status
Not open for further replies.

mama12

Programmer
Oct 18, 2005
22
NL
Hi all,

I want to mutate my DNA $DNA between 174 and 249, and save it in file, the user will give the name of the file.

I have probleem in the mutation of DNA
########################################################
#!/usr/bin/perl

use strict;
use warnings;

print "file name: ";

$file = <STDIN>;


open FH, ">$file";

my $DNA = "GCTTACGGGAGTTGCCTGGGCCAGAGCGTCATTCGGTGGGGGTACATGGATCCGATAGACTAGCGCGTACTCCATCCTCGGGAAGAAAAGCATGTAGCGCGTCGGGCTGCTGCACGCTCGGGCATGGCGACTCCTACCGATACTCTAAAACCCTGGAAGTATACGTTATTCATAGGTGCACTTCTTCTGGTTATATTGATAGAAGGCGTAAACAGTCTACTCTCGAGTACACGCGACCAGGGCGCATTCAGATTTACTCGATGTATTAGAGTGCACAGCCCCATCAACGTCTTGATCGTTCAACTGCTCTCGGGCTCGCGCTGCCATTAAACAGTTCACGGCAGGCGCCCTGGGGATGCGGCGCATCAAGGCACCGGGACCGTCCGTATTTTCCCCATTAAGTTACGCATCTCTATAGTGGCGTTATACGACTAGAGTGTAATGATGATTTCCGACGCTCGTCCGAAGTATAAAAAGGCTCATTTAACTCGAGTCGTTACCTATTTCCTCCGGTGAGATCGTTCTGTCATTGCGCTCAGTCTTGGGTTTATTGCCTTCCTAATCGGTCGGCCTGCTTATGGCTCCACTCACTGCAACATGCTAATGTATAAGCTTCCACAAAACTGTGACTTGGTTCGATTGACCCCTATGCAGCATTTTTGTGTCCCCCTCGTCGACGACAATGTGCTAGCCATGCACCTGGGAACGAGAGGACGGGCTAACAACACGCTTGGCTTAATGACTGCCTTGTCTCCGGACCGTAGAACATTGACGATTACGGGTTCGGGATAGTGACGTTCACTTTATGCCTCAAACTTCAACGGACCCCGTCATATGGGTGGGTGGAGGGTGCTTCCGTGACCGTATGCACGTTAGTGGAACTCAGTCGACGACCCCCGGGGTTACAAACCCCACACAGGGATCCCAAAGTCGTTTAATGGAGGGGTAGCCTCTGCCCCTATACTAGATAAAGCCACTTCGAGTGATGCCAGTAGACCAACCCCGCGTTTCCACAGGCGAAAGGATCTAGGAGGTCACCCTCGAACCGCCTGATCACTCCCTGAGGCCCTTTACGCGGGGAGGCTTCGGCTTCTTTTCACCAGCCAATATGCAAAGATTTTTCTAAGCTAGATTCTGAGCTAACCTACGCATTGATGTGTTGCTTAAATTACCCAGCCACTTTACCAAGCATCCCGCAGCTGTCACCGCCTGGGTGATCTGTGCCGTTTGACGGTTTACTTCCTTGCATGGCGGTGCGCAATGACCTAGAGTGAGACGATTCGGTAATAACCGCATACCGCATCCGTGAGAGTCTGCTCACTGCTCCAGCCTCAAACAGTATTTGTAAGATTTAATAGACGGTGGCAAATTAATCCATAAACCGAAGATGAGCGACATAGACGCAAGTCATACTGAACACCGTCCCAGTTGCCAAGTAGCTATCATGTCCACTAATACAGTGGACGGCAGATGTAGGGCCCTCTGATCCCACGTCTCGGCAACACTGCAGTTTGCAACACAACGATGGGATCGACTGGCGCATCGAGCCACGACCGTACTACTAATTTCAGGAGTTGTGGTTGGAGAGTCGGAGCACCCTATATGGCATCATGCGCCGAAGATAAGGGGGCCGGGGATTCAACGACTCCTCGTATGTAGTCCTGGCCGCTCAAGTTGTCTCGCTAGGATATGCAACAGATGATCCTCTCGCAACACCGAGACGAAAGGCGGCTTGTACTAGCCCTACACCCGCAAGCGGCGACTAGTCAGCGCGCTGCGCATACGATATCTGCGATTGAAGTAAAATTCAAAGCATGTCCAAGTACAGCTATATGCGAGCTCGATAAGGTACTAGCCAGGGCTCTTGTTCTCTTGGTCAGTACTACCGGGTCCAGATTGAAGCAGGGTCTGATTGCGTGCATTCATGTCACTCATGATGGAATATTGCTCCGGCTGTTGCACCTCAGAGCCATGCCACTCTCAGGTTAATAGTCAAGCCACTCTCTTGGACCATCCAGTCCCTCCTTATAGGATCAGACGGGTTCTTTCTGCCGACTGAACCGCAACTCACTTCAACCTTCTGTGATCCAATGTTCCGCCGGTGCCCCTGAAAGAAAGTGGGCTGTAGTGGTAGGGCAAGTCCACTCCTCTGGCCCGGGTTTGTTGAACGGAAGTACGAAGCATTACGTCTCGTTATACGTAGTTACCTAGGGCAGATACGACATGCGTGCCCATGTCAACTGTGATAGAGCGGAAGGTGCCAATAATACAGACACAGCACCGCTCGCAGCGTAGGAACCACACGTTGTAATTACCAGTTCTCAACTCCCTCACTTTCCGCGGCTAATCATATATATAGTATTGCGGTCGTATCGTCCAAAACTGTCCGGACCATAGACATGCCCGCGGAATATAACAACAAGGTTCAGCGGGTCGCGAGGGGAGAAGTCAGTGAAATCCAAAAATCAATTTCTGCACAACTCCTTTCCTAGACGAGACG";

my @positions = qw ('174''175' '176' '177' '178' '179' '180' '181' '182' '183' '184' '185' '186' '187' '188' '189''190' '191' '192' '193' '194' '195' '196' '197' '198' '199' '200' '201' '202' '203' '204' '205' '206' '207' '208' '209''210' '211' '212' '213' '214' '215' '216' '217' '218' '219' '220' '221' '222'
'223' '224' '225' '226' '227' '228''229' '230' '231' '232' '233' '234' '235' '236' '237' '238' '239' '240' '241' '242' '243' '244' '245' '246' '247''248' '249') ;

my $mutated_DNA = mutate_DNA($DNA, \@positions);

print "$DNA imutates to $mutated_DNA\n";

exit;

sub mutate_DNA {
my $DNA = shift;
my $position = shift;

my @bases = qw(A C G T);

foreach my $pos (@{$position}) {
print $pos ."\t";
my $base = substr ($DNA, $pos, 1);
print $base ."\t";
my $newbase;

do {
$newbase = $bases[rand @bases];
print FH "$newbase" ."\n";
} until ($newbase ne $base);

substr($DNA, $pos, 1) = $newbase;
}

return $DNA;
}

close FH;
 
note that the code you posted will not even compile because $file was never declared with "my". Having said that, I think this is what you are trying to do:

Code:
#!/usr/bin/perl
use strict;
use warnings;
print "file name: ";
my $file = <STDIN>;
open FH, ">$file";
my $DNA = 'GCTTACGGGAGTTGCCTGGGCCAGAGCGTCATTCGGTGGGGGTACATGGATCCGATAGACTAGCGCGTACTCCATCCTCGGGAAGAAAAGCATGTAGCGCGTCGGGCTGCTGCACGCTCGGGCATGGCGACTCCTACCGATACTCTAAAACCCTGGAAGTATACGTTATTCATAGGTGCACTTCTTCTGGTTATATTGATAGAAGGCGTAAACAGTCTACTCTCGAGTACACGCGACCAGGGCGCATTCAGATTTACTCGATGTATTAGAGTGCACAGCCCCATCAACGTCTTGATCGTTCAACTGCTCTCGGGCTCGCGCTGCCATTAAACAGTTCACGGCAGGCGCCCTGGGGATGCGGCGCATCAAGGCACCGGGACCGTCCGTATTTTCCCCATTAAGTTACGCATCTCTATAGTGGCGTTATACGACTAGAGTGTAATGATGATTTCCGACGCTCGTCCGAAGTATAAAAAGGCTCATTTAACTCGAGTCGTTACCTATTTCCTCCGGTGAGATCGTTCTGTCATTGCGCTCAGTCTTGGGTTTATTGCCTTCCTAATCGGTCGGCCTGCTTATGGCTCCACTCACTGCAACATGCTAATGTATAAGCTTCCACAAAACTGTGACTTGGTTCGATTGACCCCTATGCAGCATTTTTGTGTCCCCCTCGTCGACGACAATGTGCTAGCCATGCACCTGGGAACGAGAGGACGGGCTAACAACACGCTTGGCTTAATGACTGCCTTGTCTCCGGACCGTAGAACATTGACGATTACGGGTTCGGGATAGTGACGTTCACTTTATGCCTCAAACTTCAACGGACCCCGTCATATGGGTGGGTGGAGGGTGCTTCCGTGACCGTATGCACGTTAGTGGAACTCAGTCGACGACCCCCGGGGTTACAAACCCCACACAGGGATCCCAAAGTCGTTTAATGGAGGGGTAGCCTCTGCCCCTATACTAGATAAAGCCACTTCGAGTGATGCCAGTAGACCAACCCCGCGTTTCCACAGGCGAAAGGATCTAGGAGGTCACCCTCGAACCGCCTGATCACTCCCTGAGGCCCTTTACGCGGGGAGGCTTCGGCTTCTTTTCACCAGCCAATATGCAAAGATTTTTCTAAGCTAGATTCTGAGCTAACCTACGCATTGATGTGTTGCTTAAATTACCCAGCCACTTTACCAAGCATCCCGCAGCTGTCACCGCCTGGGTGATCTGTGCCGTTTGACGGTTTACTTCCTTGCATGGCGGTGCGCAATGACCTAGAGTGAGACGATTCGGTAATAACCGCATACCGCATCCGTGAGAGTCTGCTCACTGCTCCAGCCTCAAACAGTATTTGTAAGATTTAATAGACGGTGGCAAATTAATCCATAAACCGAAGATGAGCGACATAGACGCAAGTCATACTGAACACCGTCCCAGTTGCCAAGTAGCTATCATGTCCACTAATACAGTGGACGGCAGATGTAGGGCCCTCTGATCCCACGTCTCGGCAACACTGCAGTTTGCAACACAACGATGGGATCGACTGGCGCATCGAGCCACGACCGTACTACTAATTTCAGGAGTTGTGGTTGGAGAGTCGGAGCACCCTATATGGCATCATGCGCCGAAGATAAGGGGGCCGGGGATTCAACGACTCCTCGTATGTAGTCCTGGCCGCTCAAGTTGTCTCGCTAGGATATGCAACAGATGATCCTCTCGCAACACCGAGACGAAAGGCGGCTTGTACTAGCCCTACACCCGCAAGCGGCGACTAGTCAGCGCGCTGCGCATACGATATCTGCGATTGAAGTAAAATTCAAAGCATGTCCAAGTACAGCTATATGCGAGCTCGATAAGGTACTAGCCAGGGCTCTTGTTCTCTTGGTCAGTACTACCGGGTCCAGATTGAAGCAGGGTCTGATTGCGTGCATTCATGTCACTCATGATGGAATATTGCTCCGGCTGTTGCACCTCAGAGCCATGCCACTCTCAGGTTAATAGTCAAGCCACTCTCTTGGACCATCCAGTCCCTCCTTATAGGATCAGACGGGTTCTTTCTGCCGACTGAACCGCAACTCACTTCAACCTTCTGTGATCCAATGTTCCGCCGGTGCCCCTGAAAGAAAGTGGGCTGTAGTGGTAGGGCAAGTCCACTCCTCTGGCCCGGGTTTGTTGAACGGAAGTACGAAGCATTACGTCTCGTTATACGTAGTTACCTAGGGCAGATACGACATGCGTGCCCATGTCAACTGTGATAGAGCGGAAGGTGCCAATAATACAGACACAGCACCGCTCGCAGCGTAGGAACCACACGTTGTAATTACCAGTTCTCAACTCCCTCACTTTCCGCGGCTAATCATATATATAGTATTGCGGTCGTATCGTCCAAAACTGTCCGGACCATAGACATGCCCGCGGAATATAACAACAAGGTTCAGCGGGTCGCGAGGGGAGAAGTCAGTGAAATCCAAAAATCAATTTCTGCACAACTCCTTTCCTAGACGAGACG';
print "$DNA\n";
my @positions = (174..249);
my $mutated_DNA = mutate_DNA($DNA, \@positions);
print "$mutated_DNA\n";
close FH;
exit;

sub mutate_DNA {
   my $DNA = shift;
   my $position = shift;
   my @bases = qw(A C G T);
   foreach my $pos (@{$position}) {
      my $base = substr  ($DNA, $pos, 1);
      my $newbase;
      LOOP: {
         $newbase = $bases[int(rand @bases)];
         redo LOOP if $newbase eq $base; 
         print FH "$newbase\n";
      }
      substr($DNA, $pos, 1, $newbase);
  }
  return $DNA;
}
 
you will also need to chomp $file:

chomp(my $file = <STDIN>);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top