[R] new question
arun
smartpink111 at yahoo.com
Tue Mar 19 17:40:47 CET 2013
I deleted the 't' subfolders from the dados folder.
If you don't have 't' folders, wouldn't it be better to use:
directory<- "/home/arunksa111/dados"
FacGroup<-c(0,1,0,2,2,0,0)
#instead of
#FacGroup<-c(0,1,0,2,2,0,3)
FacGroup<-c(0,1,0,2,2,0,3)
lista[FacGroup!=0]
#[1] "/home/arunksa111/dados/a2/MSMS_23PepInfo.txt"
#[2] "/home/arunksa111/dados/c2/MSMS_23PepInfo.txt"
#[3] "/home/arunksa111/dados/c3/MSMS_23PepInfo.txt"
#[4] NA
FacGroup<-c(0,1,0,2,2,0,0)
lista[FacGroup!=0]
#[1] "/home/arunksa111/dados/a2/MSMS_23PepInfo.txt"
#[2] "/home/arunksa111/dados/c2/MSMS_23PepInfo.txt"
#[3] "/home/arunksa111/dados/c3/MSMS_23PepInfo.txt"
Couldn't reproduce the error you mentioned.
Spec(ListFacGroup,0.05)
# Seq Mod z a2 c2 c3
#1 aAAAAAAAAAGAAGGR 1-n_acPro/ 2 1 1 0
#2 AAAAAAAkAAK 8-K_ac/ 2 1 1 0
#3 aAAAAAGAGPEMVR 1-n_acPro/ 2 2 2 1
#4 aAAAAEQQQFYLLLGNLLSPDNVVR 1-n_acPro/ 2 1 1 0
#5 aAAAAEQQQFYLLLGNLLSPDNVVR 1-n_acPro/ 3 2 2 2
#6 AAAAAPGTAEK 2 1 1 0
#7 aAAAAVGNAVPCGAR 1-n_acPro/ 2 1 1 1
_______________________________________________________
-----------------------------------------------------------------------------------------
A.K.
________________________________
From: Vera Costa <veracosta.rt at gmail.com>
To: arun <smartpink111 at yahoo.com>
Sent: Tuesday, March 19, 2013 10:14 AM
Subject: Re: new question
Hi again.
you sent me a code ( e few time ago)
GetFileList <- function(directory,number){
setwd(directory)
filelist1<-dir()[file.info(dir())$isdir]
direct<-dir(directory,pattern = paste("MSMS_",number,"PepInfo.txt",sep=""), full.names = FALSE, recursive = TRUE)
direct<-lapply(direct,function(x) paste(directory,"/",x,sep=""))
lista<-unlist(direct)
output<- list(filelist1,lista)
return(output)
}
ReadDir<-function(FacGroup){
list.new<-lista[FacGroup!=0]
read.list<-lapply(list.new, function(x) read.table(x,header=TRUE, sep = "\t"))
names(read.list)<-file.list.names[FacGroup!=0]
return (read.list)
}
directory<-"C:/Users/Vera Costa/Desktop/dados.lixo"
file.list.names<-GetFileList(directory,23) [[1]]
lista<-GetFileList(directory,23) [[2]]
FacGroup<-c(0,1,0,2,2,0,3)
#FacGroup<-c(0,1,1,1,0,2,2,2)
ListFacGroup<-ReadDir(FacGroup)
#zPValues(ListFacGroup,FacGroup)
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 spec by group (2-columns)
spec.group<-lapply(count.spec,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
print(res)
resNew<-do.call(cbind,lapply(split(names(res)[4:ncol(res)],gsub("[0-9]","",names(res)[4:ncol(res)])), function(i) {x<-if(ncol(res[i])>1) rowSums(res[i]) else res[i]; colnames(x)<-NULL;x}))
print(head(resNew),10)
print("vera")
print(names(resNew))
indx<-combn(names(resNew),2)
t.test.p.value <- function(...) {
obj<-try(t.test(...), silent=TRUE)
if (is(obj, "try-error")) return(NA) else return(obj$p.value)
}
resPval<-do.call(cbind,lapply(seq_len(ncol(indx)),function(i) {x<-as.data.frame(apply(resNew[,indx[,i]],1,t.test.p.value)); colnames(x)<-paste("Pvalue",paste(indx[,i],collapse=""),sep="_");x}))
print(resPval)
resF<-cbind(res,resPval)
print(resF)
Spec(ListFacGroup,0.05)
And it is ok for the file list that you have. But if I apply to one file list with only a and c (for example) I have an error "Error in combn(names(resNew), 2) : n < m" How can I adapt this for all cases?
2013/3/18 arun <smartpink111 at yahoo.com>
I hope this solved the problem...
>
>
>
>
>----- 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: Monday, March 18, 2013 2:27 PM
>Subject: Re: new question
>
>
>
>
> z.boxplot<- function(lst){
> new.list<- lapply(lst,function(x) x[x$FDR<0.01,])
>print(new.list)
> par(mfrow=c(2,2))
>b1<-lapply(names(new.list),function(x) lapply(new.list[x],function(y) boxplot(FDR~z,data=y,xlab="Charge",ylab="FDR",main=x)))
>
>}
> z.boxplot(ListFacGroup) #prints new.list
>
>If you want to turn off that:
> z.boxplot<- function(lst){
> new.list<- lapply(lst,function(x) x[x$FDR<0.01,])
>#print(new.list)
> par(mfrow=c(2,2))
>b1<-lapply(names(new.list),function(x) lapply(new.list[x],function(y) boxplot(FDR~z,data=y,xlab="Charge",ylab="FDR",main=x)))
>
>}
> z.boxplot(ListFacGroup)
>A.K.
>
>
>
>
>
>________________________________
>From: Vera Costa <veracosta.rt at gmail.com>
>To: arun <smartpink111 at yahoo.com>
>Sent: Monday, March 18, 2013 1:59 PM
>Subject: Re: new question
>
>
>For example, if I run you code without "pdf...." and "dev.off" I have what I want
>
>directory<- "C:/Users/Vera Costa/Desktop/dados.lixo"
> #modified the function
>GetFileList <- function(directory,number){
> setwd(directory)
> filelist1<-dir()
>
> lista<-dir(directory,pattern = paste("MSMS_",number,"PepInfo.txt",sep=""), full.names = TRUE, recursive = TRUE)
> output<- list(filelist1,lista)
> return(output)
> }
>file.list.names<-GetFileList(directory,23)[[1]]
>lista<-GetFileList(directory,23)[[2]]
>FacGroup<-c(0,1,0,2,2,0,3)
>ReadDir<-function(FacGroup){
> list.new<-lista[FacGroup!=0]
> read.list<-lapply(list.new, function(x) read.table(x,header=TRUE, sep = "\t"))
> names(read.list)<-file.list.names[FacGroup!=0]
> return (read.list)
> }
>ListFacGroup<-ReadDir(FacGroup)
>ListFacGroup
> z.boxplot<- function(lst){
> new.list<- lapply(lst,function(x) x[x$FDR<0.01,])
> print(new.list)
> #pdf("VeraBP.pdf")
> par(mfrow=c(2,2))
> lapply(names(new.list),function(x) lapply(new.list[x],function(y) boxplot(FDR~z,data=y,xlab="Charge",ylab="FDR",main=x)))
> #dev.off()
> }
> z.boxplot(ListFacGroup)
>
>
>
>
>
>But I have the results too (I don't need it)
>
>
>[[1]]
>[[1]]$a2
>[[1]]$a2$stats
> [,1] [,2]
>[1,] 0.0000000000 0.0000000000
>[2,] 0.0000000000 0.0000000000
>[3,] 0.0001355197 0.0002175095
>[4,] 0.0010588777 0.0004350190
>[5,] 0.0016571381 0.0004350190
>[[1]]$a2$n
>[1] 8 2
>[[1]]$a2$conf
> [,1] [,2]
>[1,] -0.0004559846 -0.0002685062
>[2,] 0.0007270240 0.0007035253
>[[1]]$a2$out
>[1] 0.00494012
>[[1]]$a2$group
>[1] 1
>[[1]]$a2$names
>[1] "2" "3"
>
>[[2]]
>[[2]]$c2
>[[2]]$c2$stats
> [,1] [,2]
>[1,] 0.0000000000 0.0000000000
>[2,] 0.0000000000 0.0000000000
>[3,] 0.0001355197 0.0002175095
>[4,] 0.0010588777 0.0004350190
>[5,] 0.0016571381 0.0004350190
>[[2]]$c2$n
>[1] 8 2
>[[2]]$c2$conf
> [,1] [,2]
>[1,] -0.0004559846 -0.0002685062
>[2,] 0.0007270240 0.0007035253
>[[2]]$c2$out
>[1] 0.00494012
>[[2]]$c2$group
>[1] 1
>[[2]]$c2$names
>[1] "2" "3"
>
>[[3]]
>[[3]]$c3
>[[3]]$c3$stats
> [,1] [,2]
>[1,] 0.000000000 0.0000000000
>[2,] 0.000000000 0.0000000000
>[3,] 0.000000000 0.0000000000
>[4,] 0.002226409 0.0002086594
>[5,] 0.002226409 0.0004173187
>[[3]]$c3$n
>[1] 6 4
>[[3]]$c3$conf
> [,1] [,2]
>[1,] -0.001436105 -0.0001648409
>[2,] 0.001436105 0.0001648409
>[[3]]$c3$out
>[1] 0.00560348
>[[3]]$c3$group
>[1] 1
>[[3]]$c3$names
>[1] "2" "3"
>
>[[4]]
>[[4]]$t2
>[[4]]$t2$stats
> [,1] [,2] [,3]
>[1,] 0 0.0000000000 0
>[2,] 0 0.0000000000 0
>[3,] 0 0.0002908668 0
>[4,] 0 0.0025929827 0
>[5,] 0 0.0052577771 0
>[[4]]$t2$n
>[1] 1 10 5
>[[4]]$t2$conf
> [,1] [,2] [,3]
>[1,] 0 -0.001004691 0
>[2,] 0 0.001586424 0
>[[4]]$t2$out
>[1] 0.0092051934 0.0007174888
>[[4]]$t2$group
>[1] 2 3
>[[4]]$t2$names
>[1] "1" "2" "3"
>
>
More information about the R-help
mailing list