Skip to content

reading data

2 messages · arun

#
Hi,
Try this:


files<-paste("MSMS_",23,"PepInfo.txt",sep="")
read.data<-function(x) {names(x)<-gsub("^(.*)\\/.*","\\1",x); lapply(x,function(y) read.table(y,header=TRUE,sep = "\t",stringsAsFactors=FALSE,fill=TRUE))}
lista<-do.call("c",lapply(list.files(recursive=T)[grep(files,list.files(recursive=T))],read.data))
names(lista)<-paste("group_",gsub("\\d+","",names(lista)),sep="")
res2<-split(lista,names(lista))
res3<- lapply(res2,function(x) {names(x)<-paste(gsub(".*_","",names(x)),1:length(x),sep="");x})
#Freq whole data
res4<-lapply(seq_along(res3),function(i) do.call(rbind,lapply(res3[[i]],function(x) as.data.frame(table(factor(x$z,levels=1:3))))))
names(res4)<- names(res2)
library(reshape2)
freq.i1<-do.call(rbind,lapply(res4,function(x) dcast(melt(data.frame(id=gsub("\\..*","",row.names(x)),x),id.var=c("id","Var1")),id~Var1,value.var="value")))
freq.i1
#????????? id 1? 2 3
#group_a?? a1 1 12 6
#group_c.1 c1 0 10 3
#group_c.2 c2 0 12 3
#group_c.3 c3 0 13 4
#group_t.1 t1 0 10 4
#group_t.2 t2 1 12 6

freq.rel.i1<- as.matrix(freq.i1[,-1]/rowSums(freq.i1[,-1]) )
?freq.rel.i1
?# ???????????????? 1???????? 2???????? 3
#group_a?? 0.05263158 0.6315789 0.3157895
#group_c.1 0.00000000 0.7692308 0.2307692
#group_c.2 0.00000000 0.8000000 0.2000000
#group_c.3 0.00000000 0.7647059 0.2352941
#group_t.1 0.00000000 0.7142857 0.2857143
#group_t.2 0.05263158 0.6315789 0.3157895



#Freq with FDR< 0.01
res5<-lapply(seq_along(res3),function(i) do.call(rbind,lapply(res3[[i]],function(x) as.data.frame(table(factor(x$z[x[["FDR"]]<0.01],levels=1:3))))))
names(res5)<- names(res2)

freq.f1<- do.call(rbind,lapply(res5,function(x) dcast(melt(data.frame(id=gsub("\\..*","",row.names(x)),x),id.var=c("id","Var1")),id~Var1,value.var="value")))

?freq.f1
?# ??????? id 1? 2 3
#group_a?? a1 1 10 5
#group_c.1 c1 0? 7 2
#group_c.2 c2 0? 8 2
#group_c.3 c3 0? 6 4
#group_t.1 t1 0? 7 4
#group_t.2 t2 1 10 5


freq.rel.f1<- as.matrix(freq.f1[,-1]/rowSums(freq.f1[,-1]))

colour<-sample(rainbow(nrow(freq.rel.i1)))
par(mfrow=c(1,2))
barplot(freq.rel.i1,beside=T,main=("Sample"),xlab="Charge",ylab="Relative Frequencies",col=colour,legend.text = rownames(freq.rel.i1))
barplot(freq.rel.f1,beside=T,main=("Sample with FDR<0.01"),xlab="Charge",ylab="Relative Frequencies",col=colour,legend.text = rownames(freq.rel.f1))
#change the legend position

Also, didn't check the rest of the code from chisquare test.
A.K.
#
Hi,

You can change `res4` to:
lev<-sort(unique(do.call(c,lapply(seq_along(res3),function(i) do.call(c,lapply(res3[[i]],function(x) unique(x$z)))))))
res4<-lapply(seq_along(res3),function(i) do.call(rbind,lapply(res3[[i]],function(x) as.data.frame(table(factor(x$z,levels=lev))))))

