Borrar filtros
Borrar filtros

Function Error / If and elseif statement help

1 visualización (últimos 30 días)
Samantha Pellegrino
Samantha Pellegrino el 4 de Mayo de 2020
Comentada: Rik el 6 de Mayo de 2020
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 comentarios
Samantha Pellegrino
Samantha Pellegrino el 4 de Mayo de 2020
Editada: Rik el 4 de Mayo de 2020
to call the function I added a nucleotide_string variable in the control window and then called the function in the control window.
I adjusted the code to the following:
function [amino_acid_chain] = synth_test(nucleotide_string)
%Function to synthesize an amino acid chain from an mRNA molecule.
%To handle the upper and lowercase letters, all letter are transferred to
%uppercase to be read.
neucleotides = upper(neucleotide_string);
%Loop to check for invalid characters in neucleotide string.
while any(neucleotides ~= 'A', neucleotides ~= 'G', neucleotides ~= 'U', neucleotides ~= 'C')
error('Error! Neucleotide string contains invalid characters.');
end
amino_acid_chain = cellstr(reshape(neucleotides,3,[])');
if length(amino_acid_chain)<3
amino_acid_chain = char([]);
return;
end
strrep(amino_acid_chain, {'UUU','UUC'}, {'F','F'});
strrep(amino_acid_chain, {'UUA','UUG','CUU','CUC','CUA','CUG'}, {'L','L','L','L','L','L'});
strrep(amino_acid_chain, {'AUU', 'AUC', 'AUA'},{'I','I','I'});
strrep(amino_acid_chain, {'AUG'},{'M'});
strrep(amino_acid_chain, {'GUU','GUC','GUA','GUG'},{'V','V','V','V'});
streep(amino_acid_chain, {'UCU','UCC','UCA','UCG'},{'S','S','S','S'});
strrep(amino_acid_chain, {'CCU','CCC','CCA','CCG'},{'P','P','P','P'});
strrep(amino_acid_chain, {'ACU','ACC','ACA','ACG'},{'T','T','T','T'});
strrep(amino_acid_chain, {'GCU','GCC','GCA','GCG'},{'A','A','A','A'});
strrep(amino_acid_chain, {'UAU','UAC'},{'Y','Y'});
strrep(amino_acid_chain, {'CAA','CAG'},{'Q','Q'});
strrep(amino_acid_chain, {'AAU','AAC'},{'N','N'});
strrep(amino_acid_chain, {'AAA','AAG'},{'K','K'});
strrep(amino_acid_chain, {'GAU','GAC'},{'D','D'});
strrep(amino_acid_chain, {'GAA','GAG'},{'E','E'});
strrep(amino_acid_chain, {'UGU','UGC'},{'C','C'});
strrep(amino_acid_chain, {'UGG'},{'W'});
strrep(amino_acid_chain, {'CGU','CGC','CGA','CGG'},{'R','R','R','R'});
strrep(amino_acid_chain, {'AGU','AGC'},{'S','S'});
strrep(amino_acid_chain, {'AGA','AGG'},{'R','R'});
streep(amino_acid_chain, {'GGU','GGC','GGA','GGG'},{'G','G','G','G'});
strrep(amino_acid_chain, {'UAA','UAG','UGA'},{'Stop','Stop','Stop'});
if amino_acid_chain == 'Stop'
return;
end
end
I thought it would be better then trying to use an if/elseif statement...
I'm also not 100% sure on how to give an output that will give a string reading of the neucleotides to the converted amino acids...
Rik
Rik el 4 de Mayo de 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?

Iniciar sesión para comentar.

Respuesta aceptada

Rik
Rik el 4 de Mayo de 2020
Editada: Rik el 5 de Mayo de 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 comentarios
Samantha Pellegrino
Samantha Pellegrino el 6 de Mayo de 2020
THANK YOU! That has fixed it all!
Thank you so much for your help!!
Rik
Rik el 6 de Mayo de 2020
You're welcome

Iniciar sesión para comentar.

Más respuestas (1)

Steven Lord
Steven Lord el 5 de Mayo de 2020
Editada: Steven Lord el 5 de Mayo de 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

Categorías

Más información sobre Timing and presenting 2D and 3D stimuli en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by