diff --git a/DESCRIPTION b/DESCRIPTION index 1cdc90c3..c46c115b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: GeneTonic Title: Enjoy Analyzing And Integrating The Results From Differential Expression Analysis And Functional Enrichment Analysis -Version: 2.9.0 -Date: 2024-03-24 +Version: 2.99.0 +Date: 2024-09-22 Authors@R: c( person( @@ -51,6 +51,7 @@ Imports: igraph, matrixStats, methods, + mosdef (>= 1.1.0), plotly, RColorBrewer, rintrojs, @@ -84,7 +85,7 @@ Encoding: UTF-8 VignetteBuilder: knitr URL: https://github.com/federicomarini/GeneTonic BugReports: https://github.com/federicomarini/GeneTonic/issues -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 Roxygen: list(markdown = TRUE) biocViews: GUI, GeneExpression, Software, Transcription, Transcriptomics, Visualization, diff --git a/NAMESPACE b/NAMESPACE index b35c7443..83d7f660 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -152,6 +152,15 @@ importFrom(igraph,strength) importFrom(igraph,vcount) importFrom(matrixStats,rowSds) importFrom(methods,is) +importFrom(mosdef,create_link_GO) +importFrom(mosdef,create_link_GeneCards) +importFrom(mosdef,create_link_NCBI) +importFrom(mosdef,deresult_to_df) +importFrom(mosdef,gene_plot) +importFrom(mosdef,geneinfo_to_html) +importFrom(mosdef,go_to_html) +importFrom(mosdef,map_to_color) +importFrom(mosdef,styleColorBar_divergent) importFrom(plotly,add_trace) importFrom(plotly,ggplotly) importFrom(plotly,layout) @@ -187,6 +196,7 @@ importFrom(utils,browseURL) importFrom(utils,citation) importFrom(utils,data) importFrom(utils,head) +importFrom(utils,packageDescription) importFrom(utils,read.delim) importFrom(utils,sessionInfo) importFrom(utils,write.table) diff --git a/NEWS.md b/NEWS.md index 5f91cde9..34c4a740 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,15 @@ +# GeneTonic 2.99.0 + +## Other notes + +* The transition to the functions available in the `mosdef` Bioconductor is complete, with the original functions now being deprecated. This applies to `goseqTable()` (now replaced by `mosdef::run_goseq()`), which has now been made faster and more robust in its functionality and in the ways it can be executed +* The gene plot widgets now also use the `gene_plot()` function from `mosdef`, instead of the previous `ggplotCounts()` function - `gene_plot()` is more flexible and has more options to control the behavior of the final plot object +* The `deseqresult2tbl()` and `deseqresult2DEgenes()` are now replaced by the more flexible `mosdef::deresult_to_df()` +* The internally defined `createLinkENS()`, `createLinkGeneSymbol()`, and `createLinkGO()` are now replaced by the equivalent functions in `mosdef` +* The Roxygen-based documentation now supports markdown. No visible changes should appear to the user, as the content should have stayed fairly the same +* Although no visible changes for the end user are expected, the incoming major version bump will reflect the change in the dependency graph, ensuring that this is noticed at least at the version numbering level + + # GeneTonic 2.8.0 ## Other notes diff --git a/R/GeneTonic-extras.R b/R/GeneTonic-extras.R index eb753c93..ec0cc140 100644 --- a/R/GeneTonic-extras.R +++ b/R/GeneTonic-extras.R @@ -27,7 +27,7 @@ #' with a set of unambiguous identifiers (e.g. ENSEMBL ids) and `gene_name`, #' containing e.g. HGNC-based gene symbols. This object can be constructed via #' the `org.eg.XX.db` packages, e.g. with convenience functions such as -#' [pcaExplorer::get_annotation_orgdb()]. +#' [mosdef::get_annotation_orgdb()]. #' #' @return A `GeneTonic`-list object, containing in its named slots the arguments #' specified above: `dds`, `res_de`, `res_enrich`, and `annotation_obj` - the names @@ -193,60 +193,15 @@ describe_gtl <- function(gtl) { #' go_2_html("GO:0043368") go_2_html <- function(go_id, res_enrich = NULL) { - fullinfo <- GOTERM[[go_id]] - if (is.null(fullinfo)) { - return(HTML("Gene Ontology term not found!")) - } - # extracting the field/component values - go_linkbutton <- .link2amigo(GOID(fullinfo)) - go_term <- Term(fullinfo) - go_ontology <- Ontology(fullinfo) - go_definition <- Definition(fullinfo) - go_synonims <- paste0( - unlist( - lapply(Synonym(fullinfo), function(arg) { - paste0(tags$b("Synonym: "), arg, tags$br()) - }) - ), - collapse = "" - ) - go_secondary <- Secondary(fullinfo) - if (!is.null(res_enrich)) { - go_pvalue <- res_enrich[(res_enrich$gs_id == go_id), "gs_pvalue"] - go_zscore <- ifelse( - "z_score" %in% colnames(res_enrich), - format(round(res_enrich[(res_enrich$gs_id == go_id), "z_score"], 2), nsmall = 2), - "NA - not yet computed" - ) - go_aggrscore <- ifelse( - "aggr_score" %in% colnames(res_enrich), - format(round(res_enrich[(res_enrich$gs_id == go_id), "aggr_score"], 2), nsmall = 2), - "NA - not yet computed" - ) - } - # assembling them together - mycontent <- paste0( - tags$b("GO ID: "), go_linkbutton, tags$br(), - tags$b("Term: "), go_term, tags$br(), - ifelse( - !is.null(res_enrich), - paste0(tags$b("p-value: "), go_pvalue, tags$br(), - tags$b("Z-score: "), go_zscore, tags$br(), - tags$b("Aggregated score: "), go_aggrscore, tags$br(), - collapse = "" - ), - "" - ), - tags$b("Ontology: "), go_ontology, tags$br(), tags$br(), - tags$b("Definition: "), go_definition, tags$br(), - go_synonims, - ifelse( - length(go_secondary) > 0, - paste0(tags$b("Secondary: "), go_secondary, collapse = ""), - "" - ) - ) - return(HTML(mycontent)) + .Deprecated(old = "go_2_html", new = "mosdef::go_to_html", + msg = paste0( + "Please use `mosdef::go_to_html()` in replacement of the `go_2_html()` function, ", + "originally located in the GeneTonic package. \nCheck the manual page for ", + "`?mosdef::go_to_html()` to see the details on how to use it")) + + mycontent <- mosdef::go_to_html(go_id = go_id, + res_enrich = res_enrich) + return(mycontent) } #' Link to the AmiGO database @@ -256,12 +211,13 @@ go_2_html <- function(go_id, #' @return HTML for an action button #' @noRd .link2amigo <- function(val) { - sprintf( - '%s', - val, - .actionbutton_biocstyle, - val - ) + .Deprecated(old = ".link2amigo", new = "mosdef::create_link_GO", + msg = paste0( + "Please use `mosdef::create_link_GO()` in replacement of the `.link2amigo()` function, ", + "originally located in the GeneTonic package. \nCheck the manual page for ", + "`?mosdef::create_link_GO()` to see the details on how to use it")) + + mosdef::create_link_GO(val = val) } #' Information on a gene @@ -287,41 +243,16 @@ go_2_html <- function(go_id, #' geneinfo_2_html("Pf4") geneinfo_2_html <- function(gene_id, res_de = NULL) { - gene_ncbi_button <- .link2ncbi(gene_id) - gene_genecards_button <- .link2genecards(gene_id) - gene_gtex_button <- .link2gtex(gene_id) - - if (!is.null(res_de)) { - gid <- match(gene_id, res_de$SYMBOL) - if (is.na(gid)) { - message( - "Could not find the specified gene (`", gene_id, - "`) in the `res_de` object. \n", - "Still, the general HTML content has been generated." - ) - gene_adjpvalue <- tags$em("not found") - gene_logfc <- tags$em("not found") - } else { - gene_adjpvalue <- format(res_de[gid, "padj"]) - gene_logfc <- format(round(res_de[gid, "log2FoldChange"], 2), nsmall = 2) - } - } - - mycontent <- paste0( - tags$b(gene_id), tags$br(), - "Link to the NCBI Gene database: ", gene_ncbi_button, tags$br(), - "Link to the GeneCards database: ", gene_genecards_button, tags$br(), - "Link to the GTEx Portal: ", gene_gtex_button, tags$br(), - ifelse( - !is.null(res_de), - paste0(tags$b("DE p-value (adjusted): "), gene_adjpvalue, tags$br(), - tags$b("DE log2FoldChange: "), gene_logfc, - collapse = "" - ), - "" - ) - ) - return(HTML(mycontent)) + .Deprecated(old = "geneinfo_2_html", new = "mosdef::geneinfo_to_html", + msg = paste0( + "Please use `mosdef::geneinfo_to_html()` in replacement of the `geneinfo_2_html()` function, ", + "originally located in the GeneTonic package. \nCheck the manual page for ", + "`?mosdef::geneinfo_to_html()` to see the details on how to use it")) + + mycontent <- mosdef::geneinfo_to_html(gene_id = gene_id, + res_de = res_de) + + return(mycontent) } #' Link to NCBI database @@ -331,12 +262,13 @@ geneinfo_2_html <- function(gene_id, #' @return HTML for an action button #' @noRd .link2ncbi <- function(val) { - sprintf( - '%s', - val, - .actionbutton_biocstyle, - val - ) + .Deprecated(old = ".link2ncbi", new = "mosdef::create_link_NCBI", + msg = paste0( + "Please use `mosdef::create_link_NCBI()` in replacement of the `.link2ncbi()` function, ", + "originally located in the GeneTonic package. \nCheck the manual page for ", + "`?mosdef::create_link_NCBI()` to see the details on how to use it")) + + mosdef::create_link_NCBI(val = val) } #' Link to the GeneCards database @@ -346,12 +278,13 @@ geneinfo_2_html <- function(gene_id, #' @return HTML for an action button #' @noRd .link2genecards <- function(val) { - sprintf( - '%s', - val, - .actionbutton_biocstyle, - val - ) + .Deprecated(old = ".link2genecards", new = "mosdef::create_link_GeneCards", + msg = paste0( + "Please use `mosdef::create_link_GeneCards()` in replacement of the `.link2genecards()` function, ", + "originally located in the GeneTonic package. \nCheck the manual page for ", + "`?mosdef::create_link_GeneCards()` to see the details on how to use it")) + + mosdef::create_link_GeneCards(val = val) } #' Link to the GTEx Portal @@ -361,12 +294,13 @@ geneinfo_2_html <- function(gene_id, #' @return HTML for an action button #' @noRd .link2gtex <- function(val) { - sprintf( - '%s', - val, - .actionbutton_biocstyle, - val - ) + .Deprecated(old = ".link2gtex", new = "mosdef::create_link_GTEX", + msg = paste0( + "Please use `mosdef::create_link_GTEX()` in replacement of the `.link2gtex()` function, ", + "originally located in the GeneTonic package. \nCheck the manual page for ", + "`?mosdef::create_link_GTEX()` to see the details on how to use it")) + + mosdef::create_link_GTEX(val = val) } @@ -483,7 +417,7 @@ overlap_jaccard_index <- function(x, y) { #' @examples #' #' data(res_de_macrophage, package = "GeneTonic") -#' res_df <- deseqresult2df(res_macrophage_IFNg_vs_naive) +#' res_df <- mosdef::deresult_to_df(res_macrophage_IFNg_vs_naive) #' library("magrittr") #' library("DT") #' DT::datatable(res_df[1:50, ], @@ -529,13 +463,19 @@ overlap_jaccard_index <- function(x, y) { styleColorBar_divergent <- function(data, color_pos, color_neg) { - max_val <- max(abs(data)) - JS( - sprintf( - "isNaN(parseFloat(value)) || value < 0 ? 'linear-gradient(90deg, transparent, transparent ' + (50 + value/%s * 50) + '%%, %s ' + (50 + value/%s * 50) + '%%,%s 50%%,transparent 50%%)': 'linear-gradient(90deg, transparent, transparent 50%%, %s 50%%, %s ' + (50 + value/%s * 50) + '%%, transparent ' + (50 + value/%s * 50) + '%%)'", - max_val, color_pos, max_val, color_pos, color_neg, color_neg, max_val, max_val - ) + .Deprecated(old = "styleColorBar_divergent", new = "mosdef::styleColorBar_divergent", + msg = paste0( + "Please use `mosdef::styleColorBar_divergent()` in replacement of the `styleColorBar_divergent()` function, ", + "originally located in the GeneTonic package. \nCheck the manual page for ", + "`?mosdef::styleColorBar_divergent()` to see the details on how to use it")) + + code_ret <- mosdef::styleColorBar_divergent( + data = data, + color_pos = color_pos, + color_neg = color_neg ) + + return(code_ret) } @@ -571,22 +511,16 @@ styleColorBar_divergent <- function(data, #' )(50) #' plot(b, col = map2color(b, pal2), pch = 20, cex = 3) map2color <- function(x, pal, symmetric = TRUE, limits = NULL) { - if (is.null(limits)) { - limits <- range(x) - } + .Deprecated(old = "map2color", new = "mosdef::map_to_color", + msg = paste0( + "Please use `mosdef::map_to_color()` in replacement of the `map2color()` function, ", + "originally located in the GeneTonic package. \nCheck the manual page for ", + "`?mosdef::map_to_color()` to see the details on how to use it")) - if (symmetric) { - max_val <- max(limits) - limits[1] <- -max_val - limits[2] <- max_val - } - - pal_ret <- pal[findInterval(x, seq(limits[1], - limits[2], - length.out = length(pal) + 1 - ), - all.inside = TRUE - )] + pal_ret <- map_to_color(x = x, + pal = pal, + symmetric = symmetric, + limits = limits) return(pal_ret) } @@ -641,21 +575,18 @@ check_colors <- function(x) { #' @examples #' data(res_de_macrophage, package = "GeneTonic") #' head(res_macrophage_IFNg_vs_naive) -#' res_df <- deseqresult2df(res_macrophage_IFNg_vs_naive) +#' res_df <- mosdef::deresult_to_df(res_macrophage_IFNg_vs_naive) #' head(res_df) deseqresult2df <- function(res_de, FDR = NULL) { - if (!is(res_de, "DESeqResults")) { - stop("Not a DESeqResults object.") - } - res <- as.data.frame(res_de) - res <- cbind(rownames(res), res) - names(res)[1] <- "id" - res$id <- as.character(res$id) - res <- res[order(res$padj), ] - if (!is.null(FDR)) { - res <- res[!(is.na(res$padj)) & res$padj <= FDR, ] - } - res + .Deprecated(old = "deseqresult2df", new = "mosdef::deresult_to_df", + msg = paste0( + "Please use `mosdef::deresult_to_df()` in replacement of the `deseqresult2df()` function, ", + "originally located in the GeneTonic package. \nCheck the manual page for ", + "`?mosdef::deresult_to_df()` to see the details on how to use it")) + + df <- mosdef::deresult_to_df(res_de = res_de, + FDR = FDR) + return(df) } #' Export to sif diff --git a/R/GeneTonic-pkg.R b/R/GeneTonic-pkg.R index cf120df0..37b3c021 100644 --- a/R/GeneTonic-pkg.R +++ b/R/GeneTonic-pkg.R @@ -63,11 +63,30 @@ #' @importFrom tippy with_tippy #' @importFrom tools file_ext file_path_sans_ext #' @importFrom utils read.delim sessionInfo browseURL citation data write.table -#' head +#' head packageDescription #' @importFrom visNetwork renderVisNetwork visExport visIgraph visNetworkOutput #' visOptions #' @importFrom viridis viridis +#' @importFrom mosdef deresult_to_df gene_plot geneinfo_to_html go_to_html +#' map_to_color styleColorBar_divergent create_link_GO create_link_NCBI +#' create_link_GeneCards create_link_GO #' #' @name GeneTonic-pkg #' @keywords internal "_PACKAGE" + +.onAttach <- function(libname, pkgname) { + pkgVersion <- packageDescription("GeneTonic", fields = "Version") + msg <- paste0("Welcome to GeneTonic v", pkgVersion, "\n\n") + citation <- paste0( + "If you use GeneTonic in your work, please cite:\n\n", + " GeneTonic: an R/Bioconductor package for streamlining the interpretation of RNA-seq data\n", + " Federico Marini, Annekathrin Ludt, Jan Linke, Konstantin Strauch\n", + " BMC Bioinformatics, 2021 - https://doi.org/10.1186/s12859-021-04461-5\n", + "and/or (if adopting the series of protocols as a whole)\n", + " Interactive and Reproducible Workflows for Exploring and Modeling RNA-seq Data with pcaExplorer, ideal, and GeneTonic\n", + " Annekathrin Ludt, Arsenij Ustjanzew, Harald Binder, Konstantin Strauch, Federico Marini\n", + " Current Protocols, 2022 - https://doi.org/10.1002/cpz1.411\n" + ) + packageStartupMessage(paste0(msg, citation)) +} diff --git a/R/GeneTonic.R b/R/GeneTonic.R index a5663ce3..097637db 100644 --- a/R/GeneTonic.R +++ b/R/GeneTonic.R @@ -22,7 +22,7 @@ #' with a set of unambiguous identifiers (e.g. ENSEMBL ids) and `gene_name`, #' containing e.g. HGNC-based gene symbols. This object can be constructed via #' the `org.eg.XX.db` packages, e.g. with convenience functions such as -#' [pcaExplorer::get_annotation_orgdb()]. +#' [mosdef::get_annotation_orgdb()]. #' @param gtl A `GeneTonic`-list object, containing in its slots the arguments #' specified above: `dds`, `res_de`, `res_enrich`, and `annotation_obj` - the names #' of the list _must_ be specified following the content they are expecting @@ -666,7 +666,7 @@ GeneTonic <- function(dds = NULL, formatRound(columns = c("log2FoldChange"), digits = 3) %>% formatStyle( "log2FoldChange", - background = styleColorBar_divergent( + background = mosdef::styleColorBar_divergent( as.data.frame(res_de)$log2FoldChange, scales::alpha("navyblue", 0.4), scales::alpha("darkred", 0.4) @@ -726,7 +726,7 @@ GeneTonic <- function(dds = NULL, output$infobox_resde <- renderbs4ValueBox({ bs4ValueBox( value = paste0( - nrow(deseqresult2df(reactive_values$res_de, FDR = input$de_fdr)), + nrow(mosdef::deresult_to_df(reactive_values$res_de, FDR = input$de_fdr)), " DE genes" ), subtitle = "res object", @@ -811,7 +811,7 @@ GeneTonic <- function(dds = NULL, sel_gene_name <- input$gene_genespector corr_gene_id <- reactive_values$annotation_obj$gene_id[ match(sel_gene_name, reactive_values$annotation_obj$gene_name)] - gene_plot(reactive_values$dds, + mosdef::gene_plot(reactive_values$dds, gene = corr_gene_id, intgroup = input$exp_condition, annotation_obj = reactive_values$annotation_obj, @@ -1077,7 +1077,7 @@ GeneTonic <- function(dds = NULL, )) cur_gsid <- reactive_values$res_enrich$gs_id[match(input$ggsnetwork_selected, reactive_values$res_enrich$gs_description)] - go_2_html(cur_gsid, res_enrich) + mosdef::go_to_html(cur_gsid, res_enrich) }) output$ui_ggs_genebox <- renderUI({ @@ -1106,7 +1106,7 @@ GeneTonic <- function(dds = NULL, # if (!input$box_geneset$collapsed) # bs4Dash::updatebs4Card("box_geneset", action = "toggle") - geneinfo_2_html(cur_sel, reactive_values$res_de) + mosdef::geneinfo_to_html(cur_sel, reactive_values$res_de) }) output$ggs_geneplot <- renderPlot({ @@ -1122,7 +1122,7 @@ GeneTonic <- function(dds = NULL, )) cur_geneid <- reactive_values$annotation_obj$gene_id[match(cur_sel, reactive_values$annotation_obj$gene_name)] - gene_plot(reactive_values$dds, + mosdef::gene_plot(reactive_values$dds, gene = cur_geneid, intgroup = input$exp_condition, annotation_obj = reactive_values$annotation_obj, @@ -1325,7 +1325,7 @@ GeneTonic <- function(dds = NULL, # message(cur_gsid) # GOTERM[[cur_gsid]] - go_2_html(cur_gsid, reactive_values$res_enrich) + mosdef::go_to_html(cur_gsid, reactive_values$res_enrich) }) output$emap_sigheatplot <- renderPlot({ diff --git a/R/check_inputs.R b/R/check_inputs.R index 0a99615c..b14abf89 100644 --- a/R/check_inputs.R +++ b/R/check_inputs.R @@ -124,7 +124,7 @@ checkup_GeneTonic <- function(dds, stop( "The provided `annotation_obj` object does not respect the format required to use in GeneTonic\n", "e.g. all required column names have to be present.\n", - "You can use e.g. `pcaExplorer::get_annotation_orgdb()` for this purpose.\n", + "You can use e.g. `mosdef::get_annotation_orgdb()` for this purpose.\n", "Required columns: ", paste(colnames_annotation_obj, collapse = ", ") ) } diff --git a/R/deprecated.R b/R/deprecated.R new file mode 100644 index 00000000..37d4b4b0 --- /dev/null +++ b/R/deprecated.R @@ -0,0 +1,56 @@ +#' Deprecated functions in GeneTonic +#' +#' Functions that are on their way to the function afterlife. +#' Their successors are also listed. +#' +#' The successors of these functions are likely coming after the rework that +#' led to the creation of the `mosdef` package. See more into its +#' documentation for more details. +#' +#' @param ... Ignored arguments. +#' +#' @return All functions throw a warning, with a deprecation message pointing +#' towards its descendent (if available). +#' +#' @name deprecated +#' +#' @section Transitioning to the mosdef framework: +#' +#' - [deseqresult2df()], now replaced by the more consistent +#' [mosdef::deresult_to_df()]. The only change in its functionality concerns +#' the parameter names +#' - [gene_plot()] has now been moved to [mosdef::gene_plot()], where it +#' generalizes with respect to the container of the DE workflow object. In a +#' similar fashion, [get_expression_values()] is replaced by +#' [mosdef::get_expr_values()]. Both functions lose the `gtl` parameter, which +#' was anyways not really exploited throughout the different calls in the +#' package +#' - [go_2_html()] and [geneinfo_2_html()] have been replaced by the more +#' information-rich (and flexible) [mosdef::go_to_html()] and +#' [mosdef::geneinfo_to_html()], respectively. No change is expected for the +#' end user +#' - [map2color()] and [styleColorBar_divergent()] are now moved to the +#' [mosdef::map_to_color()] and [mosdef::styleColorBar_divergent()], again with +#' no visible changes for the end user +#' - The internally defined functions `.link2amigo()`, `.link2ncbi()`, +#' `.link2genecards()` and `.link2gtex()` are now replaced by the equivalent +#' functions in `mosdef`: +#' [mosdef::create_link_GO()], [mosdef::create_link_NCBI()], +#' [mosdef::create_link_GeneCards()] and [mosdef::create_link_GO()]. +#' Notably, the `mosdef` package expanded on the +#' concept of automatically generated buttons, taking this to the extreme of +#' efficiency with the [mosdef::buttonifier()] function +#' +#' @author Federico Marini +#' +#' @examples +#' # try(deseqresult2df()) +#' +NULL + + +## #' @export +## #' @rdname defunct +## trendVar <- function(...) { +## .Defunct("fitTrendVar") +## } diff --git a/R/enrichment_map.R b/R/enrichment_map.R index 717c710f..39a06d34 100644 --- a/R/enrichment_map.R +++ b/R/enrichment_map.R @@ -171,11 +171,11 @@ enrichment_map <- function(res_enrich, colorRampPalette(RColorBrewer::brewer.pal(name = "YlOrRd", 9))(50), 1 )) - V(emg)$color.background <- map2color(col_var, mypal, symmetric = FALSE, + V(emg)$color.background <- mosdef::map_to_color(col_var, mypal, symmetric = FALSE, limits = range(na.omit(col_var))) - V(emg)$color.highlight <- map2color(col_var, mypal_select, symmetric = FALSE, + V(emg)$color.highlight <- mosdef::map_to_color(col_var, mypal_select, symmetric = FALSE, limits = range(na.omit(col_var))) - V(emg)$color.hover <- map2color(col_var, mypal_hover, symmetric = FALSE, + V(emg)$color.hover <- mosdef::map_to_color(col_var, mypal_hover, symmetric = FALSE, limits = range(na.omit(col_var))) V(emg)$color.background[is.na(V(emg)$color.background)] <- "lightgrey" @@ -195,11 +195,11 @@ enrichment_map <- function(res_enrich, colorRampPalette(RColorBrewer::brewer.pal(name = "Oranges", 9))(50), 1 )) - V(emg)$color.background <- map2color(col_var, mypal, symmetric = FALSE, + V(emg)$color.background <- mosdef::map_to_color(col_var, mypal, symmetric = FALSE, limits = range(na.omit(col_var))) - V(emg)$color.highlight <- map2color(col_var, mypal_select, symmetric = FALSE, + V(emg)$color.highlight <- mosdef::map_to_color(col_var, mypal_select, symmetric = FALSE, limits = range(na.omit(col_var))) - V(emg)$color.hover <- map2color(col_var, mypal_hover, symmetric = FALSE, + V(emg)$color.hover <- mosdef::map_to_color(col_var, mypal_hover, symmetric = FALSE, limits = range(na.omit(col_var))) V(emg)$color.background[is.na(V(emg)$color.background)] <- "lightgrey" V(emg)$color.highlight[is.na(V(emg)$color.highlight)] <- "lightgrey" @@ -217,11 +217,11 @@ enrichment_map <- function(res_enrich, colorRampPalette(RColorBrewer::brewer.pal(name = "RdYlBu", 11))(50), 1 )) - V(emg)$color.background <- map2color(col_var, mypal, symmetric = TRUE, + V(emg)$color.background <- mosdef::map_to_color(col_var, mypal, symmetric = TRUE, limits = range(na.omit(col_var))) - V(emg)$color.highlight <- map2color(col_var, mypal_select, symmetric = TRUE, + V(emg)$color.highlight <- mosdef::map_to_color(col_var, mypal_select, symmetric = TRUE, limits = range(na.omit(col_var))) - V(emg)$color.hover <- map2color(col_var, mypal_hover, symmetric = TRUE, + V(emg)$color.hover <- mosdef::map_to_color(col_var, mypal_hover, symmetric = TRUE, limits = range(na.omit(col_var))) V(emg)$color.background[is.na(V(emg)$color.background)] <- "lightgrey" diff --git a/R/gene_plot.R b/R/gene_plot.R index 93f7d306..e9b57b92 100644 --- a/R/gene_plot.R +++ b/R/gene_plot.R @@ -82,133 +82,24 @@ gene_plot <- function(dds, plot_type = "auto", return_data = FALSE, gtl = NULL) { - plot_type <- match.arg( - plot_type, - c("auto", "jitteronly", "boxplot", "violin", "sina") - ) - - if (!is.null(gtl)) { - checkup_gtl(gtl) - dds <- gtl$dds - res_de <- gtl$res_de - res_enrich <- gtl$res_enrich - annotation_obj <- gtl$annotation_obj - } + .Deprecated(old = "gene_plot", new = "mosdef::gene_plot", + msg = paste0( + "Please use `mosdef::gene_plot()` in replacement of the `gene_plot()` function, ", + "originally located in the GeneTonic package. \nCheck the manual page for ", + "`?mosdef::gene_plot()` to see the details on how to use it")) + + p <- mosdef::gene_plot(de_container = dds, + gene = gene, + intgroup = intgroup, + assay = assay, + annotation_obj = annotation_obj, + normalized = normalized, + transform = transform, + labels_display = labels_display, + labels_repel = labels_repel, + plot_type = plot_type, + return_data = return_data) - if (!intgroup %in% colnames(colData(dds))) { - stop("`intgroup` not found in the colData slot of the dds object", - "\nPlease specify one of the following: \n", - paste0(colnames(colData(dds)), collapse = ", ") - ) - } - - df <- get_expression_values( - dds = dds, - gene = gene, - intgroup = intgroup, - assay = assay, - normalized = normalized - ) - - df$sample_id <- rownames(df) - if (!is.null(annotation_obj)) { - genesymbol <- annotation_obj$gene_name[match(gene, annotation_obj$gene_id)] - } else { - genesymbol <- "" - } - - onlyfactors <- df[, match(intgroup, colnames(df))] - df$plotby <- interaction(onlyfactors) - - min_by_groups <- min(table(df$plotby)) - # depending on this, use boxplots/nothing/violins/sina - - if (return_data) { - return(df) - } - - p <- ggplot(df, aes(x = .data$plotby, - y = .data$exp_value, - col = .data$plotby)) + - scale_x_discrete(name = "") + - scale_color_discrete(name = "Experimental\ngroup") + - theme_bw() - - # for connected handling of jittered points AND labels - jit_pos <- position_jitter(width = 0.2, height = 0, seed = 42) - - # somewhat following the recommendations here - # https://www.embopress.org/doi/full/10.15252/embj.201694659 - if (plot_type == "jitteronly" || (plot_type == "auto" & min_by_groups <= 3)) { - p <- p + - geom_point(aes(x = .data$plotby, - y = .data$exp_value), - position = jit_pos - ) - # do nothing - or add a line for the median? - } else if (plot_type == "boxplot" || (plot_type == "auto" & (min_by_groups > 3 & min_by_groups < 10))) { - p <- p + - geom_boxplot(outlier.shape = NA) + - geom_point(aes(x = .data$plotby, - y = .data$exp_value), position = jit_pos) - } else if (plot_type == "violin" || (plot_type == "auto" & (min_by_groups >= 11 & min_by_groups < 40))) { - p <- p + - geom_violin() + - geom_point(aes(x = .data$plotby, - y = .data$exp_value), position = jit_pos) + - stat_summary( - fun = median, fun.min = median, fun.max = median, - geom = "crossbar", width = 0.3 - ) - } else if (plot_type == "sina" || (plot_type == "auto" & (min_by_groups >= 40))) { - p <- p + - ggforce::geom_sina() + - stat_summary( - fun = median, fun.min = median, fun.max = median, - geom = "crossbar", width = 0.3 - ) - } - - # handling the labels - if (labels_display) { - if (labels_repel) { - p <- p + ggrepel::geom_text_repel(aes(label = .data$sample_id), - min.segment.length = 0, - position = jit_pos - ) - } - else { - p <- p + geom_text(aes(label = .data$sample_id), - hjust = -0.1, vjust = 0.1, - position = jit_pos - ) - } - } - - y_label <- if (assay == "counts" & normalized) { - "Normalized counts" - } else if (assay == "counts" & !normalized) { - "Counts" - } else if (assay == "abundance") { - "TPM - Transcripts Per Million" - } else { - assay - } - - # handling y axis transformation - if (transform) { - p <- p + scale_y_log10(name = paste0(y_label, " (log10 scale)")) - } else { - p <- p + scale_y_continuous(name = y_label) - } - - # handling the displayed names and ids - if (!is.null(annotation_obj)) { - p <- p + labs(title = paste0(genesymbol, " - ", gene)) - } else { - p <- p + labs(title = paste0(gene)) - } - return(p) } @@ -257,33 +148,20 @@ get_expression_values <- function(dds, assay = "counts", normalized = TRUE, gtl = NULL) { - if (!is.null(gtl)) { - checkup_gtl(gtl) - dds <- gtl$dds - } - if (!(assay %in% names(assays(dds)))) { - stop( - "Please specify a name of one of the existing assays: \n", - paste(names(assays(dds)), collapse = ", ") - ) - } - - # checking the normalization factors are in - if (is.null(sizeFactors(dds)) & is.null(normalizationFactors(dds))) { - dds <- estimateSizeFactors(dds) - } - - if (assay == "counts") { - exp_vec <- counts(dds, normalized = normalized)[gene, ] - } else { - exp_vec <- assays(dds)[[assay]][gene, ] - } - - exp_df <- data.frame( - exp_value = exp_vec, - colData(dds)[intgroup] + .Deprecated(old = "get_expression_values", new = "mosdef::get_expr_values", + msg = paste0( + "Please use `mosdef::get_expr_values()` in replacement of the `get_expression_values()` function, ", + "originally located in the GeneTonic package. \nCheck the manual page for ", + "`?mosdef::get_expr_values()` to see the details on how to use it")) + + expr_values <- mosdef::get_expr_values( + de_container = dds, + gene = gene, + intgroup = intgroup, + assay = assay, + normalized = normalized ) - - return(exp_df) + + return(expr_values) } diff --git a/R/ggs_graph.R b/R/ggs_graph.R index 18cc86ed..f2fe9ca4 100644 --- a/R/ggs_graph.R +++ b/R/ggs_graph.R @@ -188,7 +188,7 @@ ggs_graph <- function(res_enrich, )) } - V(g)$color[nodeIDs_genes] <- map2color(fcs_genes, mypal, limits = c(-4, 4)) + V(g)$color[nodeIDs_genes] <- mosdef::map_to_color(fcs_genes, mypal, limits = c(-4, 4)) V(g)$color[nodeIDs_gs] <- geneset_graph_color # title for tooltips @@ -437,11 +437,11 @@ ggs_backbone <- function(res_enrich, colorRampPalette(RColorBrewer::brewer.pal(name = "RdYlBu", 11))(50), 1 )) - V(bbgraph)$color.background <- map2color(col_var, mypal, symmetric = TRUE, + V(bbgraph)$color.background <- mosdef::map_to_color(col_var, mypal, symmetric = TRUE, limits = range(na.omit(col_var))) - V(bbgraph)$color.highlight <- map2color(col_var, mypal_select, symmetric = TRUE, + V(bbgraph)$color.highlight <- mosdef::map_to_color(col_var, mypal_select, symmetric = TRUE, limits = range(na.omit(col_var))) - V(bbgraph)$color.hover <- map2color(col_var, mypal_hover, symmetric = TRUE, + V(bbgraph)$color.hover <- mosdef::map_to_color(col_var, mypal_hover, symmetric = TRUE, limits = range(na.omit(col_var))) V(bbgraph)$color.background[is.na(V(bbgraph)$color.background)] <- "lightgrey" @@ -468,11 +468,11 @@ ggs_backbone <- function(res_enrich, colorRampPalette(RColorBrewer::brewer.pal(name = "RdYlBu", 11))(50), 1 )) - V(bbgraph)$color.background <- map2color(col_var, mypal, + V(bbgraph)$color.background <- mosdef::map_to_color(col_var, mypal, limits = range(na.omit(col_var))) - V(bbgraph)$color.highlight <- map2color(col_var, mypal_select, + V(bbgraph)$color.highlight <- mosdef::map_to_color(col_var, mypal_select, limits = range(na.omit(col_var))) - V(bbgraph)$color.hover <- map2color(col_var, mypal_hover, + V(bbgraph)$color.hover <- mosdef::map_to_color(col_var, mypal_hover, limits = range(na.omit(col_var))) V(bbgraph)$color.background[is.na(V(bbgraph)$color.background)] <- "lightgrey" diff --git a/R/gs_dendro.R b/R/gs_dendro.R index 1cb28939..5337c37d 100644 --- a/R/gs_dendro.R +++ b/R/gs_dendro.R @@ -147,7 +147,7 @@ gs_dendro <- function(res_enrich, mypal <- (scales::alpha( colorRampPalette(RColorBrewer::brewer.pal(name = "YlOrRd", 9))(50), 0.8 )) - leaves_col <- map2color(col_var, mypal, symmetric = FALSE, + leaves_col <- mosdef::map_to_color(col_var, mypal, symmetric = FALSE, limits = range(na.omit(col_var)))[dend_idx] } else { @@ -157,7 +157,7 @@ gs_dendro <- function(res_enrich, mypal <- (scales::alpha( colorRampPalette(RColorBrewer::brewer.pal(name = "Oranges", 9))(50), 0.8 )) - leaves_col <- map2color(col_var, mypal, symmetric = FALSE, + leaves_col <- mosdef::map_to_color(col_var, mypal, symmetric = FALSE, limits = range(na.omit(col_var)))[dend_idx] } else { @@ -165,7 +165,7 @@ gs_dendro <- function(res_enrich, mypal <- rev(scales::alpha( colorRampPalette(RColorBrewer::brewer.pal(name = "RdYlBu", 11))(50), 0.8 )) - leaves_col <- map2color(col_var, mypal, symmetric = TRUE, + leaves_col <- mosdef::map_to_color(col_var, mypal, symmetric = TRUE, limits = range(na.omit(col_var)))[dend_idx] } diff --git a/R/gs_heatmap.R b/R/gs_heatmap.R index 6e9d5831..b0025c4b 100644 --- a/R/gs_heatmap.R +++ b/R/gs_heatmap.R @@ -170,7 +170,7 @@ gs_heatmap <- function(se, } if (de_only) { - de_res <- deseqresult2df(res_de, FDR) + de_res <- mosdef::deresult_to_df(res_de, FDR) de_genes <- de_res$id de_to_keep <- rownames(mydata_sig) %in% de_genes mydata_sig <- mydata_sig[de_to_keep, , drop = FALSE] diff --git a/R/gs_shaker.R b/R/gs_shaker.R index ff6ea3e1..8a8565f3 100644 --- a/R/gs_shaker.R +++ b/R/gs_shaker.R @@ -219,7 +219,7 @@ shake_topGOtableResult <- function(obj, p_value_column = "p.value_elim") { if (!all(c("GO.ID", "Term", "Annotated", "Significant", "Expected", "p.value_classic") %in% colnames(obj))) { - stop("The provided object must be of in the format specified by the `pcaExplorer::topGOtable` function") + stop("The provided object must be of in the format specified by the `pcaExplorer::topGOtable` function or the `mosdef::run_topGO` function") } if (!p_value_column %in% colnames(obj)) { @@ -232,7 +232,7 @@ shake_topGOtableResult <- function(obj, if (!"genes" %in% colnames(obj)) { stop( "The column `genes` is not present in the provided object and is required for properly running GeneTonic.", - "\nMaybe you did set `addGeneToTerms` to FALSE in the call to `pcaExplorer::topGOtable`?" + "\nMaybe you did set `addGeneToTerms` to FALSE in the call to `pcaExplorer::topGOtable` or to `mosdef::run_topGO`?" ) } @@ -350,7 +350,7 @@ shake_davidResult <- function(david_output_file) { #' # "KEGG_2019_Human", #' # "Reactome_2016", #' # "WikiPathways_2019_Human") -#' # degenes <- (deseqresult2df(res_macrophage_IFNg_vs_naive, FDR = 0.01)$SYMBOL) +#' # degenes <- (mosdef::deresult_to_df(res_macrophage_IFNg_vs_naive, FDR = 0.01)$SYMBOL) #' # if called directly within R... #' # enrichr_output_macrophage <- enrichr(degenes, dbs) #' # or alternatively, if downloaded from the website in tabular format @@ -431,7 +431,7 @@ shake_enrichrResult <- function(enrichr_output_file, #' @family shakers #' #' @examples -#' # degenes <- (deseqresult2df(res_macrophage_IFNg_vs_naive, FDR = 0.01)$SYMBOL) +#' # degenes <- (mosdef::deresult_to_df(res_macrophage_IFNg_vs_naive, FDR = 0.01)$SYMBOL) #' # if called directly withín R... #' # enrichr_output_macrophage <- enrichr(degenes, dbs) #' # or alternatively, if downloaded from the website in tabular format diff --git a/inst/extdata/GeneTonic101.md b/inst/extdata/GeneTonic101.md index a5fc49c2..01037911 100644 --- a/inst/extdata/GeneTonic101.md +++ b/inst/extdata/GeneTonic101.md @@ -12,7 +12,7 @@ Four main ingredients are required: 2. `res_de`: a `DESeqResults` object, the results of Differential Expression analysis, computed on the `dds` object above. This extends the `S4Vectors::DataFrame` class. -3. `res_enrich`: a `data.frame`, containing the results of the enrichment analysis, generally computed on the basis of the DE results and the expression matrix. The `GeneTonic` main functions require some specific columns to be present, specified in the package documentation. Common formats (e.g. from `pcaExplorer::topGOtable` or from `ClusterProfiler`) are supported with conversion functions. +3. `res_enrich`: a `data.frame`, containing the results of the enrichment analysis, generally computed on the basis of the DE results and the expression matrix. The `GeneTonic` main functions require some specific columns to be present, specified in the package documentation. Common formats (e.g. from `pcaExplorer::topGOtable`/`mosdef::run_topGO` or from `ClusterProfiler`) are supported with conversion functions. 4. `annotation_obj`: the annotation `data.frame`, composed at least of two columns, `gene_id`, with a set of unambiguous identifiers (e.g. ENSEMBL ids) corresponding to the row names of the `dds` object, and `gene_name`, containing e.g. HGNC-based gene symbols. diff --git a/inst/extdata/cocktail_recipe.Rmd b/inst/extdata/cocktail_recipe.Rmd index 372af46f..961c3d46 100644 --- a/inst/extdata/cocktail_recipe.Rmd +++ b/inst/extdata/cocktail_recipe.Rmd @@ -166,7 +166,7 @@ For each of them, a plot for the expression values is displayed in the content t ```{r} lapply(selected_genes, function(arg) { - GeneTonic::gene_plot(dds,gene = arg,intgroup = intgroup, + mosdef::gene_plot(dds,gene = arg,intgroup = intgroup, annotation_obj = annotation_obj)}) ``` @@ -205,7 +205,7 @@ for (gs in selected_genesets) { geneset_id = gs, cluster_columns = TRUE) - cat(go_2_html(gs, res_enrich)) + cat(mosdef::go_to_html(gs, res_enrich)) cat("\n\n") } ``` diff --git a/inst/scripts/create_gt_data.R b/inst/scripts/create_gt_data.R index eacfa773..0358c8e4 100644 --- a/inst/scripts/create_gt_data.R +++ b/inst/scripts/create_gt_data.R @@ -29,7 +29,7 @@ res_macrophage_IFNg_vs_naive <- results(dds_macrophage, res_macrophage_IFNg_vs_naive$SYMBOL <- rowData(dds_macrophage)$SYMBOL library("AnnotationDbi") # de_symbols_IFNg_vs_naive <- res_macrophage_IFNg_vs_naive[(!(is.na(res_macrophage_IFNg_vs_naive$padj))) & (res_macrophage_IFNg_vs_naive$padj <= 0.05), "SYMBOL"] -de_symbols_IFNg_vs_naive <- deseqresult2df(res_macrophage_IFNg_vs_naive, FDR = 0.05)$SYMBOL +de_symbols_IFNg_vs_naive <- mosdef::deresult_to_df(res_macrophage_IFNg_vs_naive, FDR = 0.05)$SYMBOL bg_ids <- rowData(dds_macrophage)$SYMBOL[rowSums(counts(dds_macrophage)) > 0] save(res_macrophage_IFNg_vs_naive, file = "data/res_de_macrophage.RData", compress = "xz") @@ -53,7 +53,7 @@ topgoDE_macrophage_IFNg_vs_naive <- # gostres object ---------------------------------------------------------- library("gprofiler2") -degenes <- deseqresult2df(res_macrophage_IFNg_vs_naive, FDR = 0.01)$SYMBOL +degenes <- mosdef::deresult_to_df(res_macrophage_IFNg_vs_naive, FDR = 0.01)$SYMBOL gostres_macrophage <- gost( query = degenes, organism = "hsapiens", @@ -101,7 +101,7 @@ dbs <- c("GO_Molecular_Function_2018", "KEGG_2019_Human", "Reactome_2016", "WikiPathways_2019_Human") -degenes <- (deseqresult2df(res_macrophage_IFNg_vs_naive, FDR = 0.01)$SYMBOL) +degenes <- (mosdef::deresult_to_df(res_macrophage_IFNg_vs_naive, FDR = 0.01)$SYMBOL) enrichr_output_macrophage <- enrichr(degenes, dbs) save(enrichr_output_macrophage, diff --git a/man/GeneTonic.Rd b/man/GeneTonic.Rd index 90414bd9..a8fc4d63 100644 --- a/man/GeneTonic.Rd +++ b/man/GeneTonic.Rd @@ -40,7 +40,7 @@ formatting helpers with a set of unambiguous identifiers (e.g. ENSEMBL ids) and \code{gene_name}, containing e.g. HGNC-based gene symbols. This object can be constructed via the \code{org.eg.XX.db} packages, e.g. with convenience functions such as -\code{\link[pcaExplorer:get_annotation_orgdb]{pcaExplorer::get_annotation_orgdb()}}.} +\code{\link[mosdef:get_annotation_orgdb]{mosdef::get_annotation_orgdb()}}.} \item{gtl}{A \code{GeneTonic}-list object, containing in its slots the arguments specified above: \code{dds}, \code{res_de}, \code{res_enrich}, and \code{annotation_obj} - the names diff --git a/man/GeneTonicList.Rd b/man/GeneTonicList.Rd index 185d836f..2cb84a1a 100644 --- a/man/GeneTonicList.Rd +++ b/man/GeneTonicList.Rd @@ -35,7 +35,7 @@ formatting helpers with a set of unambiguous identifiers (e.g. ENSEMBL ids) and \code{gene_name}, containing e.g. HGNC-based gene symbols. This object can be constructed via the \code{org.eg.XX.db} packages, e.g. with convenience functions such as -\code{\link[pcaExplorer:get_annotation_orgdb]{pcaExplorer::get_annotation_orgdb()}}.} +\code{\link[mosdef:get_annotation_orgdb]{mosdef::get_annotation_orgdb()}}.} } \value{ A \code{GeneTonic}-list object, containing in its named slots the arguments diff --git a/man/deprecated.Rd b/man/deprecated.Rd new file mode 100644 index 00000000..6466656c --- /dev/null +++ b/man/deprecated.Rd @@ -0,0 +1,58 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/deprecated.R +\name{deprecated} +\alias{deprecated} +\title{Deprecated functions in GeneTonic} +\arguments{ +\item{...}{Ignored arguments.} +} +\value{ +All functions throw a warning, with a deprecation message pointing +towards its descendent (if available). +} +\description{ +Functions that are on their way to the function afterlife. +Their successors are also listed. +} +\details{ +The successors of these functions are likely coming after the rework that +led to the creation of the \code{mosdef} package. See more into its +documentation for more details. +} +\section{Transitioning to the mosdef framework}{ + +\itemize{ +\item \code{\link[=deseqresult2df]{deseqresult2df()}}, now replaced by the more consistent +\code{\link[mosdef:deresult_to_df]{mosdef::deresult_to_df()}}. The only change in its functionality concerns +the parameter names +\item \code{\link[=gene_plot]{gene_plot()}} has now been moved to \code{\link[mosdef:gene_plot]{mosdef::gene_plot()}}, where it +generalizes with respect to the container of the DE workflow object. In a +similar fashion, \code{\link[=get_expression_values]{get_expression_values()}} is replaced by +\code{\link[mosdef:get_expr_values]{mosdef::get_expr_values()}}. Both functions lose the \code{gtl} parameter, which +was anyways not really exploited throughout the different calls in the +package +\item \code{\link[=go_2_html]{go_2_html()}} and \code{\link[=geneinfo_2_html]{geneinfo_2_html()}} have been replaced by the more +information-rich (and flexible) \code{\link[mosdef:go_to_html]{mosdef::go_to_html()}} and +\code{\link[mosdef:geneinfo_to_html]{mosdef::geneinfo_to_html()}}, respectively. No change is expected for the +end user +\item \code{\link[=map2color]{map2color()}} and \code{\link[=styleColorBar_divergent]{styleColorBar_divergent()}} are now moved to the +\code{\link[mosdef:map_to_color]{mosdef::map_to_color()}} and \code{\link[mosdef:styleColorBar_divergent]{mosdef::styleColorBar_divergent()}}, again with +no visible changes for the end user +\item The internally defined functions \code{.link2amigo()}, \code{.link2ncbi()}, +\code{.link2genecards()} and \code{.link2gtex()} are now replaced by the equivalent +functions in \code{mosdef}: +\code{\link[mosdef:create_link_GO]{mosdef::create_link_GO()}}, \code{\link[mosdef:create_link_NCBI]{mosdef::create_link_NCBI()}}, +\code{\link[mosdef:create_link_GeneCards]{mosdef::create_link_GeneCards()}} and \code{\link[mosdef:create_link_GO]{mosdef::create_link_GO()}}. +Notably, the \code{mosdef} package expanded on the +concept of automatically generated buttons, taking this to the extreme of +efficiency with the \code{\link[mosdef:buttonifier]{mosdef::buttonifier()}} function +} +} + +\examples{ +# try(deseqresult2df()) + +} +\author{ +Federico Marini +} diff --git a/man/deseqresult2df.Rd b/man/deseqresult2df.Rd index 043e1c78..5d4f72ff 100644 --- a/man/deseqresult2df.Rd +++ b/man/deseqresult2df.Rd @@ -24,6 +24,6 @@ Generate a tidy table with the results of \code{DESeq2} \examples{ data(res_de_macrophage, package = "GeneTonic") head(res_macrophage_IFNg_vs_naive) -res_df <- deseqresult2df(res_macrophage_IFNg_vs_naive) +res_df <- mosdef::deresult_to_df(res_macrophage_IFNg_vs_naive) head(res_df) } diff --git a/man/shake_enrichrResult.Rd b/man/shake_enrichrResult.Rd index 859edad7..a11d4918 100644 --- a/man/shake_enrichrResult.Rd +++ b/man/shake_enrichrResult.Rd @@ -28,7 +28,7 @@ Convert the output of Enrichr for straightforward use in \code{\link[=GeneTonic] # "KEGG_2019_Human", # "Reactome_2016", # "WikiPathways_2019_Human") -# degenes <- (deseqresult2df(res_macrophage_IFNg_vs_naive, FDR = 0.01)$SYMBOL) +# degenes <- (mosdef::deresult_to_df(res_macrophage_IFNg_vs_naive, FDR = 0.01)$SYMBOL) # if called directly within R... # enrichr_output_macrophage <- enrichr(degenes, dbs) # or alternatively, if downloaded from the website in tabular format diff --git a/man/shake_gprofilerResult.Rd b/man/shake_gprofilerResult.Rd index 4371b527..08093f8b 100644 --- a/man/shake_gprofilerResult.Rd +++ b/man/shake_gprofilerResult.Rd @@ -20,7 +20,7 @@ A \code{data.frame} compatible for use in \code{\link[=GeneTonic]{GeneTonic()}} Convert the output of g:Profiler for straightforward use in \code{\link[=GeneTonic]{GeneTonic()}} } \examples{ -# degenes <- (deseqresult2df(res_macrophage_IFNg_vs_naive, FDR = 0.01)$SYMBOL) +# degenes <- (mosdef::deresult_to_df(res_macrophage_IFNg_vs_naive, FDR = 0.01)$SYMBOL) # if called directly withín R... # enrichr_output_macrophage <- enrichr(degenes, dbs) # or alternatively, if downloaded from the website in tabular format diff --git a/man/styleColorBar_divergent.Rd b/man/styleColorBar_divergent.Rd index fdb4f81e..516c9513 100644 --- a/man/styleColorBar_divergent.Rd +++ b/man/styleColorBar_divergent.Rd @@ -40,7 +40,7 @@ https://stackoverflow.com/questions/33521828/stylecolorbar-center-and-shift-left \examples{ data(res_de_macrophage, package = "GeneTonic") -res_df <- deseqresult2df(res_macrophage_IFNg_vs_naive) +res_df <- mosdef::deresult_to_df(res_macrophage_IFNg_vs_naive) library("magrittr") library("DT") DT::datatable(res_df[1:50, ], diff --git a/tests/testthat/test-GeneTonic_extras.R b/tests/testthat/test-GeneTonic_extras.R index 8bc85fd5..83a7e6ef 100644 --- a/tests/testthat/test-GeneTonic_extras.R +++ b/tests/testthat/test-GeneTonic_extras.R @@ -37,7 +37,7 @@ test_that("JS code for DT is generated", { value = c(-4, -3, -2, -1, 0, 1, 2, 3, 4) ) - bg_jscode <- styleColorBar_divergent( + bg_jscode <- mosdef::styleColorBar_divergent( simplest_df$value, scales::alpha("forestgreen", 0.4), scales::alpha("gold", 0.4) @@ -51,8 +51,8 @@ test_that("map2color works", { colorRampPalette(RColorBrewer::brewer.pal(name = "RdYlBu", 11))(50), 0.4 )) my_vals <- res_macrophage_IFNg_vs_naive$log2FoldChange[1:20] - m2c <- map2color(x = my_vals, pal = mypal, limits = c(-4, 4)) - m2c_nolimits <- map2color(x = my_vals, pal = mypal) + m2c <- mosdef::map_to_color(x = my_vals, pal = mypal, limits = c(-4, 4)) + m2c_nolimits <- mosdef::map_to_color(x = my_vals, pal = mypal) # plot(1:20, col = m2c, pch = 20, cex = 5) expect_length(m2c, 20) @@ -76,11 +76,11 @@ test_that("color check works", { }) test_that("results to data frame conversion works", { - res_df <- deseqresult2df(res_macrophage_IFNg_vs_naive, FDR = 1) - res_df2 <- deseqresult2df(res_macrophage_IFNg_vs_naive, FDR = 0.05) - res_df3 <- deseqresult2df(res_macrophage_IFNg_vs_naive) + res_df <- mosdef::deresult_to_df(res_macrophage_IFNg_vs_naive, FDR = 1) + res_df2 <- mosdef::deresult_to_df(res_macrophage_IFNg_vs_naive, FDR = 0.05) + res_df3 <- mosdef::deresult_to_df(res_macrophage_IFNg_vs_naive) expect_is(res_df, "data.frame") - expect_error(deseqresult2df(res_df)) + expect_error(mosdef::deresult_to_df(res_df)) }) test_that("Exporting to sif format works", { @@ -97,30 +97,30 @@ test_that("Exporting to sif format works", { }) test_that("Retrieving info on GO term", { - out <- go_2_html("GO:0032729") + out <- mosdef::go_to_html("GO:0032729") expect_is(out, "character") expect_is(out, "html") - expect_equal(go_2_html("GO:00"), HTML("Gene Ontology term not found!")) + expect_equal(mosdef::go_to_html("GO:00"), HTML("Gene Ontology term not found!")) res_enrich <- get_aggrscores(res_enrich_IFNg_vs_naive, res_de = res_macrophage_IFNg_vs_naive, annotation_obj = anno_df) - out2 <- go_2_html("GO:0032729", res_enrich = res_enrich) + out2 <- mosdef::go_to_html("GO:0032729", res_enrich = res_enrich) expect_is(out2, "character") expect_is(out2, "html") }) test_that("Retrieving info on gene", { - out <- geneinfo_2_html("Xist") + out <- mosdef::geneinfo_to_html("Xist") expect_is(out, "character") expect_is(out, "html") # using a gene name present in the res_de - out2 <- geneinfo_2_html("IRF1", res_de = res_macrophage_IFNg_vs_naive) + out2 <- mosdef::geneinfo_to_html("IRF1", res_de = res_macrophage_IFNg_vs_naive) expect_is(out2, "character") expect_is(out2, "html") # using a gene name which is not in the res_de expect_message( - out3 <- geneinfo_2_html("Irf1", res_de = res_macrophage_IFNg_vs_naive) + out3 <- mosdef::geneinfo_to_html("Irf1", res_de = res_macrophage_IFNg_vs_naive) ) expect_is(out3, "character") expect_is(out3, "html") @@ -128,17 +128,17 @@ test_that("Retrieving info on gene", { }) test_that("Linking to AmiGO database", { - out <- .link2amigo("GO:0032729") + out <- mosdef::create_link_GO("GO:0032729") expect_is(out, "character") }) test_that("Linking to NCBI database", { - out <- .link2ncbi("Actb") + out <- mosdef::create_link_NCBI("Actb") expect_is(out, "character") }) test_that("Linking to GeneCards database", { - out <- .link2genecards("Gapdh") + out <- mosdef::create_link_GTEX("Gapdh") expect_is(out, "character") }) diff --git a/tests/testthat/test-check_inputs.R b/tests/testthat/test-check_inputs.R index f2e7e3f6..36108469 100644 --- a/tests/testthat/test-check_inputs.R +++ b/tests/testthat/test-check_inputs.R @@ -11,7 +11,7 @@ test_that("Early fails are triggered", { # providing a simple data frame expect_error(GeneTonic(dds_macrophage, - deseqresult2df(res_macrophage_IFNg_vs_naive), + mosdef::deresult_to_df(res_macrophage_IFNg_vs_naive), res_enrich_IFNg_vs_naive, annotation_obj = anno_df )) diff --git a/tests/testthat/test-gene_plot.R b/tests/testthat/test-gene_plot.R index cc208259..8e949509 100644 --- a/tests/testthat/test-gene_plot.R +++ b/tests/testthat/test-gene_plot.R @@ -1,8 +1,8 @@ context("Testing function for plotting the gene expression levels") test_that("Basic gene plot is generated", { - p <- gene_plot( - dds = dds_macrophage, + p <- mosdef::gene_plot( + de_container = dds_macrophage, gene = "ENSG00000285982", assay = "counts", intgroup = "condition", @@ -12,8 +12,8 @@ test_that("Basic gene plot is generated", { ) expect_is(p, "gg") - p2_noanno_normallabels_untransformed <- gene_plot( - dds = dds_macrophage, + p2_noanno_normallabels_untransformed <- mosdef::gene_plot( + de_container = dds_macrophage, gene = "ENSG00000285982", assay = "counts", intgroup = "condition", @@ -28,15 +28,15 @@ test_that("Basic gene plot is generated", { res_enrich = res_enrich_IFNg_vs_naive, annotation_obj = anno_df ) - p3_gtl <- gene_plot( - gtl = gtl_macrophage, - gene = "ENSG00000285982" - ) - expect_is(p3_gtl, "gg") + # p3_gtl <- mosdef::gene_plot( + # gtl = gtl_macrophage, + # gene = "ENSG00000285982" + # ) + # expect_is(p3_gtl, "gg") expect_error({ - gene_plot( - dds = dds_macrophage, + mosdef::gene_plot( + de_container = dds_macrophage, gene = "ENSG00000285982", assay = "counts", intgroup = "factor_not_there", @@ -48,29 +48,29 @@ test_that("Basic gene plot is generated", { }) test_that("Enforcing plot types", { - p_jitter <- gene_plot( - dds = dds_macrophage, + p_jitter <- mosdef::gene_plot( + de_container = dds_macrophage, gene = "ENSG00000285982", assay = "counts", intgroup = "condition", plot_type = "jitteronly" ) - p_boxplot <- gene_plot( - dds = dds_macrophage, + p_boxplot <- mosdef::gene_plot( + de_container = dds_macrophage, gene = "ENSG00000285982", assay = "counts", intgroup = "condition", plot_type = "boxplot" ) - p_violin <- gene_plot( - dds = dds_macrophage, + p_violin <- mosdef::gene_plot( + de_container = dds_macrophage, gene = "ENSG00000285982", assay = "counts", intgroup = "condition", plot_type = "violin" ) - p_sina <- gene_plot( - dds = dds_macrophage, + p_sina <- mosdef::gene_plot( + de_container = dds_macrophage, gene = "ENSG00000285982", assay = "counts", intgroup = "condition", @@ -83,8 +83,8 @@ test_that("Enforcing plot types", { }) test_that("Data instead of plot is returned", { - df_jitter <- gene_plot( - dds = dds_macrophage, + df_jitter <- mosdef::gene_plot( + de_container = dds_macrophage, gene = "ENSG00000285982", assay = "counts", intgroup = "condition", @@ -94,16 +94,16 @@ test_that("Data instead of plot is returned", { }) test_that("Assays are correctly accessed", { - p_non_norm_counts <- gene_plot( - dds = dds_macrophage, + p_non_norm_counts <- mosdef::gene_plot( + de_container = dds_macrophage, gene = "ENSG00000285982", assay = "counts", intgroup = "condition", normalized = FALSE ) expect_is(p_non_norm_counts, "gg") - p_tpm <- gene_plot( - dds = dds_macrophage, + p_tpm <- mosdef::gene_plot( + de_container = dds_macrophage, gene = "ENSG00000285982", assay = "abundance", intgroup = "condition", @@ -111,8 +111,8 @@ test_that("Assays are correctly accessed", { ) expect_is(p_tpm, "gg") - p_other_assay <- gene_plot( - dds = dds_macrophage, + p_other_assay <- mosdef::gene_plot( + de_container = dds_macrophage, gene = "ENSG00000285982", assay = "avgTxLength", intgroup = "condition", @@ -122,8 +122,8 @@ test_that("Assays are correctly accessed", { }) test_that("Extraction of expression values works", { - df_simple <- get_expression_values( - dds = dds_macrophage, + df_simple <- mosdef::get_expr_values( + de_container = dds_macrophage, gene = "ENSG00000285982", intgroup = "condition", assay = "counts" @@ -136,22 +136,22 @@ test_that("Extraction of expression values works", { res_enrich = res_enrich_IFNg_vs_naive[1:200, ], annotation_obj = anno_df ) - df_simple_gtl <- get_expression_values( - gtl = gtl_macrophage, - gene = "ENSG00000285982", - intgroup = "condition", - assay = "counts" - ) - expect_is(df_simple_gtl, "data.frame") + # df_simple_gtl <- mosdef::get_expr_values( + # gtl = gtl_macrophage, + # gene = "ENSG00000285982", + # intgroup = "condition", + # assay = "counts" + # ) + # expect_is(df_simple_gtl, "data.frame") - expect_error(get_expression_values( - dds = dds_macrophage, + expect_error(mosdef::get_expr_values( + de_container = dds_macrophage, gene = "ENSG00000285982", intgroup = "condition", assay = "count" )) - df_unnormalized <- get_expression_values( - dds = dds_unnormalized, + df_unnormalized <- mosdef::get_expr_values( + de_container = dds_unnormalized, gene = "ENSG00000285982", intgroup = "condition", assay = "counts" diff --git a/tests/testthat/test-happy_hour.R b/tests/testthat/test-happy_hour.R index 2b6f1e5a..3cba0474 100644 --- a/tests/testthat/test-happy_hour.R +++ b/tests/testthat/test-happy_hour.R @@ -8,7 +8,7 @@ context("The happy hour is running!") # annotation_obj = anno_df, # project_id = "testsuite", # mygenesets = res_enrich_IFNg_vs_naive$gs_id[2:3], -# mygenes = deseqresult2df(res_de)$id[1:5], +# mygenes = mosdef::deresult_to_df(res_de)$id[1:5], # output_file = "test.html", # force_overwrite = FALSE, # open_after_creating = FALSE @@ -22,7 +22,7 @@ context("The happy hour is running!") # # annotation_obj = anno_df, # # project_id = "testsuite", # # mygenesets = res_enrich_IFNg_vs_naive$gs_id[1:2], -# # mygenes = deseqresult2df(res_de)$id[1:5], +# # mygenes = mosdef::deresult_to_df(res_de)$id[1:5], # # output_file = "test.pdf", # # force_overwrite = FALSE, # # open_after_creating = FALSE @@ -40,7 +40,7 @@ context("The happy hour is running!") # annotation_obj = anno_df, # project_id = "testsuite", # mygenesets = res_enrich_IFNg_vs_naive$gs_id[1:2], -# mygenes = deseqresult2df(res_de)$id[1:5], +# mygenes = mosdef::deresult_to_df(res_de)$id[1:5], # output_file = "doc1.html", # output_format = "pdf_document", # force_overwrite = TRUE, @@ -55,7 +55,7 @@ context("The happy hour is running!") # annotation_obj = anno_df, # project_id = "testsuite", # mygenesets = res_enrich_IFNg_vs_naive$gs_id[1:2], -# mygenes = deseqresult2df(res_de)$id[1:5], +# mygenes = mosdef::deresult_to_df(res_de)$id[1:5], # output_file = "doc1.ppt", # output_format = "powerpoint_presentation", # force_overwrite = TRUE, @@ -72,7 +72,7 @@ context("The happy hour is running!") # annotation_obj = anno_df, # project_id = "testsuite", # mygenesets = res_enrich_IFNg_vs_naive$gs_id[5:6], -# mygenes = deseqresult2df(res_de)$id[1:5], +# mygenes = mosdef::deresult_to_df(res_de)$id[1:5], # output_file = "decoy.html", # force_overwrite = TRUE, # open_after_creating = FALSE @@ -86,7 +86,7 @@ context("The happy hour is running!") # annotation_obj = anno_df, # project_id = "testsuite", # mygenesets = res_enrich_IFNg_vs_naive$gs_id[1:4], -# mygenes = deseqresult2df(res_de)$id[1:5], +# mygenes = mosdef::deresult_to_df(res_de)$id[1:5], # output_file = "decoy.html", # force_overwrite = FALSE, # open_after_creating = FALSE @@ -103,7 +103,7 @@ context("The happy hour is running!") # annotation_obj = anno_df, # project_id = "testsuite", # mygenesets = res_enrich_IFNg_vs_naive$gs_id[3:4], -# mygenes = deseqresult2df(res_de)$id[1:5], +# mygenes = mosdef::deresult_to_df(res_de)$id[1:5], # input_rmd = "custom.Rmd", # output_file = "custom.html", # force_overwrite = TRUE, @@ -118,7 +118,7 @@ context("The happy hour is running!") # annotation_obj = anno_df, # project_id = "testsuite", # mygenesets = res_enrich_IFNg_vs_naive$gs_id[1:2], -# mygenes = deseqresult2df(res_de)$id[1:5], +# mygenes = mosdef::deresult_to_df(res_de)$id[1:5], # input_rmd = "custom2.Rmd", # output_file = "custom.html", # force_overwrite = TRUE, diff --git a/vignettes/GeneTonic_manual.Rmd b/vignettes/GeneTonic_manual.Rmd index 8e2545b7..c27003c0 100644 --- a/vignettes/GeneTonic_manual.Rmd +++ b/vignettes/GeneTonic_manual.Rmd @@ -164,26 +164,25 @@ data("res_de_macrophage") head(res_macrophage_IFNg_vs_naive) ``` -3. `res_enrich`: With the DE results of the previous step, we are going to extract the vector of DE genes (via `deseqresult2df`), as well as the list of genes to be used as background, and feed these two objects into a function that computes the functional enrichment of the DE genes. +3. `res_enrich`: With the DE results of the previous step, we are going to extract the vector of DE genes (via `mosdef::deresult_to_df`), as well as the list of genes to be used as background, and feed these two objects into a function that computes the functional enrichment of the DE genes. - We are going to use the ORA method implemented in `r BiocStyle::Biocpkg("topGO")`, wrapped in the function `topGOtable` available in the `r BiocStyle::Biocpkg("pcaExplorer")` package, which by default uses the `BP` ontology and the `elim` method to decorrelate the GO graph structure and deliver less redundant functional categories. + We are going to use the ORA method implemented in `r BiocStyle::Biocpkg("topGO")`, wrapped in the function `run_topGO` available in the `r BiocStyle::Biocpkg("mosdef")` package, which by default uses the `BP` ontology and the `elim` method to decorrelate the GO graph structure and deliver less redundant functional categories. You can also use as an alternative the `enrichGO` function from `r BiocStyle::Biocpkg("clusterProfiler")`. ```{r create_resenrich1, eval=TRUE} library("AnnotationDbi") -de_symbols_IFNg_vs_naive <- deseqresult2df(res_macrophage_IFNg_vs_naive, FDR = 0.05)$SYMBOL +de_symbols_IFNg_vs_naive <- mosdef::deresult_to_df(res_macrophage_IFNg_vs_naive, FDR = 0.05)$SYMBOL bg_ids <- rowData(dds_macrophage)$SYMBOL[rowSums(counts(dds_macrophage)) > 0] ``` ```{r create_resenrich2, eval=FALSE} library("topGO") topgoDE_macrophage_IFNg_vs_naive <- - pcaExplorer::topGOtable(de_symbols_IFNg_vs_naive, - bg_ids, - ontology = "BP", - mapping = "org.Hs.eg.db", - geneID = "symbol", - topTablerows = 500) + mosdef::run_topGO(de_genes = de_symbols_IFNg_vs_naive, + bg_genes = bg_ids, + ontology = "BP", + mapping = "org.Hs.eg.db", + geneID = "symbol") ``` ```{r load_resenrich, eval=TRUE} @@ -213,7 +212,7 @@ anno_df <- data.frame( row.names = rownames(dds_macrophage) ) ## alternatively: -# anno_df <- pcaExplorer::get_annotation_orgdb(dds_macrophage, "org.Hs.eg.db", "ENSEMBL") +# anno_df <- mosdef::get_annotation_orgdb(dds_macrophage, "org.Hs.eg.db", "ENSEMBL") ``` @@ -768,25 +767,25 @@ Thanks to Charlotte Soneson for providing a compact working implementation of th ## Miscellaneous functions -Extract results and sort them (filtering by FDR) with `deseqresult2df`, select one top-ranking gene, extract its expression values and plot them, and display some buttons to link to external databases: +Extract results and sort them (filtering by FDR) with `mosdef::deresult_to_df`, select one top-ranking gene, extract its expression values and plot them, and display some buttons to link to external databases: ```{r misc} -head(deseqresult2df(res_macrophage_IFNg_vs_naive)) +head(mosdef::deresult_to_df(res_macrophage_IFNg_vs_naive)) # to make sure normalized values are available... dds_macrophage <- estimateSizeFactors(dds_macrophage) -gene_plot(dds_macrophage, +mosdef::gene_plot(dds_macrophage, gene = "ENSG00000125347", intgroup = "condition", annotation_obj = anno_df, plot_type = "auto") -gene_plot(dds_macrophage, +mosdef::gene_plot(dds_macrophage, gene = "ENSG00000174944", intgroup = "condition", assay = "abundance", annotation_obj = anno_df, plot_type = "auto") -geneinfo_2_html("IRF1") +mosdef::geneinfo_to_html("IRF1") ``` Plot a signature heatmap for a gene set, where a matrix of genes times samples for the set members is extracted, plus generate some HTML code to summarize the information of a Gene Ontology term: @@ -801,8 +800,8 @@ gs_heatmap(se = vst_macrophage, anno_col_info = "condition" ) -go_2_html("GO:0060337", - res_enrich = res_enrich_macrophage) +mosdef::go_to_html("GO:0060337", + res_enrich = res_enrich_macrophage) ``` Plot a signature volcano plot for a gene set, with the genes of the geneset highlighted in color and the remaining genes shown shaded in the background: