From b881b1f9815276c430144c8a46479420d48d521f Mon Sep 17 00:00:00 2001 From: chapmanb Date: Sun, 2 Dec 2018 06:22:12 -0500 Subject: [PATCH] Check for NAs during parameter estimation Avoids errors when running copy number estimation: ``` titan: Parameter estimation Optimal state path computation: Using 8 cores. Error in if (objfun[maxFind] >= objfun[i]) { : missing value where TRUE/FALSE needed Calls: outputTitanResults ... runEMclonalCN -> estimateClonalCNParamsMap -> updateParameters ``` I couldn't determine the underlying source of NAs when reading the code but put in defensive checks which avoids the issue. --- R/paramEstimation.R | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/R/paramEstimation.R b/R/paramEstimation.R index 9db2c4e..8193528 100644 --- a/R/paramEstimation.R +++ b/R/paramEstimation.R @@ -256,14 +256,15 @@ updateParameters <- function(n_0, s_0, var_0, varR_0, phi_0, corRho_0, chrPos_0, var_prev <- var varR_prev <- varR phi_prev <- phi - - if (objfun[maxFind] >= objfun[i]) { + + if (is.na(objfun[maxFind]) || is.na(objfun[i])) { + } else if (objfun[maxFind] >= objfun[i]) { #if (verbose) #message("Coordinate descent decreases likelihood.") - } else { + } else { maxFind <- i } - if ((abs(objfun[i] - objfun[i - 1])/abs(objfun[i])) <= 0.001) { + if (!is.na(objfun[i]) && (abs(objfun[i] - objfun[i - 1])/abs(objfun[i])) <= 0.001) { converged <- 1 } }