[R] More than on loop??

che fadialnaji at live.com
Sun Jan 31 13:58:06 CET 2010


hello, 
i appreciate your help, your help, comments, and suggestion really are so
helpful to develop not only my R skills, but also my programming language
sense. as i said, i am not breaking any academic rules, and this is a
softwar i have to develop to deal with my project after two months along
with some algorithms .. any way, for your question jholtman, if one
particular amino acids (let say letter A) is missed in the data, that wont
appear in the graph. any way i think i found the clue for this work, here
you are what i wrote, it is working, but i would love to have any comments,
or advices. the data attached. many thanks.
x<-read.table("C:/Uni/502/CA2/hiv.dat", header=TRUE)										
attach(x)																					
AA<-c('A','C','D','E','F','G','H','I','K','L','M','N','P','Q','R','S','T','V','W','Y')		
num<-nrow(x)																				
frequency<-function(Q)
{																				
y<-matrix(0,20,8)
colnames(y)<-c("N4","N3","N2","N1","C1","C2","C3","C4")

	for(i in 1:num){
		if (x$Label[i]== Q)
			{	
			for(j in 1:8){
			res<-which(AA==substr(x$Peptide[i],j,j))
			y[res, j]=y[res, j]+1

 						}
			}
}
return (y)
}
freqC<-frequency("cleaved")
freqNc<-frequency("noncleaved")

 
ClPeptide<-114
nClPeptide<-248


Norm<-function(F,N)

{
No<-matrix(0,20,8)
  colnames(No)<-c("N4","N3","N2","N1","C1","C2","C3","C4")
	for (j in 1:8){
		for (k in 1:20){
			No[k,j]=(F[k,j]/N)*100
		}
	}
	return(No)
}
normalisedC<-Norm(freqC,ClPeptide)
normalisedNc<-Norm(freqNc,nClPeptide)


hi<-function(H)
{	
	height<-rep(0,8)
		for (j in 1:8){
		height[j]<-sum(round(H)[,j])
		max.height<-max(height)
					}
return(max.height)
}

CleH<-hi(normalisedC)
nCleH<-hi(normalisedNc)

colmap<-c("#009900", "#00CC00", "#00FF00", "#009933", "#00CC33",
"#00FF33", "#009966", "#00CC66", "#00FF66", "#009999", "#00CC99",
"#00FF99", "#0099CC", "#00CCCC", "#00FFCC", "#0099FF", "#00CCFF",
"#00FFFF", "#66FFFF", "#CCFFFF")

CumulativeY<-function(k,b,F)
{
  if( b<=0)
    {
	    cum=0
	}
  else
    {
	    cum=0
	    for(d in 1:b)
    {
        cum=cum + (round(F[d,k]))
         
        }
     }
return(cum)
}
graph<- function(F)
{
for(i in 1:8)
  {
  for(j in 1:20)
    {
    rect((i-1)*10,CumulativeY(i,j-1,F),((i-1)*10)+10,CumulativeY(i,j,F),
col=colmap[j])
    if ( F[j,i] != 0)
      {
       text( ((i-1)*10)+5, (CumulativeY(i,j-1,F) + round(F[j,i])/2), AA[j],
cex=((2*round(F[j,i])/round(max(F)))),col="#990000")
       }
     }
  }  
}

par(mfrow=c(1,2))
plot(c(0,10*8),c(0,CleH),col="#303030")
graph(normalisedC)
plot(c(0,10*8),c(0,nCleH),col="#303030")
graph(normalisedNc)
http://n4.nabble.com/file/n1458002/hiv.dat hiv.dat 
-- 
View this message in context: http://n4.nabble.com/More-than-on-loop-tp1015851p1458002.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list