1 2 3 4
my $dns = 'ACTAGCTAGCCATATTCG'; my $mutation = 'A'; my $pos = 8; substr( $dns, $pos-1, 1) = $mutation;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
#! /usr/bin/perl -l use strict; use warnings; { my @POOL = qw( A C G T ); sub mutate { my $str = shift; # original sequence my @positions = @_; # get all positions for mutations for my $pos ( @positions ) { # check each position my $original = substr $str, $pos-1, 1; # determine original my @replacer = grep { $_ ne $original } @POOL; # exclude original from replacement list substr( $str, $pos-1, 1) = $replacer[ rand @replacer ]; # replace original with a random item } # return mutated sequence return $str; } } my $sequence = "ACTA"; print mutate($sequence,3,4); # mutate at 3rd and 4th position of sequence