Dear all,
Actually i posted a similar question on Biostars about usage of Needleman perl module.
i have problem with the following script (kind helps from a biostars member). Could anyone help to correct it? THANKS A LOT!
My ideal output is:
However, the following script produces the below result
script:
Actually i posted a similar question on Biostars about usage of Needleman perl module.
i have problem with the following script (kind helps from a biostars member). Could anyone help to correct it? THANKS A LOT!
My ideal output is:
HTML Code:
CTAT-------CTA CTATTTTTTTTCTG -9
HTML Code:
CTATCTA CTATTTTTTTTCTG -9
HTML Code:
#!/usr/bin/env perl
use strict;
use warnings;
use Algorithm::NeedlemanWunsch;
### scoring function:
sub score_sub {
if (!@_) {
return -2; # gap penalty
}
## mismatch scores -1, match +1
return ($_[0] eq $_[1]) ? 1 : -1;
}
my $a = "ATCTATC";
my $b = "GTCTTTTTTTTATC";
my @a = split //, $a; # make an array
my @b = split //, $b;
my ($a_align, $b_align);
sub on_align {
$a_align .= $a[$_[0]];
$b_align .= $b[$_[1]];
};
sub on_shift_a { $a_align .= $a[$_[0]];};
sub on_shift_b { $b_align .= $b[$_[0]];};
sub on_select_align { print "(select_align)\n"; return (keys (%{$_[0]})) [0]};
my $matcher = Algorithm::NeedlemanWunsch->new(\&score_sub);
my $score = $matcher->align(
\@a,
\@b,
{ align => \&on_align,
shift_a => \&on_shift_a,
shift_b => \&on_shift_b,
# select_align => \&on_select_align
});
print "$a_align\t$b_align\t";
print "$score\n";