Karim Mezhoud
2014-Oct-20 13:28 UTC
[R] matching genes to a list of gene groups an built binary data frame
Dear All,
I have a gene list
Genes <- c("ACACA", "BAX" , "BCL2",
"BID", "BAX", "MAPK9")
and a list of group of genes
ListGroup <- list(group1=c("ACACA" ,"AHSA1"
,"AIMP2" , "AKR1B1",
"AKT1", "AKT1S1"), group2=c("ANXA1" ,
"AR" , "ARID1A" ,
"ATM" , "BAK1" , "BAX" ),
group3=c("BCL2" , "BCL2L1" ,
"BCL2L11" , "BECN1" , "BID" ,
"BIRC2"))
ListGroup
$group1
[1] "ACACA" "AHSA1" "AIMP2" "AKR1B1"
"AKT1" "AKT1S1"
$group2
[1] "ANXA1" "AR" "ARID1A" "ATM"
"BAK1" "BAX"
$group3
[1] "BCL2" "BCL2L1" "BCL2L11"
"BECN1" "BID" "BIRC2"
I would like to built a data frame as:
ACACA BAX BCL2 BID BAX MAPK9
group1 1 0 0 0 0 0
group2 0 1 0 0 1 0
group3 0 0 1 1 0 0
Many thanks,
Karim
[[alternative HTML version deleted]]
David Winsemius
2014-Oct-20 17:32 UTC
[R] matching genes to a list of gene groups an built binary data frame
On Oct 20, 2014, at 6:28 AM, Karim Mezhoud wrote:> Genes <- c("ACACA", "BAX" , "BCL2", "BID", "BAX", "MAPK9") > > and a list of group of genes > > ListGroup <- list(group1=c("ACACA" ,"AHSA1" ,"AIMP2" , "AKR1B1", > "AKT1", "AKT1S1"), group2=c("ANXA1" , "AR" , "ARID1A" , > "ATM" , "BAK1" , "BAX" ), group3=c("BCL2" , "BCL2L1" , > "BCL2L11" , "BECN1" , "BID" , "BIRC2"))Desired:> I would like to built a data frame as: > > ACACA BAX BCL2 BID BAX MAPK9 > group1 1 0 0 0 0 0 > group2 0 1 0 0 1 0 > group3 0 0 1 1 0 0 >> sapply(Genes, function(x) as.numeric(sapply(ListGroup, '%in%', x=x) ) )ACACA BAX BCL2 BID BAX MAPK9 [1,] 1 0 0 0 0 0 [2,] 0 1 0 0 1 0 [3,] 0 0 1 1 0 0 ?'%in%' The x=x asserts that the x value will be used as the first argument to %in% so ListGroup items will be used as the table arguments. It's a matrix, so as.data.frame would be needed to deliver a dfrm. -- David Winsemius Alameda, CA, USA