library("GO.db") library('GOstats') library("Rgraphviz") library('grDevices') # main directory to search for postprocessing data #mainDir <- '../MF/norm_vs_tumor' #mainDir <- '../MF/tumor_vs_metas' #mainDir <- '../BP/norm_vs_tumor' mainDir <- '../BP/tumor_vs_metas' # prefix for graph picture #picNamePref <- 'MF_norm_vs_tumor_' #picNamePref <- 'MF_tumor_vs_metas_' #picNamePref <- 'BP_norm_vs_tumor_' picNamePref <- 'BP_tumor_vs_metas_' # domain type for graph #graphType <- GOMFPARENTS graphType <- GOBPPARENTS plotSelected <- function (g, selectednodes , r = NULL, add.counts = TRUE, max.nchar = 20, node.colors = c(selected = "green", not = "white"), node.shape = "plaintext", dotfilename = 'plot-dot.txt', ...) { if (!require("Rgraphviz", quietly = TRUE)) stop("The Rgraphviz package is required for this feature") n <- nodes(g) termLab <- if ("term" %in% names(nodeDataDefaults(g))) { unlist(nodeData(g, attr = "term")) } else n if (!is.null(max.nchar)) termLab <- sapply(termLab, substr, 1L, max.nchar, USE.NAMES = FALSE) ncolors <- rep(node.colors["not"], length(n)) ncolors[g@nodes %in% selectednodes] <- node.colors["selected"] if (!is.null(r) && add.counts) { if (is.null(names(node.colors))) stop(paste("invalid node.colors arg:", "must have named elements 'sig' and 'not'")) resultTerms <- names(pvalues(r)) ncolors <- ifelse(n %in% sigCategories(r), node.colors["sig"], node.colors["not"]) counts <- sapply(n, function(x) { if (x %in% resultTerms) { paste(geneCounts(r)[x], "/", universeCounts(r)[x], sep = "") } else { "0/??" } }) nlab <- paste(termLab, counts) } else { nlab <- termLab } nattr <- makeNodeAttrs(g, label = nlab, shape = node.shape, fillcolor = ncolors, fixedsize = TRUE) plot(g, ..., nodeAttrs = nattr) } # find postprocessing data pdp_pp <- list.files(mainDir, '*_disk_data') pdpPath <- paste(mainDir, pdp_pp, 'postprocessing_results', sep='/') # find all SIZE_ABOVE_stats there stats <- list.files(pdpPath, 'SIZE_ABOVE_stats_mu') for (stat in stats) { # resolve full path statPath <- paste(pdpPath, stat, sep='/') # resolve name mergeSuffix <- unlist(strsplit(stat, '.txt')) # resolve graph picture name picName <- paste(picNamePref, mergeSuffix, sep='') # load content and extract nodes statContent <- read.table(statPath, sep=',', header=T) results.nodes <- as.vector(statContent[[1]]) # create graph graph <- GOGraph(results.nodes, graphType) picNameEx = paste(picName, '.pdf', sep='') dotNameEx = paste(picName, '.dot.txt', sep='') # create device instance pdf(file = picNameEx, width=20, height=20, bg='white', pointsize=1, onefile=FALSE, useDingbats=FALSE ) cat(names(dev.cur()), 'device initialized with size', dev.size('px'), 'px', '\n') # toDot(g, dotfilename, nodeAttrs=nattr) # cat(dotNameEx, 'written\n') cat('On', picNameEx, 'plotting', length(nodes(graph)), 'nodes,', length(results.nodes), 'selected\n') gc(verbose=FALSE) tryCatch(plotSelected(graph, results.nodes, r = NULL, add.counts = FALSE, max.nchar = 20, node.shape="circle", dotfilename = dotNameEx ), error = function(e) cat('Error!\n')) dev.off() }