From 0fc6dd15ec9573cf6dfd9b87eb58ab8be6505ccd Mon Sep 17 00:00:00 2001 From: ShixiangWang Date: Mon, 19 Oct 2020 20:14:12 +0800 Subject: [PATCH] close #298 --- NEWS.md | 1 + R/show_sig_bootstrap.R | 27 ++++-- docs/news/index.html | 87 ++++++++++--------- docs/reference/show_sig_bootstrap.html | 7 +- man/show_sig_bootstrap.Rd | 7 +- ...roxytest-testexamples-show_sig_bootstrap.R | 5 +- 6 files changed, 80 insertions(+), 54 deletions(-) diff --git a/NEWS.md b/NEWS.md index 5717f08d..150cb442 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # sigminer 1.1.0 +- Added new measure 'CV' for `show_sig_bootstrap()` (#298). - Added `group_enrichment()` and `show_group_enrichment()` (#277). - Optimized signature profile visualization (#295). - Update `?sigminer` documentation. diff --git a/R/show_sig_bootstrap.R b/R/show_sig_bootstrap.R index 973eb8b6..a2fa83ad 100644 --- a/R/show_sig_bootstrap.R +++ b/R/show_sig_bootstrap.R @@ -11,6 +11,7 @@ #' - [show_sig_bootstrap_stability] - this function plots the signature exposure instability for specified signatures. Currently, #' the instability measure supports 3 types: #' - 'RMSE' for Mean Root Squared Error (default) of bootstrap exposures and original exposures for each sample. +#' - 'CV' for Coefficient of Variation (CV) based on RMSE (i.e. `RMSE / btExposure_mean`). #' - 'MAE' for Mean Absolute Error of bootstrap exposures and original exposures for each sample. #' - 'AbsDiff' for Absolute Difference between mean bootstram exposure and original exposure. #' @@ -21,7 +22,7 @@ #' @param bt_result result object from [sig_fit_bootstrap_batch]. #' @param sample a sample id. #' @param signatures signatures to show. -#' @param measure measure to estimate the exposure instability, can be one of 'RMSE', 'MAE' and 'AbsDiff'. +#' @param measure measure to estimate the exposure instability, can be one of 'RMSE', 'CV', 'MAE' and 'AbsDiff'. #' @param dodge_width dodge width. #' @param plot_fun set the plot function. #' @param agg_fun set the aggregation function when `sample` is `NULL`. @@ -85,6 +86,8 @@ #' p5 #' p6 <- show_sig_bootstrap_stability(bt_result, methods = c("QP"), measure = "AbsDiff") #' p6 +#' p7 <- show_sig_bootstrap_stability(bt_result, methods = c("QP"), measure = "CV") +#' p7 #' } else { #' message("Please install package 'BSgenome.Hsapiens.UCSC.hg19' firstly!") #' } @@ -96,6 +99,7 @@ #' expect_s3_class(p4, "ggplot") #' expect_s3_class(p5, "ggplot") #' expect_s3_class(p6, "ggplot") +#' expect_s3_class(p7, "ggplot") NULL #' @rdname show_sig_bootstrap @@ -289,7 +293,8 @@ show_sig_bootstrap_error <- function(bt_result, sample = NULL, #' @rdname show_sig_bootstrap #' @export -show_sig_bootstrap_stability <- function(bt_result, signatures = NULL, measure = c("RMSE", "MAE", "AbsDiff"), +show_sig_bootstrap_stability <- function(bt_result, signatures = NULL, + measure = c("RMSE", "CV", "MAE", "AbsDiff"), methods = "QP", plot_fun = c("boxplot", "violin"), palette = "aaas", title = NULL, xlab = FALSE, ylab = "Signature instability", @@ -338,13 +343,23 @@ show_sig_bootstrap_stability <- function(bt_result, signatures = NULL, measure = dplyr::summarise(measure = abs(.data$optimal - .data$bootstrap)) %>% dplyr::ungroup() } else { - ## Calculate RMSE(Root Mean Squared Error)or MAE (Mean Absolute Error) - if (measure == "RMSE") { + ## Calculate RMSE(Root Mean Squared Error), CV or MAE (Mean Absolute Error) + if (measure %in% c("RMSE", "CV")) { ## across solution: https://github.com/tidyverse/dplyr/issues/5230 dat <- dat %>% tidyr::pivot_wider(names_from = "type", values_from = "exposure") %>% - dplyr::mutate_at(dplyr::vars(dplyr::starts_with("Rep_")), ~ (. - .data$optimal)^2) %>% - dplyr::mutate(measure = dplyr::select(., -c("method", "sample", "optimal", "sig")) %>% rowMeans() %>% sqrt()) %>% + dplyr::mutate(mean_rep = dplyr::select(., dplyr::starts_with("Rep_")) %>% rowMeans()) %>% + dplyr::mutate_at(dplyr::vars(dplyr::starts_with("Rep_", ignore.case = FALSE)), ~ (. - .data$optimal)^2) %>% + dplyr::mutate(measure = dplyr::select(., -c("method", "sample", "optimal", "sig")) %>% rowMeans() %>% sqrt()) + + + if (measure == "CV") { + # Calculate Coefficient of Variation (CV) with RMSE + dat <- dat %>% + dplyr::mutate(measure = measure / mean_rep) + } + + dat <- dat %>% dplyr::select(c("method", "sample", "sig", "measure")) } else { ## MAE diff --git a/docs/news/index.html b/docs/news/index.html index bd373b15..6747035d 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -125,11 +125,12 @@

