Hi all,

I have a large table mapping thousands of COGs(groups of genes) to pathways.
# Ex
COG0001 patha   pathb   pathc
COG0002 pathd   pathe
COG0003 pathe   pathf   pathg   pathh
##

I would like to combine this information into a big list such as below
COG2PATHWAY<- list (COG0001 = c ("patha ","pathb ","pathc "),COG0002=c("pathd","pathe"),COG0003=c("pathf","pathg","pathh"))

I am stuck and have tried various methods involving (probably mangled) versions of lappy and loops.

Any suggestions on the most efficient way to do this would be great.

Thanks,

Alison

Here is my latest attempt.

#####

line_num<-length(scan(file="/g/bork8/waller/ test_COGtoPath.txt",what="character",sep="\n"))
COG2Path<-vector("list",line_num)
COG2Path<-lapply(1:(line_num-1),function(x) scan(file="/g/bork8/waller/ test_COGtopath.txt",skip=x,nlines=1,quiet=T,what='character',sep="\t"))

#####

I am getting an error

#####

>COG2Path<-lapply(1:(line_num-1),function(x) scan(file="/g/bork8/ waller/ test_COGtopath.txt",skip=x,nlines=1,quiet=T,what='character',sep="\t"))
Error in file(file, "r") : cannot open the connection
In addition: Warning message:
In file(file, "r") :

But if I do scan alone I don't get an error

# then I suppose it looks like the easiest wasy to name the list variables is using unix to cut the first column out and then read that in. names(COG2Path)<-scan(file="/g/bork8/waller/ test_col_names.txt",sep="\t",what="character")

______________________________________________
R-help@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.

Reply via email to