[R] More than on loop??

jim holtman jholtman at gmail.com
Tue Jan 26 04:09:38 CET 2010


Does this do what you want?  You were not initializing the plot before
calling 'rect'.  also it appears that you only have to call cleaved(x)
once to get the matrix and then use it in the loop -- more efficient
that way.

x<-read.table("C:/hiv.txt", header=TRUE)
num<-nrow(x)
AA<-c('A','C','D','E','F','G','H','I','K','L','M','N','P','Q','R','S','T','V','W','Y')
nc<-x$Label[61:308]
c<-x$Label[nc]
noncleaved<-function(x)
{
    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] %in% nc)
        {
            for(j in 1:8){
                res<-which(AA==substr(x$Peptide[i],j,j))
                y[res, j]=y[res, j]+1
            }
        }
    }
    return (y/274*100)
}

cleaved<-function(x)
{
    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] %in% nc)
        {
            for(j in 1:8){
                res<-which(AA==substr(x$Peptide[i],j,j))
                y[res, j]=y[res, j]+1
            }
        }
    }
    return (y/113*100)
}


hi<-function(x)
{
    height<-rep(0,8)
    for (j in 1:8){
        height[j]<-sum(round(cleaved(x)[,j]))
        max.height<-max(height)
    }
    plot(c(0,10*8),c(0,max.height+20),col="white")
}
recta<-function(x)
{
    plot(0, type='n', xlim=c(0,100), ylim=c(0,60))
    colmap<-c("#FFFFFF", "#FFFFCC", "#FFFF99", "#FFFF66", "#FFFF33",
    "#FFFF00", "#FFCCFF", "#FFCCCC", "#FFCC99", "#FFCC66", "#FFCC33",
    "#FFCC00", "#FF99FF", "#FF99CC", "#FF9999", "#FF9966", "#FF9933",
    "#FF9900", "#FF33FF", "#FF33CC")
    x.c <- cleaved(x)
    for (j in 1:8){

        xx<-j*10
        for(k in 1:20){

                yy<-round(x.c[k,j])

                rect(xx,yy,xx+10,yy+round(x.c[k,j]),col=colmap[k])
         }
     }
 }

recta(x)


On Mon, Jan 25, 2010 at 9:51 PM, che <fadialnaji at live.com> wrote:
>
> hopefully it is here, two files, one of them is .dat and the others is .txt,
> just in case.
> http://n4.nabble.com/file/n1290026/hiv.dat hiv.dat
> http://n4.nabble.com/file/n1290026/hiv.txt hiv.txt
> --
> View this message in context: http://n4.nabble.com/More-than-on-loop-tp1015851p1290026.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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?



More information about the R-help mailing list