Changelog

Source: NEWS.md -
+

-sigminer 1.1.0 Unreleased +sigminer 1.1.0 Unreleased

-
+

-sigminer 1.0.19 2020-09-28 +sigminer 1.0.19 2020-09-28

    -
  • Added more specific reference signatures from SigProfiler, e.g. SBS_mm9.
  • +
  • Added more specific reference signatures from SigProfiler, e.g. SBS_mm9.
  • Supported data.frame as input object for sig in get_sig_similarity() and sig_fit().
  • Modified g_label option in show_group_distribution() to better control group names.
  • Added test option and variable checking in show_cor().
  • @@ -154,18 +155,18 @@

  • Added options in show_group_distribution() to control segments.
-
+

-sigminer 1.0.18 Unreleased +sigminer 1.0.18 Unreleased

  • Fixed bugs when outputing only 1 signatures.
  • Fixed label inverse bug in add_labels(), thanks to TaoTao for reporting.
-
+

-sigminer 1.0.17 Unreleased +sigminer 1.0.17 Unreleased

  • Handled , seperated indices in show_cosmic_signatures.
  • @@ -174,9 +175,9 @@

  • Fixed default y axis title in show_sig_bootstrap_error(), now it is “Reconstruction error (L2 norm)”
-
+

-sigminer 1.0.16 2020-09-12 +sigminer 1.0.16 2020-09-12

  • Added auto_reduce option in sig_fit* functions to improve signature fitting.
  • @@ -191,9 +192,9 @@

  • Updated the copy number classification method.
-
+

-sigminer 1.0.15 Unreleased +sigminer 1.0.15 Unreleased

-
+

-sigminer 1.0.14 Unreleased +sigminer 1.0.14 Unreleased

  • Supported signature index separated by , in sig_fit() and sig_fit_bootstrap* functions.
  • @@ -217,9 +218,9 @@

  • Used package nnls instead of pracma for NNLS implementation in sig_fit().
-
+

-sigminer 1.0.13 2020-08-27 +sigminer 1.0.13 2020-08-27

  • Supported BSgenome.Hsapiens.1000genomes.hs37d5 in sig_tally().
  • @@ -228,9 +229,9 @@

  • Added letter_colors as an unexported discrete palette.
-
+

-sigminer 1.0.12 Unreleased +sigminer 1.0.12 Unreleased

-
+

