I'm being given an DNA sequence, for example:
ATTAGGGCCCATTACGCTGACGAGCACTTG
I need to write a function, given two inputs (the DNA sequence, and A, C, G or T) determine the length of the longest possible part of the sequence containing only that specific letter.
dna = 'ATTAGGGCCCATTACGCTGACGAGCACTTG';
giveLength(dna, 'A')
ans =
1
giveLength(dna, 'C')
ans =
3
I had started out like this:
function length = giveLength(sequentce, amino)
[begin, end] = regexp(sequentie, amino , 'start', 'end')
pos = 1;
if isempty(begin)
error('Doesn't exist!')
else
for i = 1:length(begin)
if begin(i) ~= end(i)
if (end(i) - begin(i)) > (end(i) - begin(i)) || (end(i) - begin(i)) > 1
pos = end(i) - begin(i);
end
end
end
length = pos;
end
Obviously this doesn't work, because for each letter the begin and starting position are the same, and I can't write amino+
either to let it select the parts that correspond.
Help would be highly appreciated!