Binary to DNA sequence conversion

1 Ansicht (letzte 30 Tage)
lilly lord
lilly lord am 10 Jun. 2020
Bearbeitet: James Tursa am 19 Jun. 2020
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

Akzeptierte Antwort

James Tursa
James Tursa am 10 Jun. 2020
Bearbeitet: James Tursa am 10 Jun. 2020
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 Kommentare
lilly lord
lilly lord am 11 Jun. 2020
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 am 19 Jun. 2020
Bearbeitet: James Tursa am 19 Jun. 2020
The inverse function would be:
reshape(dec2bin((0:3)*(s == ACGT'))',1,[])

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Downloads finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by