Function Error / If and elseif statement help
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Hello,
I have been trying to create this function to call when entering nucleotides and then having the string divided by 3 and then read and changed into the appropriate amino acid. When I try to run the function it comes up with the error:
'Not enough input arguements'
If anyone could help to fix this code up it would be amazing!!
function [amino_acid_chain] = synthesize2(neucleotide_string)
%Function to synthesize an amino acid chain from an mRNA molecule.
neucleotide_string = upper(neucleotide_string);
%Loop to check for invalid characters in neucleotide string.
while any(neucleotide_string ~= 'A' && neucleotide_string ~= 'G' && neucleotide_string ~= 'U' && neucleotide_string ~= 'C');
error('Error! Neucleotide string contains invalid characters.');
end
amino_acid_chain = cellstr(reshape(neucleotide_string,3,[])');
if length(amino_acid_chain)<3
amino_acid_chain = char([]);
return;
end
if amino_acid_chain == 'UUU' or 'UUC'
amino_acid_chain = replace(word,{'UUU','UUC'},{'F','F'});
elseif amino_acid_chain == 'UUA' or 'UUG' or 'CUU' or 'CUA' or 'CUG'
amino_acid_chain = replace(word,{'UUA','UUG','CUU','CUC','CUA','CUG'},{'L','L','L','L','L','L'});
elseif amino_acid_chain == 'AUU' or 'AUC' or 'AUA'
amino_acid_chain = replace(word,{'AUU', 'AUC', 'AUA'},{'I','I','I'});
elseif amino_acid_chain == 'AUG'
amino_acid_chain = replace(word,{'AUG'},{'M'});
elseif amino_acid_chain == 'GUU' or 'GUC' or 'GUA' or 'GUG'
amino_acid_chain = replace(word,{'GUU','GUC','GUA','GUG'},{'V','V','V','V'});
elseif amino_acid_chain == 'UCU' or 'UCC' or 'UCA' or 'UCG'
amino_acid_chain = replace(word,{'UCU','UCC','UCA','UCG'},{'S','S','S','S'});
elseif amino_acid_chain == 'CCU' or 'CCC' or 'CCA' or 'CCG'
amino_acid_chain = replace(word,{'CCU','CCC','CCA','CCG'},{'P','P','P','P'});
elseif amino_acid_chain == 'ACU' or 'ACC' or 'ACA' or 'ACG'
amino_acid_chain = replace(word,{'ACU','ACC','ACA','ACG'},{'T','T','T','T'});
elseif amino_acid_chain == 'GCU' or 'GCC' or 'GCA' or 'GCG'
amino_acid_chain = replace(word,{'GCU','GCC','GCA','GCG'},{'A','A','A','A'});
elseif amino_acid_chain == 'UAU' or 'UAC'
amino_acid_chain = replace(word,{'UAU','UAC'},{'Y','Y'});
elseif amino_acid_chain == 'CAA' or 'CAG'
amino_acid_chain = replace(word,{'CAA','CAG'},{'Q','Q'});
elseif amino_acid_chain == 'AAU' or 'AAC'
amino_acid_chain = replace(word,{'AAU','AAC'},{'N','N'});
elseif amino_acid_chain == 'AAA' or 'AAG'
amino_acid_chain = replace(word,{'AAA','AAG'},{'K','K'});
elseif amino_acid_chain == 'GAU' or 'GAC'
amino_acid_chain = replace(word,{'GAU','GAC'},{'D','D'});
elseif amino_acid_chain == 'GAA' or 'GAG'
amino_acid_chain = replace(word,{'GAA','GAG'},{'E','E'});
elseif amino_acid_chain == 'UGU' or 'UGC'
amino_acid_chain = replace(word,{'UGU','UGC'},{'C','C'});
elseif amino_acid_chain == 'UGG'
amino_acid_chain = replace(word,{'UGG'},{'W'});
elseif amino_acid_chain == 'CGU' or 'CGC' or 'CGA' or 'CGG'
amino_acid_chain = replace(word,{'CGU','CGC','CGA','CGG'},{'R','R','R','R'});
elseif amino_acid_chain == 'AGU' or 'AGC'
amino_acid_chain = replace(word,{'AGU','AGC'},{'S','S'});
elseif amino_acid_chain == 'AGA' or 'AGG'
amino_acid_chain = replace(word,{'AGA','AGG'},{'R','R'});
elseif amino_acid_chain == 'CGU' or 'GGC' or 'GGA' or 'GGG'
amino_acid_chain = replace(word,{'GGU','GGC','GGA','GGG'},{'G','G','G','G'});
elseif amino_acid_chain == 'UAA' or 'UAG' or 'UGA'
amino_acid_chain = replace(word,{'UAA','UAG','UGA'},{'Stop','Stop','Stop'});
end
end
I was also using 'or' in my if/elseif statement, however I don't think that is correct either...
3 Commenti
Rik
il 4 Mag 2020
Why do you still have this?
if amino_acid_chain == 'Stop'
The goal of that if is unclear anyway, as there is no code between the return and the end of the function.
Also, have you seen my answer?
Risposta accettata
Rik
il 4 Mag 2020
Modificato: Rik
il 5 Mag 2020
As a replacement for what you have done here, I would suggest using ismember to find the triples that form valid codes. You can even use it to keep track of every marked position so you can see if you forgot to implement any triples.
amino_acid_chain = cellstr(reshape(neucleotide_string,3,[])');
L=false(size(amino_acid_chain));%keep track of replaced codes
library={{'E','GAA','GAG'};...
{'W','UGG'}};%etc
for n=1:numel(library)
triplet=library{n}(2:end);%select the triplet(s) from the library (e.g. {'GAA','GAG'})
letter=library{n}(1);%select the corresponding amino acid letter (e.g. 'E')
L_current_code=ismember(amino_acid_chain,triplet);%find all positions where the amino acid occurs
amino_acid_chain(L_current_code)=letter;%replace by the letter code
L=L | L_current_code;%mark as replaced
end
if any(~L)%shouldn't happen
error('some code was not implemented correctly')
end
15 Commenti
Più risposte (1)
Steven Lord
il 5 Mag 2020
Modificato: Steven Lord
il 5 Mag 2020
Consider using a switch / case statement.
food = ["apple", "beans", "cauliflower", "dragonfruit", "egg"];
groceries = food(randi(numel(food), 20, 1)); % 20 random items from food
for whichItem = 1:numel(groceries)
item = groceries(whichItem);
switch item
case {"apple"; "dragonfruit"}
itIsA = "fruit";
case {"beans"; "cauliflower"}
itIsA = "vegetable";
otherwise
itIsA = "something else";
end
fprintf("Item %d, %s, is a %s.\n", whichItem, item, itIsA);
end
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!