% This function finds all the orfs that are more than 99 bases long, have
% valid start codon and valid stop codon. 
function ORFGL = ORF(DNA) % ORF: Open Reading Frame.
% DNA = {'AAAAAAAAAAAAATGAAAAAAAAAAAAATGAAAAAAAAAAAAAAAAAATAAAAAAAAAAAAAATAAAAAAAAAAAAAAAAAATGAAAAAAAAAAAAAAAAAATAAAAAAAA'};
clc,close all;
DNA = upper(DNA);
k = 1; % Hypothetical Protein index
i = 1;
while i <length(DNA{1})-2
    codon1 = DNA{1}(i:i+2);
    if (codon1 == 'ATG')|(codon1 == 'GTG')|(codon1 == 'TTG'),
        for j = i+3:3:length(DNA{1})-2
            codon2 = DNA{1}(j:j+2);
            if (codon2 == 'TAG')|(codon2 == 'TAA')|(codon2 == 'TGA'),
                if (j+2-i)>=99,
                    ORFGL{k,1} = k;
                    ORFGL{k,2} = i;
                    ORFGL{k,3} = j + 2;
                    ORFGL{k,4} = DNA{1}(i:j+2);
                    ORFGL{k,5} = length(DNA{1}(i:j+2));
                    i = j + 2;
                    k = k + 1;
                    {i,j,k,codon1,codon2}, 
                    break;
                end
            end
        end
    end
    i = i + 1;
end