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

Star Strider
Star Strider 2015년 9월 20일
DNA has four bases (two complementary sets, A-T and C-G) and you have a binary sequence ...
Meghashree G
Meghashree G 2015년 9월 20일
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..

댓글을 달려면 로그인하십시오.

 채택된 답변

Image Analyst
Image Analyst 2015년 9월 20일

2 개 추천

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

Meghashree G
Meghashree G 2015년 9월 20일
Thank you so much :) it worked :)
Saurabh Kumar
Saurabh Kumar 2018년 2월 12일
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
Saurabh Kumar
Saurabh Kumar 2018년 2월 12일
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
Image Analyst
Image Analyst 2018년 2월 12일
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.
Saurabh Kumar
Saurabh Kumar 2018년 2월 13일
it worked. THANKS
How to decrypt it back to binary sequence
Image Analyst
Image Analyst 2020년 12월 5일
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.
Shiva Reddy
Shiva Reddy 2021년 2월 5일
Pls Can I get the decryption code
Image Analyst
Image Analyst 2021년 2월 5일
Shiva, I'm not sure who you're asking, but personally I don't have any to give you.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Cell Arrays에 대해 자세히 알아보기

질문:

2015년 9월 20일

댓글:

2021년 2월 5일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by