-sigminer 1.0.11 Unreleased +sigminer 1.0.11 Unreleased

  • Added option to control the SigProfilerExtractor to avoid issue in docker image build.
-
+

-sigminer 1.0.10 Unreleased +sigminer 1.0.10 Unreleased

  • Some updates.
  • Compatible with SigProfiler 1.0.15
-
+

-sigminer 1.0.9 Unreleased +sigminer 1.0.9 Unreleased

  • Tried to speed up joining adjacent segments in read_copynumber(), got 200% improvement.
-
+

-sigminer 1.0.8 Unreleased +sigminer 1.0.8 Unreleased

-
+

-sigminer 1.0.7 2020-06-17 +sigminer 1.0.7 2020-06-17

  • Fixed bug in OsCN feature calculation.
  • @@ -301,9 +302,9 @@

  • Fixed bug about signature profile plotting for method ‘M’.
-
+

-sigminer 1.0.6 2020-06-01 +sigminer 1.0.6 2020-06-01

  • Added “scatter” in sig_fit() function to better visualize a few samples.
  • @@ -322,9 +323,9 @@

  • Added COSMIC TSB signatures.
-
+

-sigminer 1.0.5 2020-05-14 +sigminer 1.0.5 2020-05-14

  • Exported APOBEC result when the mode is ‘ALL’ in sig_tally().
  • @@ -333,9 +334,9 @@

  • Added strand feature to signature profile.
-
+

