MATLAB: Addition of two DNA sequenc

dna sequence addition

Hi, I have a problem in DNA addition
%%%%%%DNA addition
P_DNA1='ACAAGGGTTTAAACCCTTAC';
P_DNA2='TTTTGGGAAATGTGACATAT';
[m n]=size(P_DNA1);
mn=m*n;
d3=[];
for i = 1:mn
d3 = DNA_add('P_DNA1(i)','P_DNA2(i)');
end
where DNA_add is a function

Best Answer

Hi,
There are a couple of minor issues with your implementation that is causing a problem.
  1. Your function is missing an end statement.
  2. Assuming that you wanted to send the ith character of P_DNA1 and P_DNA2 to the function DNA_add, the quotation marks are not needed.
  3. The variable d3 gets overwritten at each iteration of the loop rather than the result of DNA_add being appended to d3.
Here is the modified code which should resolve these issues:
P_DNA1='ACAAGGGTTTAAACCCTTAC';
P_DNA2='TTTTGGGAAATGTGACATAT';
[m n]=size(P_DNA1);
mn=m*n;
d3=[];
for i = 1:mn
d3 = [d3 DNA_add(P_DNA1(i),P_DNA2(i))];
end
function K = DNA_add(Q1,Q2)
if Q1=='A' && Q2=='A';
K = 'A';
elseif Q1=='A' && Q2=='G';
K = 'G';
elseif Q1=='A' && Q2=='C';
K = 'C';
elseif Q1=='A' && Q2=='T';
K = 'T';
elseif Q1=='G' && Q2=='A';
K = 'G';
elseif Q1=='G' && Q2=='G';
K = 'C';
elseif Q1=='G' && Q2=='C';
K = 'T';
elseif Q1=='G' && Q2=='T';
K = 'A';
elseif Q1=='C' && Q2=='A';
K = 'C';
elseif Q1=='C' && Q2=='G';
K = 'T';
elseif Q1=='C' && Q2=='C';
K = 'A';
elseif Q1=='C' && Q2=='T';
K = 'G';
elseif Q1=='T' && Q2=='A';
K = 'T';
elseif Q1=='T' && Q2=='G';
K = 'A';
elseif Q1=='T' && Q2=='C';
K = 'G';
elseif Q1=='T' && Q2=='T';
K = 'C';
end
end