ベン図の要素

MikuHatsune2013-05-31

ベン図を描いていたのだが、各要素がどこに所属するか、Rに入ってない(!?!?)。
というわけで無理矢理作った。

library(gplots)
# venn の example から
oneName <- function() paste(sample(LETTERS, 5, replace=TRUE), collapse="")
geneNames <- replicate(1000, oneName())

GroupA <- sample(geneNames, 400, replace=FALSE)
GroupB <- sample(geneNames, 750, replace=FALSE)
GroupC <- sample(geneNames, 250, replace=FALSE)
GroupD <- sample(geneNames, 300, replace=FALSE)
input  <-list(GroupA, GroupB, GroupC, GroupD)

v0 <- venn(input)

# geneName が Group にあるかないかを一括して計算する
# ある gene が GroupA, B, C にあるかないかを探すのが第一段階の mapply
# それをすべての gene についてやるのが第二段階の mapply
g0 <- mapply(function(y) mapply(function(x) y %in% x, input), geneNames)
element <- apply(g0 + 0, 2, paste, collapse="") # あれば 1, なければ 0
element
 VUZTT  FFZNY  ADBMY  UZAKB  WMIGN  HNBXW  BALTC  WDNSK  VCPRU  GBELE  RZKKZ 
"0110" "0110" "0000" "0101" "1110" "0000" "0100" "0100" "0100" "1100" "1100"