首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >vennCounts的VennDiagram创建列表

vennCounts的VennDiagram创建列表
EN

Stack Overflow用户
提问于 2011-03-21 17:14:21
回答 1查看 2.3K关注 0票数 2

我有一张这样的桌子:

代码语言:javascript
复制
> 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会给出以下输出:

代码语言:javascript
复制
> 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的列表。

你能帮帮我吗?

EN

回答 1

Stack Overflow用户

发布于 2011-06-21 02:15:46

这里有一个可能的解决方案。基本上,它涉及到将矩阵转换为字符向量,因为有一些方便的函数用于匹配文本字符串。

代码语言:javascript
复制
## 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)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5375642

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档