Skip to content

Commit

Permalink
Merge pull request #13 from federicomarini/mosdefied-ideal
Browse files Browse the repository at this point in the history
Mosdefied ideal
  • Loading branch information
federicomarini authored Sep 20, 2024
2 parents b4bf5c9 + b405ed6 commit e73bea6
Show file tree
Hide file tree
Showing 32 changed files with 483 additions and 359 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ _pkgdown.yml
docs/*
^\.github/workflows/R-CMD-check\.yaml$
^\.github/workflows/pr-commands\.yaml$
^\.github/workflows$
^CODE_OF_CONDUCT\.md$
^LICENSE\.md$
18 changes: 12 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
Package: ideal
Type: Package
Title: Interactive Differential Expression AnaLysis
Version: 1.29.0
Date: 2024-04-07
Version: 1.99.0
Date: 2024-09-13
Authors@R: c(person("Federico", "Marini", role = c("aut", "cre"),
email ="[email protected]",
comment = c(ORCID = '0000-0003-3252-7758')))
Description: This package provides functions for an Interactive
Differential Expression AnaLysis of RNA-sequencing datasets, to
extract quickly and effectively information downstream the step
of differential expression. A Shiny application encapsulates
the whole package.
the whole package. Support for reproducibility of the whole analysis is
provided by means of a template report which gets automatically compiled
and can be stored/shared.
License: MIT + file LICENSE
LazyData: TRUE
Depends: topGO
Imports:
DESeq2,
SummarizedExperiment,
mosdef (>= 1.1.0),
GenomicRanges,
IRanges,
S4Vectors,
ggplot2 (>= 2.0.0),
heatmaply,
plotly,
pheatmap,
pcaExplorer,
IHW,
gplots,
UpSetR,
Expand All @@ -48,8 +49,11 @@ Imports:
shinyAce,
BiocParallel,
grDevices,
graphics,
base64enc,
methods
methods,
utils,
stats
Suggests:
testthat,
BiocStyle,
Expand All @@ -58,6 +62,7 @@ Suggests:
org.Hs.eg.db,
TxDb.Hsapiens.UCSC.hg38.knownGene,
DEFormats,
htmltools,
edgeR
URL: https://github.com/federicomarini/ideal,
https://federicomarini.github.io/ideal/
Expand All @@ -67,3 +72,4 @@ biocViews: ImmunoOncology, GeneExpression, DifferentialExpression, RNASeq, Seque
VignetteBuilder: knitr
RoxygenNote: 7.3.2
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
33 changes: 32 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import(SummarizedExperiment)
import(ggplot2)
import(knitr)
import(methods)
import(pcaExplorer)
import(rmarkdown)
import(shiny)
import(shinydashboard)
Expand Down Expand Up @@ -47,11 +46,26 @@ importFrom(goseq,goseq)
importFrom(goseq,nullp)
importFrom(gplots,venn)
importFrom(grDevices,axisTicks)
importFrom(grDevices,colorRamp)
importFrom(grDevices,dev.off)
importFrom(grDevices,pdf)
importFrom(grDevices,rgb)
importFrom(graphics,pairs)
importFrom(graphics,par)
importFrom(graphics,strwidth)
importFrom(graphics,text)
importFrom(heatmaply,heatmaply)
importFrom(limma,goana)
importFrom(limma,topGO)
importFrom(mosdef,create_link_ENSEMBL)
importFrom(mosdef,create_link_GO)
importFrom(mosdef,create_link_NCBI)
importFrom(mosdef,deresult_to_df)
importFrom(mosdef,gene_plot)
importFrom(mosdef,get_annotation_orgdb)
importFrom(mosdef,pair_corr)
importFrom(mosdef,run_goseq)
importFrom(mosdef,run_topGO)
importFrom(pheatmap,pheatmap)
importFrom(plotly,plotlyOutput)
importFrom(plotly,renderPlotly)
Expand All @@ -68,6 +82,23 @@ importFrom(shinyAce,updateAceEditor)
importFrom(shinyBS,bsCollapse)
importFrom(shinyBS,bsCollapsePanel)
importFrom(shinyBS,bsTooltip)
importFrom(stats,as.formula)
importFrom(stats,cor)
importFrom(stats,quantile)
importFrom(stats,sd)
importFrom(stats,terms.formula)
importFrom(stats,var)
importFrom(stringr,str_count)
importFrom(utils,count.fields)
importFrom(utils,data)
importFrom(utils,head)
importFrom(utils,installed.packages)
importFrom(utils,packageDescription)
importFrom(utils,packageVersion)
importFrom(utils,read.delim)
importFrom(utils,sessionInfo)
importFrom(utils,str)
importFrom(utils,tail)
importFrom(utils,write.csv)
importMethodsFrom(GOstats,hyperGTest)
importMethodsFrom(GOstats,summary)
11 changes: 11 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# ideal 1.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

# ideal 1.18.0

## Bug fixes
Expand Down
45 changes: 45 additions & 0 deletions R/deprecated.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#' Deprecated functions in ideal
#'
#' 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:
#'
#' - [goseqTable()] is now being replaced by the more flexible
#' [mosdef::run_goseq()] function (which is even faster)
#' - [ggplotCounts()] is now being replaced by the more flexible, better
#' designed, and actually even more good looking [mosdef::gene_plot()]
#' function, with better default behavior and all.
#' - [deseqresult2tbl()] and [deseqresult2DEgenes()] are now replaced by the
#' more flexible [mosdef::deresult_to_df()]
#' - The internally defined functions `createLinkENS()`, `createLinkGeneSymbol()`,
#' and `createLinkGO()` are now replaced by the equivalent functions in `mosdef`:
#' [mosdef::create_link_ENSEMBL()], [mosdef::create_link_NCBI()] 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(goseqtable())
#'
NULL


## #' @export
## #' @rdname defunct
## trendVar <- function(...) {
## .Defunct("fitTrendVar")
## }
14 changes: 7 additions & 7 deletions R/genesignatures.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#' # this example reads in the freely available pathways from wikipathways
#' \dontrun{
#' mysigs <- read_gmt(
#' "http://data.wikipathways.org/20180910/gmt/wikipathways-20180910-gmt-Homo_sapiens.gmt"
#' "http://data.wikipathways.org/20240910/gmt/wikipathways-20240910-gmt-Homo_sapiens.gmt"
#' )
#' head(mysigs)
#' # see how the gene identifiers are encoded as ENTREZ id
Expand All @@ -34,11 +34,11 @@ read_gmt <- function(gmtfile) {
#' Plot a heatmap for the selected gene signature on the provided data, with the
#' possibility to compactly display also DE only genes
#'
#' @param vst_data A \code{\link{DESeqTransform}} object - usually the variance
#' @param vst_data A [DESeqTransform()] object - usually the variance
#' stabilized transformed data, which will be used to extract the expression values
#' @param my_signature A character vector, usually named, containing the genes
#' which compose the gene signature
#' @param res_data A \code{\link{DESeqResults}} object. If not provided, it can
#' @param res_data A [DESeqResults()] object. If not provided, it can
#' be computed during the execution of the application
#' @param FDR Numeric value between 0 and 1, the False Discovery Rate
#' @param de_only Logical, whether to display only DE genes belonging to the pathway -
Expand All @@ -57,13 +57,13 @@ read_gmt <- function(gmtfile) {
#' @param scale_row Logical, whether to perform row-based standardization of the
#' expression values
#'
#' @return A plot based on the \code{pheatmap} function
#' @return A plot based on the `pheatmap` function
#' @export
#'
#' @examples
#' # with the well known airway package...
#' library(airway)
#' data(airway)
#' library("airway")
#' data("airway", package = "airway")
#' airway
#' dds_airway <- DESeq2::DESeqDataSetFromMatrix(assay(airway),
#' colData = colData(airway),
Expand Down Expand Up @@ -117,7 +117,7 @@ sig_heatmap <- function(vst_data, my_signature,
}

if (de_only) {
de_res <- deseqresult2DEgenes(res_data, FDR)
de_res <- mosdef::deresult_to_df(res_data, FDR)
de_genes <- de_res$id
de_to_keep <- rownames(mydata_sig) %in% de_genes
mydata_sig <- mydata_sig[de_to_keep, ]
Expand Down
93 changes: 29 additions & 64 deletions R/ggplotCounts.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,30 @@
#' Plot for normalized counts of a single gene, with jittered points superimposed
#' on the boxplot
#'
#' Note: this function relies on the \code{\link{plotCounts}} function of DESeq2,
#' Note: this function relies on the [plotCounts()] function of DESeq2,
#' therefore pseudocounts of 0.5 are added to each point
#'
#' @param dds A \code{\link{DESeqDataSet}} object.
#' @param dds A [DESeqDataSet()] object.
#' @param gene A character, specifying the name of the gene to plot
#' @param intgroup Interesting groups: a character vector of
#' names in \code{colData(dds)} to use for grouping
#' @param annotation_obj A \code{data.frame} object, with \code{row.names} as gene
#' identifiers (e.g. ENSEMBL ids) and a column, \code{gene_name}, containing
#' names in `colData(dds)` to use for grouping
#' @param annotation_obj A `data.frame` object, with `row.names` as gene
#' identifiers (e.g. ENSEMBL ids) and a column, `gene_name`, containing
#' e.g. HGNC-based gene symbols. Optional.
#' @param transform Logical value, corresponding whether to have log scale y-axis
#' or not. Defaults to TRUE.
#' @param labels_repel Logical value. Whether to use \code{ggrepel}'s functions to
#' @param labels_repel Logical value. Whether to use `ggrepel`'s functions to
#' place labels; defaults to TRUE.
#'
#' @return An object created by \code{ggplot}
#' @return An object created by `ggplot`
#'
#' @importFrom mosdef gene_plot
#'
#' @export
#'
#' @examples
#' library(airway)
#' data(airway)
#' library("airway")
#' data("airway", package = "airway")
#' airway
#' dds_airway <- DESeq2::DESeqDataSetFromMatrix(assay(airway),
#' colData = colData(airway),
Expand All @@ -35,59 +38,21 @@
#' )
ggplotCounts <- function(dds, gene, intgroup = "condition", annotation_obj = NULL,
transform = TRUE, labels_repel = TRUE) {
df <- plotCounts(dds, gene, intgroup, returnData = TRUE)
df$sampleID <- rownames(df)

if (!is.null(annotation_obj)) {
genesymbol <- annotation_obj$gene_name[match(gene, annotation_obj$gene_id)]
} else {
genesymbol <- ""
}

jittered_df <- df
# jittered_df$conditionj <- jitter(as.numeric(factor(jittered_df$condition)))
jittered_df$countj <- jitter(jittered_df$count)

onlyfactors <- df[, match(intgroup, colnames(df))]
df$plotby <- interaction(onlyfactors)

# base_breaks <- function(n = 10){
# function(x) {
# axisTicks(log10(range(x, na.rm = TRUE)), log = TRUE, nint = n)
# }
# }

p <-
ggplot(df, aes_string(x = "plotby", y = "count", col = "plotby")) +
geom_boxplot(outlier.shape = NA) +
# geom_text(data = jittered_df,aes(x=conditionj,y=countj,label=sampleID)) +
scale_x_discrete(name = "") +
geom_jitter(aes_string(x = "plotby", y = "count"),
position = position_jitter(width = 0.1)
) +
scale_color_discrete(name = "Experimental\nconditions")

if (labels_repel) {
p <- p + ggrepel::geom_text_repel(aes_string(label = "sampleID"))
} else {
p <- p + geom_text(aes_string(label = "sampleID"), hjust = -.1, vjust = 0)
}

if (transform) {
p <- p + scale_y_log10(name = "Normalized counts (log10 scale)")
} else {
p <- p + scale_y_continuous(name = "Normalized counts")
}

# scale_y_log10(name="Normalized counts - log10 scale") +
# coord_cartesian(ylim = c())# ,limits=c(0.1,NA)) +
p <- p + theme_bw()

if (!is.null(annotation_obj)) {
p <- p + labs(title = paste0("Normalized counts for ", genesymbol, " - ", gene))
} else {
p <- p + labs(title = paste0("Normalized counts for ", gene))
}

p
.Deprecated(old = "ggplotCounts", new = "mosdef::gene_plot",
msg = paste0(
"Please use `mosdef::gene_plot()` in replacement of the `ggplotCounts()` function, ",
"originally located in the ideal package. \nCheck the manual page for ",
"`?mosdef::gene_plot()` to see the details on how to use it, e.g. ",
"refer to the new parameter definition and naming"))

p <- mosdef::gene_plot(
de_container = dds,
gene = gene,
intgroup = intgroup,
annotation_obj = annotation_obj,
transform = transform,
labels_repel = labels_repel
)

return(p)
}
Loading

0 comments on commit e73bea6

Please sign in to comment.