Take input and use it in a function
1 次查看(过去 30 天)
显示 更早的评论
I''m trying to write a program that can analyze protein relationship. I'm trying to make the user input the accession number of the protein, then save it in a variable, then load the sequence using the getgenpept function, but it doesn't seem to work! (Input AAA69808, NP_989750)
protein1=input('NCBI accession number of the first protein: ', 's');
protein2=input('NCBI accession number of the second protein: ', 's');
seq1 = getgenpept('protein1','SequenceOnly',true);
seq2 = getgenpept('protein2','SequenceOnly',true);
However, doing the folloiwng in MATLAB works fine:
human = getgenpept('AAA69808','SequenceOnly',true);
chicken = getgenpept('NP_989750','SequenceOnly',true);
0 个评论
采纳的回答
Geoff Hayes
2015-1-6
Ahmad - please clarify what you mean by it doesn't seem to work. Are you observing an error or are you not getting the correct/desired results?
Seq = getgenpept('AAA59174')
and it produces some result. You have even shown that something like
human = getgenpept('AAA69808','SequenceOnly',true);
chicken = getgenpept('NP_989750','SequenceOnly',true);
works too. So what is different between the above two statements and your code that gets the input from the user? Note what you are doing
protein1=input('NCBI accession number of the first protein: ', 's');
protein2=input('NCBI accession number of the second protein: ', 's');
protein1 and protein2 are variables of data type char (so are string variables). With your input example this means that
protein1 == 'AAA69808'
protein2 == 'NP_989750'
Now since these are string variables and the first input to the getgenpept is a string variable, there is no need to wrap these variables in quotes like
seq1 = getgenpept('protein1','SequenceOnly',true);
seq2 = getgenpept('protein2','SequenceOnly',true);
because if you do, then what you are really passing this function are strings representing the variable name of protein1 or protein2 and not the value of the variable.
Remove the single quotes and change these two lines to
seq1 = getgenpept(protein1,'SequenceOnly',true);
seq2 = getgenpept(protein2,'SequenceOnly',true);
1 个评论
Stephen23
2015-1-6
It might be a good time for the OP to read some documentation:
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Biological and Health Sciences 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!