freqs1<-do.call(rbind,lapply(split(freq.f1,gsub("\\d+","",freq.f1$id)),function(x) x[-1,])) #here there is only level for a1.? So, it is removed
?average1<- colMeans(freqs1[,-1])
?average1
#??????? 1???????? 2???????? 3 
#0.3333333 8.0000000 3.6666667 
pvalues1<-do.call(rbind,lapply(seq_len(nrow(freqs1)),function(x) chisq.test(freqs1[x,-1],average1)))
?row.names(pvalues1)<- row.names(freqs1)
?pvalues1
#???????????????? [,1]
#c.group_c.2 0.7235907
#c.group_c.3 0.7963287
#t?????????? 0.9079200

A.K.

----- Original Message -----
From: arun <smartpink111 at yahoo.com>
To: Vera Costa <veracosta.rt at gmail.com>
Cc: R help <r-help at r-project.org>
Sent: Tuesday, February 19, 2013 7:29 PM
Subject: Re: reading data

Hi,
Try this:


files<-paste("MSMS_",23,"PepInfo.txt",sep="")
read.data<-function(x) {names(x)<-gsub("^(.*)\\/.*","\\1",x); lapply(x,function(y) read.table(y,header=TRUE,sep = "\t",stringsAsFactors=FALSE,fill=TRUE))}
lista<-do.call("c",lapply(list.files(recursive=T)[grep(files,list.files(recursive=T))],read.data))
names(lista)<-paste("group_",gsub("\\d+","",names(lista)),sep="")
res2<-split(lista,names(lista))
res3<- lapply(res2,function(x) {names(x)<-paste(gsub(".*_","",names(x)),1:length(x),sep="");x})
#Freq whole data
res4<-lapply(seq_along(res3),function(i) do.call(rbind,lapply(res3[[i]],function(x) as.data.frame(table(factor(x$z,levels=1:3))))))
names(res4)<- names(res2)
library(reshape2)
freq.i1<-do.call(rbind,lapply(res4,function(x) dcast(melt(data.frame(id=gsub("\\..*","",row.names(x)),x),id.var=c("id","Var1")),id~Var1,value.var="value")))
freq.i1
#????????? id 1? 2 3
#group_a?? a1 1 12 6
#group_c.1 c1 0 10 3
#group_c.2 c2 0 12 3
#group_c.3 c3 0 13 4
#group_t.1 t1 0 10 4
#group_t.2 t2 1 12 6

freq.rel.i1<- as.matrix(freq.i1[,-1]/rowSums(freq.i1[,-1]) )
?freq.rel.i1
?# ???????????????? 1???????? 2???????? 3
#group_a?? 0.05263158 0.6315789 0.3157895
#group_c.1 0.00000000 0.7692308 0.2307692
#group_c.2 0.00000000 0.8000000 0.2000000
#group_c.3 0.00000000 0.7647059 0.2352941
#group_t.1 0.00000000 0.7142857 0.2857143
#group_t.2 0.05263158 0.6315789 0.3157895



#Freq with FDR< 0.01
res5<-lapply(seq_along(res3),function(i) do.call(rbind,lapply(res3[[i]],function(x) as.data.frame(table(factor(x$z[x[["FDR"]]<0.01],levels=1:3))))))
names(res5)<- names(res2)

freq.f1<- do.call(rbind,lapply(res5,function(x) dcast(melt(data.frame(id=gsub("\\..*","",row.names(x)),x),id.var=c("id","Var1")),id~Var1,value.var="value")))

?freq.f1
?# ??????? id 1? 2 3
#group_a?? a1 1 10 5
#group_c.1 c1 0? 7 2
#group_c.2 c2 0? 8 2
#group_c.3 c3 0? 6 4
#group_t.1 t1 0? 7 4
#group_t.2 t2 1 10 5


freq.rel.f1<- as.matrix(freq.f1[,-1]/rowSums(freq.f1[,-1]))

colour<-sample(rainbow(nrow(freq.rel.i1)))
par(mfrow=c(1,2))
barplot(freq.rel.i1,beside=T,main=("Sample"),xlab="Charge",ylab="Relative Frequencies",col=colour,legend.text = rownames(freq.rel.i1))
barplot(freq.rel.f1,beside=T,main=("Sample with FDR<0.01"),xlab="Charge",ylab="Relative Frequencies",col=colour,legend.text = rownames(freq.rel.f1))
#change the legend position

Also, didn't check the rest of the code from chisquare test.
A.K.