##
## Example using a list of item names belonging to the
## specified group.
##
## construct some fake gene names..
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)
input
venn(input)
##
## Example using a list of item indexes belonging to the
## specified group.
##
GroupA.i <- which(geneNames %in% GroupA)
GroupB.i <- which(geneNames %in% GroupB)
GroupC.i <- which(geneNames %in% GroupC)
GroupD.i <- which(geneNames %in% GroupD)
input.i <-list(A=GroupA.i,B=GroupB.i,C=GroupC.i,D=GroupD.i)
input.i
venn(input.i)
##
## Example using a data frame of indicator ('f'lag) columns
##
GroupA.f <- geneNames %in% GroupA
GroupB.f <- geneNames %in% GroupB
GroupC.f <- geneNames %in% GroupC
GroupD.f <- geneNames %in% GroupD
input.df <- data.frame(A=GroupA.f,B=GroupB.f,C=GroupC.f,D=GroupD.f)
head(input.df)
venn(input.df)
## smaller set to create empty groupings
small <- input.df[1:20,]
venn(small, simplify=FALSE) # with empty groupings
venn(small, simplify=TRUE) # without empty groupings
## Capture group counts, but don't plot
tmp <- venn(input, show.plot=FALSE)
tmp
## Show internal binary group labels
venn(input, showSetLogicLabel=TRUE)
## Limit universe
tmp <- venn(input, universe=geneNames[1:100])
tmp
##
## Example to determine which elements are in A and B but not in
## C and D: first determine the universe, then form indicator columns
## and perform intersections on these. R allows using the set operations
## directly, but some might find this approach more intuitive.
##
universe <- unique(c(GroupA,GroupB,GroupC,GroupD))
GroupA.l <-universe %in% GroupA
GroupB.l <-universe %in% GroupB
GroupC.l <-universe %in% GroupC
GroupD.l <-universe %in% GroupD
## Genes that are in GroupA and in GroupB but not in GroupD (unification
## of sets III0 and II00 in the venn diagram:
universe[GroupA.l & GroupB.l & !GroupD.l]
##
## Alternatively: construct a function to test for the pattern you want.
##
test <- function(x) (x %in% GroupA) & (x %in% GroupB) & !(x %in% GroupC)
universe[ test(universe) ]Run the code above in your browser using DataLab