caculate the frequencies of the Amino Acids
On Jan 2, 2010, at 12:26 AM, David Winsemius wrote:
On Jan 1, 2010, at 11:59 PM, che wrote:
may some one please help me to sort this out, i am trying to writ a
R code
for calculating the frequencies of the amino acids in 9 different
sequences,
i want the code to read the sequence from external text file, i
used the
following code to do so:
x<-read.table("sequence.txt",header=FALSE)
then i defined an array for 20 amino acids as following:
AA<-
c
('A
','C
','D
','E
','F','G','H','I','K','L','M','N','P','Q','R','S','T','V','W','Y')
i am using the following code to calculate the frequencies:
frequency<-function(X)
{
y<-rep(0,20)
Further thoughts: If I understand how you are doing this, that structure would only be large enough for one string's results. (Seems like this process would be easier if you used table() instead of for-loops.)
for(j in 1:nchar(as.character(x$V1[i]))){
# at this point you are referencing "i" but it is not yet being iterated and might not even exist. # did you mean "j"? # also might be safer to use seq_along()
for(i in 1:9){
res<-which(AA==substr(x$V1[i],j,j))
# Is that really working for even one sequence? Without an "x" sequence I cannot test, but it "looks wrong".
y[res]=y[res]+1 } } return(y) } but this code actually is not working, it reads only one sequence, i dont know why the loop is not working for the "i", which suppose to read the nine rows of the file sequence.txt. the sequence.txt file is attached to this message. cheers http://n4.nabble.com/file/n997072/sequence.txt sequence.txt -- View this message in context: http://n4.nabble.com/caculate-the-frequencies-of-the-Amino-Acids-tp997072p997072.html Sent from the R help mailing list archive at Nabble.com.
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.