### R code from vignette source 'vignettes/gCMAP/inst/doc/keggReactome.Rnw' ################################################### ### code chunk number 1: keggReactome.Rnw:25-26 ################################################### options(warn=-1) ################################################### ### code chunk number 2: load.annotation ################################################### library(reactome.db) library(gCMAP) library(Matrix) ## use multiple cores if available options(mc.cores=2) ## retrieve entrez ids of pathway members pathways <- as.list(reactomePATHID2EXTID) ## retrieve names pathway.names <- unlist(mget(names(pathways), reactomePATHID2NAME)) pathway.names <- pathway.names[ match(names( pathways), names( pathway.names )) ] ## remove categories with duplicated or missing names filtered.names <- duplicated( names( pathway.names)) | is.na(pathway.names) pathways <- pathways[ ! filtered.names ] pathway.names <- pathway.names[ ! filtered.names] ################################################### ### code chunk number 3: subset.collections ################################################### head( pathway.names ) human <- grepl( "^Homo sapiens", pathway.names) ################################################### ### code chunk number 4: reactome.human ################################################### pheno.data <- as( data.frame(name=pathway.names[ human ], row.names=names(pathways[ human ]) ), "AnnotatedDataFrame") i.matrix <- Matrix::t( incidence( pathways[ human ] ) ) reactome.hs <- CMAPCollection( i.matrix, phenoData=pheno.data, annotation='org.Hs.eg', signed=rep( FALSE, ncol(i.matrix)) ) ################################################### ### code chunk number 5: pathway2cmap ################################################### pathway2cmap <- function(pathways, pathway.names, selected, anno){ pheno.data <- as( data.frame(name=pathway.names[ selected ], row.names=names(pathways[ selected ]) ), "AnnotatedDataFrame") i.matrix <- Matrix::t( incidence(pathways[ selected ]) ) CMAPCollection(i.matrix, phenoData=pheno.data, annotation=anno, signed=rep(FALSE, ncol(i.matrix))) } ################################################### ### code chunk number 6: reactome.mouse ################################################### mouse <- grepl( "^Mus musculus", pathway.names) reactome.mm <- pathway2cmap( pathways, pathway.names, selected=mouse, "org.Mm.eg") ################################################### ### code chunk number 7: kegg ################################################### library(KEGG.db) ## retrieve entrez ids of pathway members pathways <- as.list(KEGGPATHID2EXTID) ## retrieve names pathway.names <- unlist(mget(sub("^...", "",names(pathways)), KEGGPATHID2NAME)) ## species-specific CMAPCollections human <- grepl( "^hsa", names( pathways )) KEGG.hs <- pathway2cmap( pathways, pathway.names, selected=human, "org.Hs.eg") mouse <- grepl( "^mmu", names( pathways )) KEGG.mm <- pathway2cmap( pathways, pathway.names, selected=mouse, "org.Mm.eg") ################################################### ### code chunk number 8: sessionInfo ################################################### sessionInfo()