From 05288f024082e6bd96c4804057b200e8f2dc65c1 Mon Sep 17 00:00:00 2001 From: nicola-calonaci Date: Wed, 7 Aug 2024 15:10:32 +0200 Subject: [PATCH] silent mode --- R/compute_posterior.R | 9 +++++---- R/utils.R | 12 +++++++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/R/compute_posterior.R b/R/compute_posterior.R index c7198af..b5c623a 100644 --- a/R/compute_posterior.R +++ b/R/compute_posterior.R @@ -34,7 +34,8 @@ compute_posterior = function(NV, purity, entropy_cutoff, rho = 0.01, - karyotypes) + karyotypes, + silent = FALSE) { NV_x = 1:DP @@ -50,7 +51,7 @@ compute_posterior = function(NV, label = paste0(Major + minor, 'N (Mutated: ', p, "N)") if(is.data.frame(prior)){ - if(!(label %in% prior$label)) cli::cli_alert_danger("Incomplete prior distribution!") + if(!(label %in% prior$label) & !silent) cli::cli_alert_danger("Incomplete prior distribution!") stopifnot(label %in% prior$label) prior = prior %>% dplyr::filter(label == !!label) %>% dplyr::pull(p) } @@ -90,7 +91,7 @@ compute_posterior = function(NV, } if(is.na(purity)){ - cli_alert_warning(text = + if(!silent) cli_alert_warning(text = "With purity {.field {purity}} classification is not possible." ) return(dplyr::tibble(ploidy = NA, @@ -105,7 +106,7 @@ compute_posterior = function(NV, if (is.null(priors)){ prior = 1 } else { - prior = get_prior(priors, gene, tumor_type) + prior = get_prior(priors, gene, tumor_type, silent = silent) } posterior = lapply(karyotypes, function(k) { alleles = strsplit(k, split = ":")[[1]] %>% as.integer() diff --git a/R/utils.R b/R/utils.R index 99803d2..aaee142 100644 --- a/R/utils.R +++ b/R/utils.R @@ -199,14 +199,14 @@ get_gene_role = function(x, id){ # Prior getter -get_prior = function(x, gene, tumor_type){ +get_prior = function(x, gene, tumor_type, silent = FALSE){ - if(is.null(x)) { + if(is.null(x) & !silent) { cli::cli_alert("No prior probabilities provided") return(1) } - if(!(gene %in% x$gene)) { + if(!(gene %in% x$gene) & !silent) { cli::cli_alert("No prior probability specified for {.field {gene}}") return(1) } @@ -214,8 +214,10 @@ get_prior = function(x, gene, tumor_type){ if(tumor_type %in% (x %>% dplyr::filter(gene == !!gene) %>% dplyr::pull(tumor_type))) { out = x %>% dplyr::filter(gene == !!gene, tumor_type == !!tumor_type) } else { - cli::cli_alert("No {.field {tumor_type}}-specific prior probability specified for {.field {gene}}") - cli::cli_alert("Using a pan-cancer prior") + if(!silent){ + cli::cli_alert("No {.field {tumor_type}}-specific prior probability specified for {.field {gene}}") + cli::cli_alert("Using a pan-cancer prior") + } out = x %>% dplyr::filter(gene == !!gene, tumor_type == 'PANCA') }