MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply TodayTo resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

Asked by huda nawaf on 8 Apr 2012

This question is closed and may reopen in the future if edited.

hi, i want alignment two sequences using Needleman, but i faced this problem.

the result be:

{1x1 cell}{1x1 cell} {1x1 cell} - {1x1 cell} {1x1 cell}

- {1x1 cell} {1x1 cell}{1x1 cell} {1x1 cell} {1x1 cell}

where it must be as:

'?RKG' 'RCRE' '?RFI' - '???Q' 'AGQI' - 'RCRE' '?RFI' 'AGOI' 'GGAR' ' CVC'

%%%%%%%%%this is code%%%%%%%%%

f=fopen('codweb1.txt');z=fscanf(f,'%c');fclose(f);k1=1;

for i=1:2

k=1; for j=1:p(i);

if z(k1)~=0 x{i,k}=z(k1:k1+3); k=k+1;k1=k1+4; end;end k1=k1+1;end %%%%%%% after read file in x, x will be as follow: %x= % '?RKG' 'RCRE' '?RFI' '???Q' 'AGQI' 'ZXC' % 'RCRE' '?RFI' 'AGOI' 'GGAR' ' CVC' 'LKJ'

g = -1; %the score of an insertion/deletion

M = 5; N =4; F = zeros(M+1, N+1); I = zeros(M+1, N+1);

for i = 2:M+1

F(i,1) = (i-1)*g; I(i,1) = 1; %I:vertical end for j = 2:N+1

F(1,j) = (j-1)*g; I(1,j) = 3; %I:horizontal end

for i = 2:M+1

for j = 2:N+1

if strcmp(x(1,i-1),x(2,j-1))

w(i,j) = 1;

else

w(i,j) = -1;

end [F(i,j) I(i,j)] = max([ F(i-1,j)+g F(i-1,j-1)+w(i,j) F(i,j-1)+g]);

end;end

xrev={}; yrev={};

k = 0;score=0; %note i = M+1, j = N+1

while I(i,j) > 0

k = k+1; if I(i,j) == 1;

i = i-1; xrev{k} = x(1,i); yrev{k} = '-'; score=score-1;

elseif I(i,j) == 2

i = i-1; j = j-1; xrev{k} = x(1,i); yrev{k} = x(2,j);

if strcmp(x(1,i),x(2,j))

score=score+2;

else

score=score-1; end

else

j = j-1; xrev{k} = '-'; yrev{k} = x(2,j); score=score-1;

end;end

%reverse arrays for proper display

K = length(xrev);

for k = 1:K

xalign{k} = xrev{K-k+1}; yalign{k} = yrev{K-k+1};end

disp(yalign); disp(yalign);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

*No products are associated with this question.*

## 1 Comment

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/34858#comment_72510

Huda, you have been posting questions for many months now. Please learn how to format your questions to be more readable.

http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup