diff --git a/.dockerfile/v1.0.0/dockerfile b/.dockerfile/v1.0.0/dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..70a8df87b67d829b948bb05428b41ceea0df0fb9 --- /dev/null +++ b/.dockerfile/v1.0.0/dockerfile @@ -0,0 +1,11 @@ +FROM r-base:4.3.1 + + +RUN apt-get -y update && \ + apt-get -y install cmake libxml2-dev + +RUN wget http://gitbio.ens-lyon.fr/aduvermy/HTRfit/-/archive/v1.0.0/HTRfit-v1.0.0.tar && \ + tar -xf /HTRfit-v1.0.0.tar && \ + R -e "install.packages(c('car', 'parallel', 'data.table', 'ggplot2', 'gridExtra', 'glmmTMB', 'magrittr', 'MASS', 'plotROC', 'reshape2', 'rlang', 'stats', 'utils', 'BiocManager'))" && \ + R -e "BiocManager::install('S4Vectors', update = FALSE)" && \ + R -e "install.packages('/HTRfit-v1.0.0', repos = NULL, type='source')" diff --git a/CHANGELOG b/CHANGELOG index 6327b046792dd1dac9faa517c08de937158e7b99..2d10b3bd6e40c51533d7578d2c16d6a70a82399d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,4 +4,13 @@ The functions, tests, and vignettes are fully functional and operational! To do: - conducting installation tests - - seeking out beta testers for further evaluation. \ No newline at end of file + - seeking out beta testers for further evaluation. + + +# v1.0.1 : few enhancements + + - The metrics_plot function has been updated to display histograms instead of density plots. + - The identity plot's point shape has been modified, enhancing the visual clarity of comparisons between HTRfit and DESeq2 results. + - Similar to the identity plot, the dispersion plot also benefits from improved point shape, contributing to a more effective visual analysis. + - Add xlab/ylab to ROC plot + - The vignette section now includes a new topic, "About mixed model evaluation". \ No newline at end of file diff --git a/NAMESPACE b/NAMESPACE index b44ed98584e99faffe3f0db66c5d60e2bbbf7766..af9a2dc9c5b15b6b7dc17debdfede65b7fff193f 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -135,6 +135,7 @@ importFrom(ggplot2,element_blank) importFrom(ggplot2,facet_wrap) importFrom(ggplot2,geom_abline) importFrom(ggplot2,geom_density) +importFrom(ggplot2,geom_histogram) importFrom(ggplot2,geom_point) importFrom(ggplot2,ggplot) importFrom(ggplot2,ggsave) @@ -146,6 +147,8 @@ importFrom(ggplot2,sym) importFrom(ggplot2,theme) importFrom(ggplot2,theme_bw) importFrom(ggplot2,unit) +importFrom(ggplot2,xlab) +importFrom(ggplot2,ylab) importFrom(gridExtra,arrangeGrob) importFrom(gridExtra,grid.arrange) importFrom(gridExtra,tableGrob) diff --git a/R/evaluatedispersion.R b/R/evaluatedispersion.R index 640aac058ff008e9f7b958dfb073fa8d64e77951..39b81b9f877fbd1fdd43775a684d84a78d8b7c0e 100644 --- a/R/evaluatedispersion.R +++ b/R/evaluatedispersion.R @@ -21,8 +21,7 @@ #' } evaluateDispersion <- function(TMB_dispersion_df, DESEQ_dispersion_df, color2use) { disp_comparison_dtf <- rbind(TMB_dispersion_df, DESEQ_dispersion_df) - disp_plot <- dispersion_plot(disp_comparison_dtf, col = "from") + ggplot2::scale_color_manual(values = color2use) - + disp_plot <- dispersion_plot(disp_comparison_dtf, col = "from", pch = "from") + ggplot2::scale_color_manual(values = color2use) return(list(disp_plot = disp_plot, data = disp_comparison_dtf)) } diff --git a/R/identityplot.R b/R/identityplot.R index f16934bcb8814507440f9627862dd6cdc0e28c2a..943704f6db51af8f14986e04d9cb50f6286b4784 100644 --- a/R/identityplot.R +++ b/R/identityplot.R @@ -24,7 +24,7 @@ identity_plot <- function(comparison_df, ...){ ggplot2::ggplot(comparison_df) + - ggplot2::geom_point(ggplot2::aes(x = actual, y = estimate, !!!args), alpha = 0.6) + + ggplot2::geom_point(ggplot2::aes(x = actual, y = estimate, !!!args), alpha = 0.6, size = 2) + ggplot2::geom_abline(intercept = 0, slope = 1, lty = 3, col = 'red', linewidth = 1) + ggplot2::facet_wrap(~description, scales = "free") + ggplot2::theme_bw() + diff --git a/R/plot_metrics.R b/R/plot_metrics.R index 49f39455e400ead1c7967639941d8ee56bffc0b2..de36e10ce75da342ee5723030daf8a482742c89e 100644 --- a/R/plot_metrics.R +++ b/R/plot_metrics.R @@ -40,10 +40,10 @@ subset_glance <- function(glance_df, focus){ #' values include "AIC", "BIC", "logLik", "deviance", "df.resid", and #' "dispersion". If \code{NULL}, all available metrics will be plotted. #' -#' @return A ggplot object displaying density plots for the specified metrics. +#' @return A ggplot object displaying histogram plots for the specified metrics. #' #' @importFrom reshape2 melt -#' @importFrom ggplot2 aes facet_wrap geom_density theme_bw theme ggtitle +#' @importFrom ggplot2 aes facet_wrap geom_histogram theme_bw theme ggtitle #' #' @export #' @@ -59,7 +59,7 @@ metrics_plot <- function(l_tmb, focus = NULL) { } long_glance_df <- reshape2::melt(glance_df, variable.name = "metric") p <- ggplot2::ggplot(long_glance_df) + - ggplot2::geom_density(ggplot2::aes(x = value, col = metric, fill = metric), alpha = 0.4) + + ggplot2::geom_histogram(ggplot2::aes(x = value, col = metric, fill = metric)) + ggplot2::facet_wrap(~metric, scales = "free") + ggplot2::theme_bw() + ggplot2::theme(legend.position = 'null') + diff --git a/R/rocplot.R b/R/rocplot.R index 352ced38fe8e1f15727e3bb57411210cfba3edfc..1745b02c525c19df2162389dbfb41c08a1eb0788 100644 --- a/R/rocplot.R +++ b/R/rocplot.R @@ -47,7 +47,7 @@ getLabelExpected <- function(comparison_df, coeff_threshold, alt_hypothesis) { #' @param ... additional params to pass ggplot2::aes #' @return A ggplot object representing the ROC curve plot. #' @importFrom plotROC geom_roc -#' @importFrom ggplot2 ggtitle theme_bw aes sym +#' @importFrom ggplot2 ggtitle theme_bw aes sym xlab ylab #' #' @examples #' comparison_data <- data.frame( @@ -75,7 +75,9 @@ roc_plot <- function(comparison_df, ...) { p <- ggplot2::ggplot(comparison_df, ggplot2::aes(d = !isDE , m = p.adj, !!!args )) + plotROC::geom_roc(n.cuts = 0, labels = FALSE) + ggplot2::theme_bw() + - ggplot2::ggtitle("ROC curve") + ggplot2::ggtitle("ROC curve") + + ggplot2::xlab("False positive rate") + + ggplot2::ylab("True positive rate") ## -- annotation AUC df_AUC <- subset(plotROC::calc_auc(p) , select = -c(PANEL, group)) diff --git a/R/simulationreport.R b/R/simulationreport.R index 3200568615d7ae2e116249152ba31f9004c6c36f..b15cb24f8a3f1f8157e202c53c2da5843cb2f8f2 100644 --- a/R/simulationreport.R +++ b/R/simulationreport.R @@ -68,15 +68,15 @@ getGrobTable <- function(df){ #' #' @param mock_obj A list containing simulation data and ground truth. #' @param list_tmb A list of model results. -#' @param dds_obj a DESeq2 object #' @param coeff_threshold A threshold for comparing estimates. #' @param alt_hypothesis The alternative hypothesis for comparisons ("greater", "less", "greaterAbs"). #' @param report_file File name to save the generated report. If NULL, the report will not be exported. +#' @param dds_obj a DESeq2 object #' @importFrom ggplot2 aes geom_point geom_abline facet_wrap theme_bw ggtitle #' @return A list containing settings, plots, and evaluation results. #' @export -simulationReport <- function(mock_obj, list_tmb = NULL, dds_obj = NULL , - coeff_threshold = 0, alt_hypothesis = "greaterAbs", report_file = NULL){ +simulationReport <- function(mock_obj, list_tmb = NULL, + coeff_threshold = 0, alt_hypothesis = "greaterAbs", report_file = NULL, dds_obj = NULL ){ #-- init TMB_comparison_df <- data.frame() @@ -111,12 +111,13 @@ simulationReport <- function(mock_obj, list_tmb = NULL, dds_obj = NULL , comparison_df <- rbind( DESEQ_comparison_df, TMB_comparison_df ) - color2use <- c("#D2B4DE", "#A2D9CE") - color2use <- color2use[c(!is.null(list_tmb), !is.null(dds_obj))] + #color2use <- c("#D2B4DE", "#A2D9CE") + color2use <- c("#500472", "#79cbb8") + color2use <- color2use[c(!is.null(dds_obj), !is.null(list_tmb))] # -- plotting roc_curve <- roc_plot(comparison_df, col = "from" ) + ggplot2::scale_color_manual(values = color2use) - id_plot <- identity_plot(comparison_df, col = "from") + ggplot2::scale_color_manual(values = color2use) + id_plot <- identity_plot(comparison_df, col = "from", pch = "from") + ggplot2::scale_color_manual(values = color2use) #metrics_plot <- metrics_plot(list_tmb) evalDisp <- evaluateDispersion(TMB_dispersion_df, DESEQ_dispersion_df, color2use ) dispersion_plot <- evalDisp$disp_plot diff --git a/README.md b/README.md index 498424ce4799af66dc47328b5e2086bd18896420..a5a9187f22cb57d7403ce65b695a303c0562ab45 100644 --- a/README.md +++ b/README.md @@ -2,23 +2,34 @@ ## Installation +* method A: To install the latest version of HTRfit, run the following in your R console : - ``` if (!requireNamespace("remotes", quietly = TRUE)) install.packages("remotes") remotes::install_git("https://gitbio.ens-lyon.fr/aduvermy/HTRfit") ``` -When dependencies are met, installation should take under 20 seconds. +* method B: + +Alternatively, you can download a release on https://gitbio.ens-lyon.fr/aduvermy/HTRfit/-/releases. +Then, run the following in your R console: + +``` +## -- example with release HTRfit-v1.0.0 +install.packages('/HTRfit-v1.0.0', repos = NULL, type='source') +``` + +When dependencies are met, installation should take a few minutes. ## CRAN packages dependencies +The following depandencies are mandatory: + ``` -install.packages(c("car", "parallel", "data.table", "ggplot2", "gridExtra", - "glmmTMB", "magrittr", "MASS", "plotROC", "reshape2", - "rlang", "S4Vectors", "stats", "utils")) +install.packages(c('car', 'parallel', 'data.table', 'ggplot2', 'gridExtra', 'glmmTMB', 'magrittr', 'MASS', 'plotROC', 'reshape2', 'rlang', 'stats', 'utils', 'BiocManager')) +BiocManager::install('S4Vectors', update = FALSE) ``` ### System requirements diff --git a/dev/flat_full.Rmd b/dev/flat_full.Rmd index 21306178514dbff0ecdc19f33284651b1cc8ede4..cb68a25a63a4f3615662f158c54442c0ca1445a5 100644 --- a/dev/flat_full.Rmd +++ b/dev/flat_full.Rmd @@ -3672,10 +3672,10 @@ subset_glance <- function(glance_df, focus){ #' values include "AIC", "BIC", "logLik", "deviance", "df.resid", and #' "dispersion". If \code{NULL}, all available metrics will be plotted. #' -#' @return A ggplot object displaying density plots for the specified metrics. +#' @return A ggplot object displaying histogram plots for the specified metrics. #' #' @importFrom reshape2 melt -#' @importFrom ggplot2 aes facet_wrap geom_density theme_bw theme ggtitle +#' @importFrom ggplot2 aes facet_wrap geom_histogram theme_bw theme ggtitle #' #' @export #' @@ -3691,7 +3691,7 @@ metrics_plot <- function(l_tmb, focus = NULL) { } long_glance_df <- reshape2::melt(glance_df, variable.name = "metric") p <- ggplot2::ggplot(long_glance_df) + - ggplot2::geom_density(ggplot2::aes(x = value, col = metric, fill = metric), alpha = 0.4) + + ggplot2::geom_histogram(ggplot2::aes(x = value, col = metric, fill = metric)) + ggplot2::facet_wrap(~metric, scales = "free") + ggplot2::theme_bw() + ggplot2::theme(legend.position = 'null') + @@ -3767,8 +3767,7 @@ test_that("metrics_plot returns a ggplot object", { #' } evaluateDispersion <- function(TMB_dispersion_df, DESEQ_dispersion_df, color2use) { disp_comparison_dtf <- rbind(TMB_dispersion_df, DESEQ_dispersion_df) - disp_plot <- dispersion_plot(disp_comparison_dtf, col = "from") + ggplot2::scale_color_manual(values = color2use) - + disp_plot <- dispersion_plot(disp_comparison_dtf, col = "from", pch = "from") + ggplot2::scale_color_manual(values = color2use) return(list(disp_plot = disp_plot, data = disp_comparison_dtf)) } @@ -5611,7 +5610,7 @@ getLabelExpected <- function(comparison_df, coeff_threshold, alt_hypothesis) { #' @param ... additional params to pass ggplot2::aes #' @return A ggplot object representing the ROC curve plot. #' @importFrom plotROC geom_roc -#' @importFrom ggplot2 ggtitle theme_bw aes sym +#' @importFrom ggplot2 ggtitle theme_bw aes sym xlab ylab #' #' @examples #' comparison_data <- data.frame( @@ -5639,7 +5638,9 @@ roc_plot <- function(comparison_df, ...) { p <- ggplot2::ggplot(comparison_df, ggplot2::aes(d = !isDE , m = p.adj, !!!args )) + plotROC::geom_roc(n.cuts = 0, labels = FALSE) + ggplot2::theme_bw() + - ggplot2::ggtitle("ROC curve") + ggplot2::ggtitle("ROC curve") + + ggplot2::xlab("False positive rate") + + ggplot2::ylab("True positive rate") ## -- annotation AUC df_AUC <- subset(plotROC::calc_auc(p) , select = -c(PANEL, group)) @@ -5788,7 +5789,7 @@ identity_plot <- function(comparison_df, ...){ ggplot2::ggplot(comparison_df) + - ggplot2::geom_point(ggplot2::aes(x = actual, y = estimate, !!!args), alpha = 0.6) + + ggplot2::geom_point(ggplot2::aes(x = actual, y = estimate, !!!args), alpha = 0.6, size = 2) + ggplot2::geom_abline(intercept = 0, slope = 1, lty = 3, col = 'red', linewidth = 1) + ggplot2::facet_wrap(~description, scales = "free") + ggplot2::theme_bw() + @@ -5892,15 +5893,15 @@ getGrobTable <- function(df){ #' #' @param mock_obj A list containing simulation data and ground truth. #' @param list_tmb A list of model results. -#' @param dds_obj a DESeq2 object #' @param coeff_threshold A threshold for comparing estimates. #' @param alt_hypothesis The alternative hypothesis for comparisons ("greater", "less", "greaterAbs"). #' @param report_file File name to save the generated report. If NULL, the report will not be exported. +#' @param dds_obj a DESeq2 object #' @importFrom ggplot2 aes geom_point geom_abline facet_wrap theme_bw ggtitle #' @return A list containing settings, plots, and evaluation results. #' @export -simulationReport <- function(mock_obj, list_tmb = NULL, dds_obj = NULL , - coeff_threshold = 0, alt_hypothesis = "greaterAbs", report_file = NULL){ +simulationReport <- function(mock_obj, list_tmb = NULL, + coeff_threshold = 0, alt_hypothesis = "greaterAbs", report_file = NULL, dds_obj = NULL ){ #-- init TMB_comparison_df <- data.frame() @@ -5935,12 +5936,13 @@ simulationReport <- function(mock_obj, list_tmb = NULL, dds_obj = NULL , comparison_df <- rbind( DESEQ_comparison_df, TMB_comparison_df ) - color2use <- c("#D2B4DE", "#A2D9CE") - color2use <- color2use[c(!is.null(list_tmb), !is.null(dds_obj))] + #color2use <- c("#D2B4DE", "#A2D9CE") + color2use <- c("#500472", "#79cbb8") + color2use <- color2use[c(!is.null(dds_obj), !is.null(list_tmb))] # -- plotting roc_curve <- roc_plot(comparison_df, col = "from" ) + ggplot2::scale_color_manual(values = color2use) - id_plot <- identity_plot(comparison_df, col = "from") + ggplot2::scale_color_manual(values = color2use) + id_plot <- identity_plot(comparison_df, col = "from", pch = "from") + ggplot2::scale_color_manual(values = color2use) #metrics_plot <- metrics_plot(list_tmb) evalDisp <- evaluateDispersion(TMB_dispersion_df, DESEQ_dispersion_df, color2use ) dispersion_plot <- evalDisp$disp_plot @@ -7383,6 +7385,8 @@ l_tmb <- fitModelParallel(formula = kij ~ varB + (varB | varA), family = glmmTMB::nbinom2(link = "log"), log_file = "log.txt", n.cores = 1) +## -- output +l_tmb$gene1 ## -- evaluation resSimu <- simulationReport(mock_data, list_tmb = l_tmb, @@ -7400,6 +7404,11 @@ resSimu$roc_plot ``` +# About mixed model evaluation + +**HTRfit** offers a versatile simulation framework capable of fitting various types of models involving mixed effects, thanks to its implementation of **glmmTMB**. By combining the functionalities of `init_variable()` and `add_interaction()`, **HTRfit** enables the simulation of even the most complex experimental designs. However, it's important to note that as of now, HTRfit supports the evaluation of only *Type I* mixed models. In this context, *Type I* models are defined as those that follow the structure: `~ varA + (1 | varB)` or `~ varA + (varA | varB)`. Models not conforming to this specific form cannot be evaluated using **HTRfit's** current implementation. Nonetheless, you are welcome to extend its capabilities by implementing support for additional model types. + + ```{r development-inflate, eval=FALSE} setwd("/Users/ex_dya/Documents/LBMC/HTRfit/") #usethis::create_package(path = "/Users/ex_dya/Documents/LBMC/HTRfit/") @@ -7409,5 +7418,5 @@ usethis::use_pipe(export = TRUE) devtools::document() # Keep eval=FALSE to avoid infinite loop in case you hit the knit button # Execute in the console directly -fusen::inflate(flat_file = "dev/flat_full.Rmd", vignette_name = "HTRfit") +fusen::inflate(flat_file = "dev/flat_full.Rmd", vignette_name = "HTRfit", open_vignette = T, overwrite = T) ``` diff --git a/man/metrics_plot.Rd b/man/metrics_plot.Rd index f252d49384a8660ddedbb30a6ae392a4a69bf8e7..f01ebf10c22d090eb53bf5e473ecbdc2af45437f 100644 --- a/man/metrics_plot.Rd +++ b/man/metrics_plot.Rd @@ -14,7 +14,7 @@ values include "AIC", "BIC", "logLik", "deviance", "df.resid", and "dispersion". If \code{NULL}, all available metrics will be plotted.} } \value{ -A ggplot object displaying density plots for the specified metrics. +A ggplot object displaying histogram plots for the specified metrics. } \description{ This function generates a density plot of the specified metrics for the given diff --git a/man/simulationReport.Rd b/man/simulationReport.Rd index 2d678f3d95e582e91e8ba1cb00257224fbfedc39..123a3af603ad14486e6d3fd7bf943dceb68090cc 100644 --- a/man/simulationReport.Rd +++ b/man/simulationReport.Rd @@ -7,10 +7,10 @@ simulationReport( mock_obj, list_tmb = NULL, - dds_obj = NULL, coeff_threshold = 0, alt_hypothesis = "greaterAbs", - report_file = NULL + report_file = NULL, + dds_obj = NULL ) } \arguments{ @@ -18,13 +18,13 @@ simulationReport( \item{list_tmb}{A list of model results.} -\item{dds_obj}{a DESeq2 object} - \item{coeff_threshold}{A threshold for comparing estimates.} \item{alt_hypothesis}{The alternative hypothesis for comparisons ("greater", "less", "greaterAbs").} \item{report_file}{File name to save the generated report. If NULL, the report will not be exported.} + +\item{dds_obj}{a DESeq2 object} } \value{ A list containing settings, plots, and evaluation results. diff --git a/vignettes/htrfit.Rmd b/vignettes/htrfit.Rmd index 38619891eaecd9b971fc664e0b7ab094db9d12f4..56f5478f12a7c8efb5ee54ca613fd9e990dfcec4 100644 --- a/vignettes/htrfit.Rmd +++ b/vignettes/htrfit.Rmd @@ -503,6 +503,8 @@ l_tmb <- fitModelParallel(formula = kij ~ varB + (varB | varA), family = glmmTMB::nbinom2(link = "log"), log_file = "log.txt", n.cores = 1) +## -- output +l_tmb$gene1 ## -- evaluation resSimu <- simulationReport(mock_data, list_tmb = l_tmb, @@ -519,3 +521,9 @@ resSimu$dispersionEvaluation$disp_plot resSimu$roc_plot ``` +# About mixed model evaluation + +**HTRfit** offers a versatile simulation framework capable of fitting various types of models involving mixed effects, thanks to its implementation of **glmmTMB**. By combining the functionalities of `init_variable()` and `add_interaction()`, **HTRfit** enables the simulation of even the most complex experimental designs. However, it's important to note that as of now, HTRfit supports the evaluation of only *Type I* mixed models. In this context, *Type I* models are defined as those that follow the structure: `~ varA + (1 | varB)` or `~ varA + (varA | varB)`. Models not conforming to this specific form cannot be evaluated using **HTRfit's** current implementation. Nonetheless, you are welcome to extend its capabilities by implementing support for additional model types. + + +