How do I connect my strings to my function?

2 ビュー (過去 30 日間)
Natalie Merchant
Natalie Merchant 2022 年 5 月 11 日
コメント済み: Natalie Merchant 2022 年 5 月 11 日
I need to use the input nucleotide to make a string of amino acids. I am unsure how to use a for loop to do this, if someone could please help me. My code is below:
function [aminoAcidChain] = synthesise(nucleotide)
nucleotide = input('Please enter a nucelotide chain: ','s');
%Make sure code is all uppercase and 3 characters long
nucleotide = upper(nucleotide);
while ~all(ismember(nucleotide, 'AGUC'))
error('Character entered is invalid.');
end
%Divide the nucleotide chain into groups of 3 and discard leftover
%characters
if length (nucleotide)<3
aminoAcidChain= char([]);
end
codonChain = floor(length(nucleotide)/3);
aminoAcidChain = char(zeros(codonChain,3));
for i = 1:codonChain
start(i)= 3<(i-1)+1;
finish(i) = start+2;
CCodons = codonChain(start(i) : finish(i));
aminoAcidChain(i,:) = CCodons;
end
%convert codons to amino acids
UUC = {'F'};
UUU = {'F'};
UUA = {'L'};
UUG = {'L'};
CUU = {'L'};
CUC = {'L'};
CUG = {'L'};
AUU = {'I'};
AUC = {'I'};
AUA = {'I'};
AUG = {'M'};
GUU = {'V'};
GUC = {'V'};
GUA = {'V'};
GUG = {'V'};
UCU = {'S'};
UCC = {'S'};
UCA = {'S'};
UCG = {'S'};
CCU = {'P'};
CCC = {'P'};
CCA = {'P'};
CCG = {'P'};
ACU = {'T'};
ACC = {'T'};
ACA = {'T'};
ACG = {'T'};
GCU = {'A'};
GCC = {'A'};
GCA = {'A'};
GCG = {'A'};
UAU = {'Y'};
UAC = {'Y'};
CAU = {'H'};
CAC = {'H'};
CAA = {'Q'};
CAG = {'Q'};
AAU = {'N'};
AAC = {'N'};
AAA = {'K'};
AAG = {'K'};
GAU = {'D'};
GAC = {'D'};
GAA = {'E'};
GAG = {'E'};
UGU = {'C'};
UGC = {'C'};
UGG = {'W'};
CGU = {'R'};
CGC = {'R'};
CGA = {'R'};
CGC = {'R'};
AGU = {'S'};
AGC = {'S'};
AGA = {'R'};
AGG = {'R'};
GGU = {'G'};
GGC = {'G'};
GGA = {'G'};
GGG = {'G'};
UAA = {'STOP'};
UAG = {'STOP'};
UGA = {'STOP'};
fprintf('The resulting amino acid chain from the nucleotide is %s.',codonChain);
end

採用された回答

Geoff Hayes
Geoff Hayes 2022 年 5 月 11 日
編集済み: Geoff Hayes 2022 年 5 月 11 日
@Natalie Merchant - I may not have grasped exactly what you want, but I think from the code and your question, you are looking for a way to create a string of (multiple) three letter codes that are one of the characters AGUC. I wasn't sure if you are prompting the user to enter a 3 character chain at a time or a string whose length is a multiple of three. If the former, you could store the 3 character codes in a cell array like
nucleotides = {};
k = 1;
while true
nucleotide = input('Please enter a nucelotide chain: ','s');
%Make sure code is all uppercase and 3 characters long
nucleotide = upper(nucleotide);
if strcmpi(nucleotide, 'exit')
break;
elseif length(nucleotide) ~= 3
fprintf('Nucleotide string is not 3 characters long.\n');
elseif ~all(ismember(nucleotide, 'AGUC'))
fprintf('Nucleotide string has invalid character.\n');
end
nucleotides{k} = nucleotide;
k = k + 1;
end
You can then iterate over this cell array and convert each cell to the amino acid equivalents (which you may want to store in a containers.Map where the key is the 3 digit code ('UUC' for example) and the value is the amino acid string 'F').
Looking closer at your function
function [aminoAcidChain] = synthesise(nucleotide)
nucleotide = input('Please enter a nucelotide chain: ','s');
why do you allow the user to pass in the parameter nucleotide only to overwrite it with user input?
  1 件のコメント
Natalie Merchant
Natalie Merchant 2022 年 5 月 11 日
Thank you for your help. Yes sorry should of given more detail but the user will give a nucleotide chain that is longer than three. And not sure why I overwrite that not sure I did my function correctly!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeString Parsing についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by