convert code into matlab code

hi, i badly need this code, but it is not matlab code. this is code foe sequence local alignment(smith-waterman), I did not find it as matlab code .I converted most of this code but the last part, I did not know the commands of this programming language can anybody help to convert the following code into matlab?
  1. trace-back
my $align1 = "";
my $align2 = "";
my $j = $max_j;
my $i = $max_i;
while (1) {
last if $matrix[$i][$j]{pointer} eq "none";
if ($matrix[$i][$j]{pointer} eq "diagonal") {
$align1 .= substr($seq1, $j-1, 1);
$align2 .= substr($seq2, $i-1, 1);
$i--; $j--;
}
elsif ($matrix[$i][$j]{pointer} eq "left") {
$align1 .= substr($seq1, $j-1, 1);
$align2 .= "-";
$j--;
}
elsif ($matrix[$i][$j]{pointer} eq "up") {
$align1 .= "-";
$align2 .= substr($seq2, $i-1, 1);
$i--;
}
}
$align1 = reverse $align1;
$align2 = reverse $align2;
print "$align1\n";
print "$align2\n";
thanks in advance

 采纳的回答

Looks like perl.
last if condition
translates to
if condition; break; end
and
A .= B
translates to
A = [A B]
and
$matrix[$i][$j]{pointer}
translates to
matrix(i,j).pointer
and
reverse $align1
translates to
fliplr(align1)

5 个评论

thanks walter,
do u mean that
$matrix[$i][$j]{score} and $matrix[$i][$j]{pointer}
like struture
matrix=structure('score', var1, 'pointer',var2
I did not understand what substr mean, here
it is not call fun.
# calculate match score
my $letter1 = substr($seq1, $j-1, 1);
my $letter2 = substr($seq2, $i-1, 1);
if ($letter1 eq $letter2) {
$diagonal_score = $matrix[$i-1][$j-1]{score} + $MATCH;
}
else {
$diagonal_score = $matrix[$i-1][$j-1]{score} + $MISMATCH;
}
for more details:
what is this :
my ($diagonal_score, $left_score, $up_score);
is it array with three dim?
for(my $i = 1; $i <= length($seq2); $i++) {
for(my $j = 1; $j <= length($seq1); $j++) {
my ($diagonal_score, $left_score, $up_score);
# calculate match score
my $letter1 = substr($seq1, $j-1, 1);
my $letter2 = substr($seq2, $i-1, 1);
if ($letter1 eq $letter2) {
$diagonal_score = $matrix[$i-1][$j-1]{score} + $MATCH;
}
else {
$diagonal_score = $matrix[$i-1][$j-1]{score} + $MISMATCH;
}
substr($seq1, $j-1, 1) translates as seq1(j-1:j-1+1), which is to say seq1(j-1:j)
"my" is used to declare local variables in perl. The code
my ($diagonal_score, $left_score, $up_score);
can (often) just be dropped in MATLAB as MATLAB does not have local variables.
You were very close on the structure but MATLAB uses "struct" rather than "structure":
matrix=struct('score', var1, 'pointer',var2);
hi walter,
this code of perl is very tired:
I totally converted it of course with you help , but I found out something I forgot it so I have not correct result
I looked for in google about what mean 'next' with 'if' in perl , but did not understand it, I did not pick up what is the role of 'next' here:
if ($diagonal_score <= 0 and $up_score <= 0 and $left_score <= 0) {
$matrix[$i][$j]{score} = 0;
$matrix[$i][$j]{pointer} = "none";
next; # terminate this iteration of the loop
}
many thanks in advance
"next" in perl is the equivalent of "continue" -- that is, skip any further instructions in the body of the loop and start the next iteration of the loop.
This contrasts with perl's "last", which is the equivalent of "break" -- that is, skip any further instructions in the body of the loop and exit the loop itself, continuing on after the end of the loop.

请先登录,再进行评论。

更多回答(1 个)

Diego
Diego 2011-12-30

0 个投票

If you have the bioinfo toolbox, then you probably have the swalign file that implements the smith-waterman algorithm. On the other hand, I just discovered that Matlab runs perl scripts smoothly! In my case, I have a perl script that uses the bioperl module and Matlab ran it!. I said this because I was facing a similar problem, and these tips may help you to accomplish your work. Regards, Diego

4 个评论

Huda is attempting to use Smith-Waterman, an algorithm designed for biological sequence alignment, to do alignment of non-biological sequences, and so cannot use the bioinfo toolbox version.
Hi Walter and Huda. Hopefully my participation in this post is ok.
As you may remember, past few days I used the needleman-wunsh algorithm to align decimal numbers. I'm going to have to do the same in a couple of days with the SW algorithm since I need local and not global alignments. So I wonder if there is a reason (structure of the code or function callings etc) for which the swalign file cannot be modified the same as the nwalign file for reading non-biological sequences?
Thanks,
Diego
hi Diego,
I'm glad to hear that someone use alignment with non biological seq.
in fact, I can not use swalign and nwalign , because these codes defined just for 4 symbols (A,C,G,T) or 20 symols of amino acids. In my situation , need more symbols to represent my data, not just this reason ,but because of substitution matrices, BLOSUM AND PAM , are defined just for Nucleotides and amino acids.
In my situation , I think i have to use unitary matrix instead of BLOSUM and PAM.
currently, i try to write code of smith-waterman . Regarding Needleman I wrote it, it is work correctly.
hi,
is necessary existence perl software to run perl script in matlab?

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Matrix Indexing 的更多信息

标签

尚未输入任何标签。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by