Discover MakerZone

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

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

problem in display of sequences

Asked by huda nawaf

huda nawaf (view profile)

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%%%%%%%%%


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
%%%%%%% after read file in x, x will be as follow:
%    '?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
for j = 2:N+1
   F(1,j) = (j-1)*g;   I(1,j) = 3; %I:horizontal

for i = 2:M+1

   for j = 2:N+1
      if strcmp(x(1,i-1),x(2,j-1))
         w(i,j) = 1;
         w(i,j) = -1;
[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]);
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-1; end
 j = j-1;  xrev{k} = '-'; yrev{k} = x(2,j); score=score-1;

%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);


1 Comment

Walter Roberson

Walter Roberson (view profile)

on 8 Apr 2012

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

huda nawaf

huda nawaf (view profile)



No products are associated with this question.

0 Answers

Contact us