Skip to content

Commit

Permalink
silent mode
Browse files Browse the repository at this point in the history
  • Loading branch information
nicola-calonaci committed Aug 7, 2024
1 parent 6e33166 commit 05288f0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
9 changes: 5 additions & 4 deletions R/compute_posterior.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ compute_posterior = function(NV,
purity,
entropy_cutoff,
rho = 0.01,
karyotypes)
karyotypes,
silent = FALSE)
{
NV_x = 1:DP

Expand All @@ -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)
}
Expand Down Expand Up @@ -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,
Expand All @@ -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()
Expand Down
12 changes: 7 additions & 5 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -199,23 +199,25 @@ 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)
}

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')
}

Expand Down

0 comments on commit 05288f0

Please sign in to comment.