Binary to DNA sequence encoding - matlab
显示 更早的评论
I am implementing DNA encryption algorithm.
For that, I have a vector containing binary values such as:
01100011 01110010 01111001 01110000 01110100 01101111.
Now, these values should be mapped to DNA sequence. How do I do that in MATLAB?
2 个评论
DNA has four bases (two complementary sets, A-T and C-G) and you have a binary sequence ...
yeah..i know To use ATGC concept,but i don't know how to code..Like how do i extract only 2 digits from the binary vector and assign it to either A,T,G,C..
采纳的回答
Perhaps this:
% Assign sample data.
binaryArray = [0,1,1,0,0,0,1,1, 0,1,1,1,0,0,1,0, 0,1,1,1,1,0,0,1, 0,1,1,1,0,0,0,0, 0,1,1,1,0,1,0,0, 0,1,1,0,1,1,1,1];
% Define base letters to choose from.
bases = 'ATGC';
for k = 1 : 2 : length(binaryArray)
% Convert these two digits into a number 1 - 4.
index = 2 * binaryArray(k) + binaryArray(k+1) + 1;
% Use that index to assign a letter to our result.
result((k+1)/2) = bases(index);
end
% Display in command window:
result
It shows:
result =
TGACTCAGTCGTTCAATCTATGCC
12 个评论
Thank you so much :) it worked :)
I want to create a function in Matlab of above solution you have given. So that I don't need to describe different binary Everytime in .m blank file format. Please help Function []=binary()
function result = LabelBinaryArray(binaryArray)
% Define base letters to choose from.
bases = 'ATGC';
for k = 1 : 2 : length(binaryArray)
% Convert these two digits into a number 1 - 4.
index = 2 * binaryArray(k) + binaryArray(k+1) + 1;
% Use that index to assign a letter to our result.
result((k+1)/2) = bases(index);
end
Attempted to access binaryArray(2); index out of bounds because numel(binaryArray)=1.
Error in LabelBinaryArray (line 6) index = 2 * binaryArray(k) + binaryArray(k+1) + 1;
NOT WORKING
It works if you pass in something like you said, like '01100011'. You can't pass in a single value like '1' like you did because that can't be mapped to a letter. How do I know you passed in only a single element? Because the error message says "because numel(binaryArray)=1" Are you sure you're passing in a binary array like you said? I'm assuming a binary array, which is class logical, though a double will work. You aren't passing in a string are you? Show me how you defined the array you passed in to the function.
LabelBinaryArray('011000110111001001111001011100000111010001101111')
Attempted to access bases(146); index out of bounds because numel(bases)=4.
Error in LabelBinaryArray (line 8) result((k+1)/2) = bases(index);
OK, you have a string, not a binary/logical array. To convert to a binary array you need to do this:
str = '011000110111001001111001011100000111010001101111'
binaryArray = logical(str - '0')
You can do that either inside the function, if you want to pass a string, or in your main program before you call the function, if you want to pass a binary array.
it worked. THANKS
How to decrypt it back to binary sequence
Decrypt what back to a binary sequence. You have the binary sequence both as a character array, str, and a logical/boolean array, binaryArray. What else do you want? What's missing? Just keep both things and you're all set.
Pls Can I get the decryption code
Shiva, I'm not sure who you're asking, but personally I don't have any to give you.
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Cell Arrays 的更多信息
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
