Thread Punkt-Mutation (2 answers)
Opened by Skyblader at 2014-09-06 17:10

Linuxer
 2014-09-06 17:51
#177120 #177120
User since
2006-01-27
3875 Artikel
HausmeisterIn

user image
Sorry, mir war gerade danach:

Code (perl): (dl )
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
meine Beiträge: I.d.R. alle Angaben ohne Gewähr und auf Linux abgestimmt!
Die Sprache heisst Perl, nicht PERL. - Bitte Crossposts als solche kenntlich machen!

View full thread Punkt-Mutation