[R] new question
arun
smartpink111 at yahoo.com
Thu Mar 28 15:18:39 CET 2013
Hi,
Try this:
Spec <- function(lista,FDR_k) {
list.new<-lapply(lista,function(x) within(x,{spec<- as.character(spec)}))
split.list<-split(list.new,names(lista))
#Data needed with FDR<FDR_k
seq.mod.z<-lapply(seq_along(split.list),function(i) lapply(split.list[[i]],function(x) x[x[["FDR"]]<FDR_k,c("Seq","Mod","z","spec")]))
names(seq.mod.z)<- names(split.list)
#insert colunm with the name of the folder
folder.name<-lapply(seq.mod.z,function(x) lapply(names(x),function(i) do.call(rbind,lapply(x[i],function(x) cbind(folder_name=i,x)))))
#merge data with the same Seq, Mod and z
library(plyr)
library(data.table)
merge.data<- lapply(folder.name,function(x) lapply(x,function(x1) {x1<-data.table(x1); x1[,spec:=paste(spec,collapse=","),by=c("Seq","Mod","z")]}))
#colunm with number of spec
count.spec<-lapply(merge.data,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)]}))
count.specUnique<-lapply(count.spec,function(x) lapply(x,unique))
#count spec by group (2-columns)
spec.group<-lapply(count.specUnique,function(x) Reduce(function(...) merge(...,by=c("Seq","Mod","z"),all=TRUE),x))
#spec.group1<-spec.group[lapply(spec.group,length)!=0]
#data frame with count of spec
res<- Reduce(function(...) merge(...,by=c("Seq","Mod","z"),all=TRUE),spec.group)
res[is.na(res)] <- 0
res<- as.data.frame(res,stringsAsFactors=FALSE)
print(res)
}
Spec(ListFacGroup,0.05)
# Seq Mod z a2 c2 c3 t2
#1 aAAAAAAAAAAAAAATATAGPR 1-n_acPro/ 2 5 0 0 1
#2 aAAAAAAAAAAASSPVGVGQR 1-n_acPro/ 2 6 0 0 1
#3 aAAAAAAAAAGAAGGR 1-n_acPro/ 2 1 1 0 1
#4 AAAAAAALQAK 2 1 0 1 1
#5 aAAAAAGAGPEMVR 1-n_acPro/ 2 2 2 1 2
#6 aAAAAEQQQFYLLLGNLLSPDNVVR 1-<_Carbamoylation/ 2 1 0 0 1
#7 aAAAAEQQQFYLLLGNLLSPDNVVR 1-<_Carbamoylation/ 3 1 0 0 1
#8 aAAAAEQQQFYLLLGNLLSPDNVVR 1-n_acPro/ 2 0 1 0 0
#9 aAAAAEQQQFYLLLGNLLSPDNVVR 1-n_acPro/ 3 1 2 2 1
#10 AAAAAPGTAEK 2 0 1 0 0
#11 aAAAASAPQQLSDEELFSQLR 1-n_acPro/ 2 1 0 0 1
#12 aAAAAVGNAVPCGAR 1-n_acPro/ 2 1 1 1 1
#13 AAAAAWEEPSSGNGTAR 2 1 1 1 1
#14 aAAAELSLLEK 1-n_acPro/ 1 1 0 0 1
#15 aAAAELSLLEK 1-n_acPro/ 2 1 1 1 1
#16 AAAAEVLGLILR 2 1 1 1 1
#17 aAAAGAAAAAAAEGEAPAEMGALLLEK 1-n_acPro/ 3 1 1 1 1
#18 aAAAGGGGPGTAVGATGSGIAAAAAGLAVYR 1-<_Carbamoylation/ 3 0 0 1 0
#19 aAAAGGGGPGTAVGATGSGIAAAAAGLAVYR 1-n_acPro/ 3 1 0 0 1
#20 aAAANSGSSLPLFDCPTWAGKPPPGLHLDVVK 1-n_acPro/ 3 1 0 0 1
#21 AAAAAAAkAAK 8-K_ac/ 2 0 1 0 0
#22 aAAAVGAGHGAGGPGAASSSGGAR 1-n_acPro/ 2 0 1 1 0
#23 aAAAVGAGHGAGGPGAASSSGGAR 1-n_acPro/ 3 0 0 1 0
#24 aAADGDDSLYPIAVLIDELR 1-n_acPro/ 2 0 0 1 0
Regarding the 2nd question, I am a bit busy now. Will try it later.
A.K.
________________________________
From: Vera Costa <veracosta.rt at gmail.com>
To: arun <smartpink111 at yahoo.com>
Sent: Thursday, March 28, 2013 9:43 AM
Subject: Re: new question
I don't remove duplicated, but write only one time. If I haven't "unique" I have the same row a lot of times, but with "unique" we remove all. I need this row write only one time.
without "unique" the output is
1 aA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 1 1 1
18 aAAAGGGGPGTAVGATGSGIAAAAAGLAVYR 1-<_Carbamoylation/ 3 0 0 1 0
19 aAAAGGGGPGTAVGATGSGIAAAAAGLAVYR 1-n_acPro/ 3 1 0 0 1
20 aAAANSGSSLPLFDCPTWAGKPPPGLHLDVVK 1-n_acPro/ 3 1 0 0 1
21 AAAAAAAkAAK 8-K_ac/ 2 0 1 0 0
22 aAAAVGAGHGAGGPGAASSSGGAR 1-n_acPro/ 2 0 1 1 0
23 aAAAVGAGHGAGGPGAASSSGGAR 1-n_acPro/ 3 0 0 1 0
24 aAADGDDSLYPIAVLIDELR 1-n_acPro/ 2 0 0 1 0
But I need the row
1 aAAAAAAAAAAAAAATATAGPR 1-n_acPro/ 2 5 0 0 1
write only one time
More information about the R-help
mailing list