フィルターのクリア

Binary to DNA sequence conversion

4 ビュー (過去 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 Center および File ExchangeDownloads についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by