text = 'CGATCCGATC--------------CGCGCCGCGATCCGATCCGATCCGATCCGATCCGATCCGATCCGATCCGATCCGATCCGATCCGATC';
newLetters = 'ACTG';
n = numel(text);
percentChange = 20;
idx = 1:n;
hak = isletter(text(:));
hakk = sum(hak);
idxToChange = idx(isletter(text));
nChanges = max([ceil(hakk*percentChange/100), 1]);
changeIdx = idxToChange(randperm(numel(idxToChange), nChanges));
currentLetters = text(changeIdx);
currentIndex = currentLetters == newLetters(:);
[row, ~] = find(~currentIndex);
matrixRows = reshape(row, size(currentIndex, 1) - 1, size(currentIndex, 2));
rowIdx = randi([1, numel(newLetters) - 1], 1, nChanges);
subIndex = sub2ind([size(currentIndex, 1) - 1, size(currentIndex, 2)], rowIdx, 1: size(currentIndex, 2));
changeLetterIdx = row(subIndex');
newText = text;
newText(changeIdx) = newLetters(changeLetterIdx);
if any(newText(changeIdx) == text(changeIdx))
disp('Something didn''t change to a new value, but this should no longer be possible!');
end
0 Comments
Sign in to comment.