Binary to DNA sequence conversion

1 次查看(过去 30 天)
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