How do I connect my strings to my function?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Natalie Merchant
il 11 Mag 2022
Commentato: Natalie Merchant
il 11 Mag 2022
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
0 Commenti
Risposta accettata
Geoff Hayes
il 11 Mag 2022
Modificato: Geoff Hayes
il 11 Mag 2022
@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?
Più risposte (0)
Vedere anche
Categorie
Scopri di più su RESTful API in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!