File: get_sig_start.R

package info (click to toggle)
r-bioc-mutationalpatterns 3.16.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,360 kB
  • sloc: sh: 8; makefile: 2
file content (43 lines) | stat: -rw-r--r-- 1,241 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#' Determine the number of significance stars
#'
#' The number of significance stars is determined based on the statistical value
#' and the significance cutoffs.
#'
#' @param val Statistical value. Either a p value or fdr.
#' @param cutoffs Significance cutoffs for the statistical value.
#'
#' @return A vector of significance stars and empty strings (not significant).
#' @noRd
#'
.get_sig_star <- function(val, cutoffs) {

  # Get name of cutoffs argument
  cutoffs_name <- deparse(substitute(cutoffs))

  # Validate cutoff argument
  if (length(cutoffs) > 3) {
    stop(paste0("The length of the ", cutoffs_name, " argument can't be higher than 3."),
      call. = FALSE
    )
  }

  if (!all.equal(cutoffs, sort(cutoffs, decreasing = TRUE))) {
    stop(paste0("The ", cutoffs_name, " argument should be in decreasing order."),
      call. = FALSE
    )
  }

  # Add -Infs to cutoffs if the length is lower than 3.
  # Since a val cant be lower than -Inf, these cutoffs will never be reached.
  cutoffs <- c(cutoffs, rep(-Inf, 3 - length(cutoffs)))


  # Determine significance level
  stars <- dplyr::case_when(
    val < cutoffs[3] ~ "***",
    val < cutoffs[2] ~ "**",
    val < cutoffs[1] ~ "*",
    TRUE ~ ""
  )
  return(stars)
}