vennDiagram function in
limma takes a
TestResults matrix, which is simply a matrix containing 0, 1, -1, indicating if a given row (i.e. gene) is significant up or down for a given column (i.e. experiment), such that 0 = not significant, 1 = significant up, -1 = significant down. The
vennDigram function summarizes visually how rows partition into sets. So to get the pieces of the venn diagram you have to apply logic to the rows of your matrix to get the sets you want. For instance, to get any genes that are significantly changed up OR down in both experiments 4 AND 5, (like your example above), you could do:
which(results[,4] != 0 & results[,5] != 0)
This returns the overlap set from both experiments. Using combinations of statements containing AND/OR you can retrieve any set represented in the venn diagram. However, it's easy to make mistakes with the logic, so it can be useful to check your results to make sure the counts you retrieve match the numbers you see in the venn diagram. For instance to get genes up only in experiment 4 but not experiment 5, you would apply the following:
sum(results[,4] == 1 & results[,5] != 1)
Since the result of the statement in parenthesis above is a boolean vector, you can use it as an index vector to get your gene names. Assuming a
limma object called
fit2 (like in the
# make a boolean index vector based on criteria
iv <- results[,4] == 1 & results[,5] != 1
# use it to extract gene names
You can't get the names from the
Table function like you mentioned above, as that just summarizes the elements of your matrix.
There are a few ways to work with venn diagrams and there's a good biostar question on this.
Also, if you want an easy way to get the sets in R, you can use a function written by Thomas Girke:
When you draw a venn diagram using his function (the docs are in the comments), the sets are all saved in a list and can be easily accessed.