Skip to content

reading data

1 message · 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 FDR<0.01 
res4<-lapply(seq_along(res3),function(i) lapply(res3[[i]],function(x) x[x[["FDR"]]<0.01,c("Seq","Mod","z","spec")])) 
names(res4)<- names(res2)
?res4New<-lapply(res4,function(x) lapply(names(x),function(i) do.call(rbind,lapply(x[i],function(x) cbind(folder_name=i,x))) ))
?
res5<- lapply(res4New,function(x) if(length(x)>1) tail(x,-1) else NULL) 
library(plyr) 
library(data.table) 
res6<- lapply(res5,function(x) lapply(x,function(x1) {x1<-data.table(x1); x1[,spec:=paste(spec,collapse=","),by=c("Seq","Mod","z")]}))
?res7<-lapply(res6,function(x) lapply(x,function(x1) {x1$counts<-sapply(x1$spec, function(x2) length(gsub("\\s", "", unlist(strsplit(x2, ",")))));x3<-as.data.frame(x1);names(x3)[6]<- as.character(unique(x3$folder_name));x3[,-c(1,5)]}))
?res8<-lapply(res7,function(x) Reduce(function(...) merge(...,by=c("Seq","Mod","z"),all=TRUE),x)) 
?res9<-res8[lapply(res8,length)!=0] 
?res10<- Reduce(function(...) merge(...,by=c("Seq","Mod","z"),all=TRUE),res9)
head(res10,3)
?# ?????????????????? Seq??????? Mod z c2 c3 t2
#1 aAAAAAAAAAAAAAATATAGPR 1-n_acPro/ 2 NA NA? 1
#2? aAAAAAAAAAAASSPVGVGQR 1-n_acPro/ 2 NA NA? 1
#3?????? aAAAAAAAAAGAAGGR 1-n_acPro/ 2? 1 NA? 1
A.K.