I am working in R and have a named list of character vectors. Each vector describes the genes present in a biological pathway.
Please see example below:
gene_sets = list(pathwayX= c("Gene3"),pathwayY= c("Gene2", "Gene3"),pathwayz= c("Gene1", "Gene2","Gene3"))
> gene_sets
$pathwayX
"Gene3"
$pathwayY
"Gene2" "Gene3"
$pathwayZ
"Gene1" "Gene2" "Gene3"
What I want to do is to convert the list into a binary matrix, with genes as columns and pathways as rows. 0 means gene is not present in the pathway and 1 means gene is present.
Gene1 | Gene2 | Gene3 | |
---|---|---|---|
pathwayX | 0 | 0 | 1 |
pathwayY | 0 | 1 | 1 |
pathwayZ | 1 | 1 | 1 |
mtabulate
in Quinten's answer, I found the Q&A that motivated this function: create a data frame of tag frequencies from a list of tag vectors. I have voted up that question. I shall update my answer with a benchmark when I am available. – Singularize