library(graphite) ##Need to install the graphite package to load KEGG pathways paths<- pathways('hsapiens','kegg') ##Load in all homo sapiens pathways keep <- read.table("pathways.txt",sep='\n') ###OPTIONAL: If only certain pathways are to be converted into priors keep<-sapply(keep$V1,tolower) ###Convert pathway names to lowercase to match KEGG inds <- which(tolower(names(paths))%in%keep) ## Find which indices correspond to pathways to keep goodPaths <- paths[inds] ###Select only these pathways allGenes <- c() dir.create("pathway_lists") ###Create a directory to store the pathways desired ###Loop through desired pathways and write them each as a file to the directory in .sif format for (i in 1:length(goodPaths)) { curr <- goodPaths[[i]] print(curr) curr2 <- convertIdentifiers(curr,"SYMBOL") edges <-graphite::edges(curr2) allGenes <- c(allGenes,unique(c(unique(edges$src),unique(edges$dest)))) edges <- edges[,c("src","dest")] write.table(edges,file=paste('pathway_lists/',curr@title,".txt",sep=''),row.names=FALSE,quote=FALSE,sep='\t') }