$xLength = @xSeq = qw (A A G G C C T T); $yLength = @ySeq = qw (A C G T A C T T); $LM[$_][0] = 0 for 0..$xLength; #### x-Achse mit 0 füllen #### $LM[0][$_] = 0 for 0..$yLength; #### y-Achse mit 0 füllen #### #### wert ermitteln #### for my $x (1..$xLength) { for my $y (1..$yLength) { if ($xSeq[$y-1] eq $ySeq[$x-1]) { $tauscher = $LM[$x-1][$y-1] + 2 } else { $tauscher = $LM[$x-1][$y-1] - 1 } for ($LM[$x-1][$y]-1, $LM[$x][$y-1]-1, 0) { $tauscher = $_ if $_ > $tauscher } $LM[$x][$y] = $tauscher; } } #### höchsten Wert finden #### $Hochw = 0; for my $x (0..$xLength) { for my $y (0..$yLength) { if ($Hochw < $LM[$x][$y]) { $Hochw = $LM[$x][$y]; $Hochx = $x; $Hochy = $y; } } } #### Optimale align #### ($CursorWert, $x, $y, @align) = ($Hochw, $Hochx, $Hochy); while() { if (( $CursorWert == $LM[$x-1][$y-1] + 2 ) or ( $CursorWert == $LM[$x-1][$y-1] - 1 ) ) { $x--; $y--; push @align, "$xSeq[$x]$ySeq[$y]"; } elsif ( $CursorWert == $LM[$x-1][$y] - 1 ) { $x--; push @align, "-$ySeq[$y]"; } elsif ( $CursorWert == $LM[$x][$y-1] - 1 ) { $y--; push @align, "$xSeq[$x]-"; } else { last } $CursorWert=$LM[$x][$y]; last if $x == 0 or $y == 0; } print <