diff --git a/R/GOsummaries.R b/R/GOsummaries.R index f2c2111..0f16251 100644 --- a/R/GOsummaries.R +++ b/R/GOsummaries.R @@ -63,7 +63,7 @@ gosummaries_base = function(x){ comp$Percentage = sprintf("Up: %d\nDown: %d", length(x[[i]][[2]]), length(x[[i]][[1]])) } - res[[as.character(components[i])]] = comp + res[[i]] = comp } class(res) = "gosummaries" @@ -287,8 +287,6 @@ annotate.gosummaries = function(gosummaries, organism, components = 1:length(gos if(!is.gosummaries(gosummaries)) stop("Function requires a gosummaries type of object") - components = as.character(components) - #Compile gene lists gl = NULL for(i in seq_along(components)){ @@ -312,9 +310,9 @@ annotate.gosummaries = function(gosummaries, organism, components = 1:length(gos k = 1 for(i in seq_along(components)){ - for(j in seq_along(gosummaries[[components[i]]]$GPR)){ + for(j in seq_along(gosummaries[[i]]$GPR)){ lname = paste("gpr", j, sep = "") - gosummaries[[components[i]]]$GPR[[lname]] = gpr[gpr$query.number == k, -1] + gosummaries[[i]]$GPR[[lname]] = gpr[gpr$query.number == k, -1] k = k + 1 } } @@ -856,8 +854,6 @@ panel_crossbar = function(data, fontsize = 10, par){ #' of a gosummaries object. The legend and the actual plots for the panels are extracted #' later from the figure produced by this function. #' @author Raivo Kolde -#' @examples -#' # Example1 #' #' @rdname panel_boxplot #' @export @@ -1009,8 +1005,7 @@ customize = function(p, par){ #' differential expression it draws the boxplot of expression values. #' #' @param x a gosummaries object -#' @param components names of the gosummaries components to draw. The names are usually -#' numbers 1:n in character format. +#' @param components names of the gosummaries components to draw. #' @param classes name of the variable from annotation data.frame that defines the colors in the plot #' @param panel_plot plotting function for panel #' @param panel_customize customization function for the panel plot, menat for making @@ -1043,7 +1038,7 @@ customize = function(p, par){ #' plot(gs_limma, panel_height = 0, fontsize = 8) #' #' # Selecting only certain components -#' plot(gs_limma, components = as.character(c(1, 3)), fontsize = 8) +#' plot(gs_limma, components = c(1, 3), fontsize = 8) #' #' # Cutting the longer terms shorter (see the effect on the right wordcloud on first component) #' plot(gs_limma, term_length = 20, fontsize = 8) @@ -1054,24 +1049,24 @@ customize = function(p, par){ #' # Adjust panel plot type (see panel_boxplot help for options) #' data(gs_kmeans) #' -#' plot(gs_kmeans, panel_plot = panel_violin, classes = "Tissue", components = c("1", "2"), fontsize = 8) -#' plot(gs_kmeans, panel_plot = panel_violin_box, classes = "Tissue", components = c("1", "2"), fontsize = 8) +#' plot(gs_kmeans, panel_plot = panel_violin, classes = "Tissue", components = 1:2, fontsize = 8) +#' plot(gs_kmeans, panel_plot = panel_violin_box, classes = "Tissue", components = 1:2, fontsize = 8) #' #' # Adjust colorscheme for plot (see customize help for more information) #' cust = function(p, par){ #' p = p + scale_fill_brewer(par$classes, type = "qual", palette = 2) #' return(p) #' } -#' plot(gs_kmeans, panel_plot = panel_violin, panel_customize = cust, classes = "Tissue", components = c("1", "2"), fontsize = 8) +#' plot(gs_kmeans, panel_plot = panel_violin, panel_customize = cust, classes = "Tissue", components = 1:2, fontsize = 8) #' #' @method plot gosummaries #' #' @export -plot.gosummaries = function(x, components = names(x)[1:min(10, length(x))], classes = NA, panel_plot = NULL, panel_customize = NULL, panel_par = list(), panel_height = 5, panel_width = 30, fontsize = 10, term_length = 35, wordcloud_colors = c("grey70", "grey10"), filename = NA, ...){ +plot.gosummaries = function(x, components = 1:min(10, length(x)), classes = NA, panel_plot = NULL, panel_customize = NULL, panel_par = list(), panel_height = 5, panel_width = 30, fontsize = 10, term_length = 35, wordcloud_colors = c("grey70", "grey10"), filename = NA, ...){ # Check input if(!is.gosummaries(x)) stop("Function requires an object of gosummaries type") - if(any(!(as.character(components) %in% names(x)))) stop("Selected components are not present in data") + if(any(!(components %in% 1:length(x)))) stop("Selected components are not present in data") # Add classes to panel_par if(!is.na(classes)){ @@ -1084,7 +1079,7 @@ plot.gosummaries = function(x, components = names(x)[1:min(10, length(x))], clas } # Take out components of interest - x = x[as.character(components)] + x = x[components] if(length(x) < 1) stop("No components selected") # Add wordcloud colors and adjust the string length @@ -1242,8 +1237,8 @@ gosummaries.prcomp = function(x, annotation = NULL, components = 1:6, n_genes = #' #' # Create gosummaries object #' gs_kmeans = gosummaries(kmr, exp = exp2, annotation = tissue_example$annot) -#' plot(gs_kmeans, panel_height = 0, components = c("1", "2", "3"), fontsize = 8) -#' plot(gs_kmeans, classes = "Tissue", components = c("1", "2", "3"), fontsize = 8) +#' plot(gs_kmeans, panel_height = 0, components = 1:3, fontsize = 8) +#' plot(gs_kmeans, classes = "Tissue", components = 1:3, fontsize = 8) #' #' @method gosummaries kmeans #' @S3method gosummaries kmeans diff --git a/man/add_expression.gosummaries.Rd b/man/add_expression.gosummaries.Rd index 1d346f7..cefa2ac 100644 --- a/man/add_expression.gosummaries.Rd +++ b/man/add_expression.gosummaries.Rd @@ -40,7 +40,7 @@ gs_limma_exp1 = add_expression.gosummaries(gs_limma, exp = tissue_example$exp) print(gs_limma_exp1) -# Add just expression without annotations +# Add expression with annotations gs_limma_exp2 = add_expression.gosummaries(gs_limma, exp = tissue_example$exp, annotation = tissue_example$annot) print(gs_limma_exp1) diff --git a/man/gosummaries.MArrayLM.Rd b/man/gosummaries.MArrayLM.Rd index 576cf13..231fe8c 100644 --- a/man/gosummaries.MArrayLM.Rd +++ b/man/gosummaries.MArrayLM.Rd @@ -65,9 +65,9 @@ fit = limma::eBayes(fit) gs_limma = gosummaries(fit) gs_limma_exp = gosummaries(fit, exp = tissue_example$exp, annotation = tissue_example$annot) -plot(gs_limma) -plot(gs_limma, panel_height = 0) -plot(gs_limma_exp, classes = "Tissue") +plot(gs_limma, fontsize = 8) +plot(gs_limma, panel_height = 0, fontsize = 8) +plot(gs_limma_exp, classes = "Tissue", fontsize = 8) } \author{ Raivo Kolde diff --git a/man/gosummaries.kmeans.Rd b/man/gosummaries.kmeans.Rd index 138310c..b7e8130 100644 --- a/man/gosummaries.kmeans.Rd +++ b/man/gosummaries.kmeans.Rd @@ -55,8 +55,8 @@ kmr = kmeans(exp2, centers = 6, iter.max = 100) # Create gosummaries object gs_kmeans = gosummaries(kmr, exp = exp2, annotation = tissue_example$annot) -plot(gs_kmeans, panel_height = 0, components = c("1", "2", "3")) -plot(gs_kmeans, classes = "Tissue", components = c("1", "2", "3")) +plot(gs_kmeans, panel_height = 0, components = 1:3, fontsize = 8) +plot(gs_kmeans, classes = "Tissue", components = 1:3, fontsize = 8) } \author{ Raivo Kolde diff --git a/man/plot.gosummaries.Rd b/man/plot.gosummaries.Rd index 1df49c8..95d17a2 100644 --- a/man/plot.gosummaries.Rd +++ b/man/plot.gosummaries.Rd @@ -3,11 +3,10 @@ \title{Plot the GOsummaries figure} \usage{ \method{plot}{gosummaries} (x, - components = names(x)[1:min(10, length(x))], - classes = NA, panel_plot = NULL, - panel_customize = NULL, panel_par = list(), - panel_height = 5, panel_width = 30, fontsize = 10, - term_length = 35, + components = 1:min(10, length(x)), classes = NA, + panel_plot = NULL, panel_customize = NULL, + panel_par = list(), panel_height = 5, panel_width = 30, + fontsize = 10, term_length = 35, wordcloud_colors = c("grey70", "grey10"), filename = NA, ...) } @@ -15,8 +14,7 @@ \item{x}{a gosummaries object} \item{components}{names of the gosummaries components to - draw. The names are usually numbers 1:n in character - format.} + draw.} \item{classes}{name of the variable from annotation data.frame that defines the colors in the plot} @@ -88,26 +86,26 @@ plot(gs_limma, fontsize = 8) plot(gs_limma, panel_height = 0, fontsize = 8) # Selecting only certain components -plot(gs_limma, components = as.character(c(1, 3)), fontsize = 8) +plot(gs_limma, components = c(1, 3), fontsize = 8) # Cutting the longer terms shorter (see the effect on the right wordcloud on first component) -plot(gs_limma, term_length = 20) +plot(gs_limma, term_length = 20, fontsize = 8) # Change wordcloud colors -plot(gs_limma, term_length = 20, wordcloud_colors = c("#C6DBEF", "#08306B")) +plot(gs_limma, term_length = 20, wordcloud_colors = c("#C6DBEF", "#08306B"), fontsize = 8) # Adjust panel plot type (see panel_boxplot help for options) data(gs_kmeans) -plot(gs_kmeans, panel_plot = panel_violin, classes = "Tissue", components = c("1", "2")) -plot(gs_kmeans, panel_plot = panel_violin_box, classes = "Tissue", components = c("1", "2")) +plot(gs_kmeans, panel_plot = panel_violin, classes = "Tissue", components = 1:2, fontsize = 8) +plot(gs_kmeans, panel_plot = panel_violin_box, classes = "Tissue", components = 1:2, fontsize = 8) # Adjust colorscheme for plot (see customize help for more information) cust = function(p, par){ p = p + scale_fill_brewer(par$classes, type = "qual", palette = 2) return(p) } -plot(gs_kmeans, panel_plot = panel_violin, panel_customize = cust, classes = "Tissue", components = c("1", "2")) +plot(gs_kmeans, panel_plot = panel_violin, panel_customize = cust, classes = "Tissue", components = 1:2, fontsize = 8) } \author{ Raivo Kolde diff --git a/visual_test/tests.r b/visual_test/tests.r index ebf3763..027f4d1 100644 --- a/visual_test/tests.r +++ b/visual_test/tests.r @@ -1,7 +1,7 @@ library(GOsummaries) -load_all("GOsummaries") +load_all(package("GOsummaries")) -setwd("/Users/Kolde/Raivo/Projects/GOsummaries/GOsummaries/visual_test/vtest/") +setwd("/Users/kolde/Raivo/Projects/GOsummaries/GOsummaries/visual_test/vtest/") dirname = date() system(sprintf("mkdir '%s'", dirname))