我有一张这样的桌子:
> updownregtable
PIM WDR MYC OBX
ILMN_1651282 0 0 0 0
ILMN_1651354 0 0 0 0
ILMN_1651358 0 0 0 0
ILMN_1656638 0 0 0 0
ILMN_1657235 0 0 0 0
ILMN_1657639 -1 0 0 0 行名是基因的代码。colnames是细胞中的转染体。
我使用以下链接中的函数创建一个vennDiagram:http://bioinfo-mite.crb.wsu.edu/Rcode/Venn.R
在生成结果之前,vennCounts vennDiagram会给出以下输出:
> vennCounts(regulationtable)
PIM WDR MYC OBX Counts
[1,] 0 0 0 0 740
[2,] 0 0 0 1 5
[3,] 0 0 1 0 1
[4,] 0 0 1 1 0
[5,] 0 1 0 0 4
[6,] 0 1 0 1 1
[7,] 0 1 1 0 0
[8,] 0 1 1 1 0
[9,] 1 0 0 0 6
[10,] 1 0 0 1 0
[11,] 1 0 1 0 0
[12,] 1 0 1 1 0
[13,] 1 1 0 0 1
[14,] 1 1 0 1 0
[15,] 1 1 1 0 0
[16,] 1 1 1 1 0现在,我想在该组中存储的所有genename中每行创建一个列表。例如:
组1-创建包含740个通用名称的列表
组2-创建一个包含5个通用名称的列表
组3-创建具有1个通用名称的列表
Group 5-创建一个包含4个通用名称的列表
组6-创建具有1个通用名称的列表
Group 9-创建具有6个通用名称的列表
组13 -创建一个具有1个genename的列表。
你能帮帮我吗?
发布于 2011-06-21 02:15:46
这里有一个可能的解决方案。基本上,它涉及到将矩阵转换为字符向量,因为有一些方便的函数用于匹配文本字符串。
## create an example matrix - analagous to your 'updownregtable'
nc <- 4
nr <- 1000
M <- matrix(rbinom(nr*nc,1,0.5),
nrow = nr, ncol = nc,
dimnames = list(sapply(1:nr, function(i) paste(sample(letters,5),collapse='')),paste('V',1:nc)))
## function for converting rows of a matrix to lines of text
matrix2text <- function(y) apply(y,1,function(x)paste(x,collapse=','))
## unique entries - analagous to the first four columns of your matrix
## vennCounts(regulationtable)
Mu <- matrix2text(unique(M))
names(Mu) <- NULL
## convert the full matrix to text
Mc <- matrix2text(M)
## find the matching groups
matching.groups <- sapply(Mu,function(x)names(grep(x,Mc,value=TRUE)))
## here are the counts per group
counts.per.group <- sapply(matching.groups,length)https://stackoverflow.com/questions/5375642
复制相似问题