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!

problem with my subroutine

Status
Not open for further replies.

mama12

Programmer
Oct 18, 2005
22
NL
Hallo,

I have problem in my subroutine, I want to DNA mutate my DNA at position 3 and 9. can some one here tel me how can I do it.

best regards



#!/usr/bin/perl

use strict;
use warnings;

my $DNA = 'ATGCATGCAT';

my $mutated_DNA = mutate_DNA($DNA);

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

exit;

sub mutate_DNA {

my($DNA) = @_;

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

my $position = 3;

my $base = $bases[$position];

my $newbase;

do {
$newbase = $bases[rand @bases];
} until ($newbase ne $base);

substr($DNA, $position, 1) = $newbase;

return $DNA;
}
 
I wasn't sure why this code wasn't verifying that the new sequence position didn't match was was being fed into the sub-routine, so I changed it a bit. If that's not correct, please feel free to change it back to what you had before.

Something like the following:

Code:
#!/usr/bin/perl

use strict;
use warnings;

my $DNA = 'ATGCATGCAT';
my @positions = qw(3 6 9);

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 $newbase ."\n";
			} until ($newbase ne $base);

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

        return $DNA;
}

- George
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top