Binary to DNA sequence conversion

조회 수: 1 (최근 30일)
lilly lord
lilly lord 2020년 6월 10일
편집: James Tursa 2020년 6월 19일
Hi, i have a binary string which I want to convert into DNA sequence.
A='010110101010101011100110011111';
[m n]=size(A);
mn=m*n;
k1=[];k2=[];k3=[];k4=[];s=[];
for i=1:mn
x=A(i,i+1);
if x(1) == '0' && x(2) == '0';
k1 = 'A';
elseif x(1) == '0' && x(2) == '1';
k1 = 'C';
elseif x(1) == '1' && x(2) == '0';
k1 = 'G';
elseif x(1) == '1' && x(2) == '1';
k1 = 'T';
end
%___
if x(3) == '0' && x(4) == '0';
k2 = 'A';
elseif x(3) == '0' && x(4) == '1';
k2 = 'C';
elseif x(3) == '1' && x(4) == '0';
k2 = 'G';
elseif x(3) == '1' && x(4) == '1';
k2 = 'T';
end
%___
if x(5) == '0' && x(6) == '0';
k3 = 'A';
elseif x(5) == '0' && x(6) == '1';
k3 = 'C';
elseif x(5) == '1' && x(6) == '0';
k3 = 'G';
elseif x(5) == '1' && x(6) == '1';
k3 = 'T';
end
%___
if x(7) == '0' && x(8) == '0';
k4 = 'A';
elseif x(7) == '0' && x(8) == '1';
k4 = 'C';
elseif x(7) == '1' && x(8) == '0';
k4 = 'G';
elseif x(7) == '1' && x(8) == '1';
k4 = 'T';
end
s=[s k1 k2 k3 k4];
end
%%%Error
Index exceeds matrix dimensions.
Error in binay_rule1 (line 16)
elseif x(1) == '1' && x(2) == '0';
Can an anyone help me. Thanks in advance

채택된 답변

James Tursa
James Tursa 2020년 6월 10일
편집: James Tursa 2020년 6월 10일
x = A(i:i+1);
But if you are going to process pairs of characters in A, then maybe you need to step by 2 as well, e.g.
for i=1:2:mn
But, instead of all that handwritten logic, does this do what you want?
ACGT = 'ACGT';
s = ACGT(bin2dec(reshape(A,2,[])')+1)
  댓글 수: 2
lilly lord
lilly lord 2020년 6월 11일
Thanks
ACGT = 'ACGT';
s = ACGT(bin2dec(reshape(A,2,[])')+1)
This work well. Can u plz tell how to get inverse of it
James Tursa
James Tursa 2020년 6월 19일
편집: James Tursa 2020년 6월 19일
The inverse function would be:
reshape(dec2bin((0:3)*(s == ACGT'))',1,[])

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Downloads에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by