-sigminer 1.0.4 Unreleased +sigminer 1.0.4 Unreleased

  • Added profile plot for DBS and INDEL.
  • @@ -343,9 +344,9 @@

  • Fixed method ‘M’ for CN tally cannot work when cores > 1 (#161).
-
+

-sigminer 1.0.3 2020-04-30 +sigminer 1.0.3 2020-04-30

  • Added multiple methods for sig_fit().
  • @@ -358,27 +359,27 @@

  • Updated citation.
-
+

-sigminer 1.0.2 Unreleased +sigminer 1.0.2 Unreleased

  • Added merged transcript info for hg19 and hg38 build, this is availabe by data().
  • Added gene info for hg19 and hg38 build to extdata directory.
-
+

-sigminer 1.0.1 Unreleased +sigminer 1.0.1 Unreleased

  • Removed fuzzyjoin package from dependency.
  • Moved ggalluvial package to field suggsets.
-
+

-sigminer 1.0.0 2020-03-31 +sigminer 1.0.0 2020-03-31

All users, this is a break-through version of sigminer, most of functions have been modified, more features are implemented. Please read the reference list to see the function groups and their functionalities.

Please read the vignette for usage.

diff --git a/docs/reference/show_sig_bootstrap.html b/docs/reference/show_sig_bootstrap.html index 0f039ce0..fecdc46e 100644 --- a/docs/reference/show_sig_bootstrap.html +++ b/docs/reference/show_sig_bootstrap.html @@ -176,7 +176,7 @@

Show Signature Bootstrap Analysis Results

show_sig_bootstrap_stability( bt_result, signatures = NULL, - measure = c("RMSE", "MAE", "AbsDiff"), + measure = c("RMSE", "CV", "MAE", "AbsDiff"), methods = "QP", plot_fun = c("boxplot", "violin"), palette = "aaas", @@ -289,7 +289,7 @@

Arg measure -

measure to estimate the exposure instability, can be one of 'RMSE', 'MAE' and 'AbsDiff'.

+

measure to estimate the exposure instability, can be one of 'RMSE', 'CV', 'MAE' and 'AbsDiff'.

@@ -306,6 +306,7 @@

Details
  • show_sig_bootstrap_stability - this function plots the signature exposure instability for specified signatures. Currently, the instability measure supports 3 types:

    • 'RMSE' for Mean Root Squared Error (default) of bootstrap exposures and original exposures for each sample.

    • +
    • 'CV' for Coefficient of Variation (CV) based on RMSE (i.e. RMSE / btExposure_mean).

    • 'MAE' for Mean Absolute Error of bootstrap exposures and original exposures for each sample.

    • 'AbsDiff' for Absolute Difference between mean bootstram exposure and original exposure.

  • @@ -369,6 +370,8 @@

    Examp p5 p6 <- show_sig_bootstrap_stability(bt_result, methods = c("QP"), measure = "AbsDiff") p6 + p7 <- show_sig_bootstrap_stability(bt_result, methods = c("QP"), measure = "CV") + p7 } else { message("Please install package 'BSgenome.Hsapiens.UCSC.hg19' firstly!") } diff --git a/man/show_sig_bootstrap.Rd b/man/show_sig_bootstrap.Rd index 4dc7a8bc..1b94dc34 100644 --- a/man/show_sig_bootstrap.Rd +++ b/man/show_sig_bootstrap.Rd @@ -52,7 +52,7 @@ show_sig_bootstrap_error( show_sig_bootstrap_stability( bt_result, signatures = NULL, - measure = c("RMSE", "MAE", "AbsDiff"), + measure = c("RMSE", "CV", "MAE", "AbsDiff"), methods = "QP", plot_fun = c("boxplot", "violin"), palette = "aaas", @@ -123,7 +123,7 @@ c("top", "bottom", "left", "right", "none"). To remove the legend use legend = "none". Legend position can be also specified using a numeric vector c(x, y); see details section.} -\item{measure}{measure to estimate the exposure instability, can be one of 'RMSE', 'MAE' and 'AbsDiff'.} +\item{measure}{measure to estimate the exposure instability, can be one of 'RMSE', 'CV', 'MAE' and 'AbsDiff'.} } \value{ a \code{ggplot} object @@ -142,6 +142,7 @@ The error from optimal solution (the decomposition error from original input) is the instability measure supports 3 types: \itemize{ \item 'RMSE' for Mean Root Squared Error (default) of bootstrap exposures and original exposures for each sample. +\item 'CV' for Coefficient of Variation (CV) based on RMSE (i.e. \code{RMSE / btExposure_mean}). \item 'MAE' for Mean Absolute Error of bootstrap exposures and original exposures for each sample. \item 'AbsDiff' for Absolute Difference between mean bootstram exposure and original exposure. } @@ -198,6 +199,8 @@ if (require("BSgenome.Hsapiens.UCSC.hg19")) { p5 p6 <- show_sig_bootstrap_stability(bt_result, methods = c("QP"), measure = "AbsDiff") p6 + p7 <- show_sig_bootstrap_stability(bt_result, methods = c("QP"), measure = "CV") + p7 } else { message("Please install package 'BSgenome.Hsapiens.UCSC.hg19' firstly!") } diff --git a/tests/testthat/test-roxytest-testexamples-show_sig_bootstrap.R b/tests/testthat/test-roxytest-testexamples-show_sig_bootstrap.R index 2d7b6a1a..93ab9699 100644 --- a/tests/testthat/test-roxytest-testexamples-show_sig_bootstrap.R +++ b/tests/testthat/test-roxytest-testexamples-show_sig_bootstrap.R @@ -2,7 +2,7 @@ context("File R/show_sig_bootstrap.R: @testexamples") -test_that("[unknown alias] @ L99", { +test_that("[unknown alias] @ L103", { if (require("BSgenome.Hsapiens.UCSC.hg19")) { @@ -54,6 +54,8 @@ test_that("[unknown alias] @ L99", { p5 p6 <- show_sig_bootstrap_stability(bt_result, methods = c("QP"), measure = "AbsDiff") p6 + p7 <- show_sig_bootstrap_stability(bt_result, methods = c("QP"), measure = "CV") + p7 } else { message("Please install package 'BSgenome.Hsapiens.UCSC.hg19' firstly!") } @@ -64,5 +66,6 @@ test_that("[unknown alias] @ L99", { expect_s3_class(p4, "ggplot") expect_s3_class(p5, "ggplot") expect_s3_class(p6, "ggplot") + expect_s3_class(p7, "ggplot") })