From fa2381411f69586e53dca56b5eb72028fcb444c6 Mon Sep 17 00:00:00 2001 From: Waldir Leoncio Date: Mon, 11 Sep 2023 13:54:52 +0200 Subject: [PATCH 1/2] Increment version number to 0.0.0.9023 --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index de86792..412b0fe 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: rBAPS Title: Bayesian Analysis of Population Structure -Version: 0.0.0.9022 +Version: 0.0.0.9023 Date: 2020-11-09 Authors@R: c( From ceaf7eca4b3dd8a0018cb0e3378ca13fd92bb35a Mon Sep 17 00:00:00 2001 From: Waldir Leoncio Date: Mon, 11 Sep 2023 14:06:45 +0200 Subject: [PATCH 2/2] Added verbose argument to writeMixtureInfo() --- R/greedyMix.R | 2 +- R/writeMixtureInfo.R | 77 ++++++++++++++++++++--------------------- man/writeMixtureInfo.Rd | 5 ++- 3 files changed, 42 insertions(+), 42 deletions(-) diff --git a/R/greedyMix.R b/R/greedyMix.R index 6642290..53f3270 100644 --- a/R/greedyMix.R +++ b/R/greedyMix.R @@ -69,7 +69,7 @@ greedyMix <- function( # Writing mixture info ======================================================= changesInLogml <- writeMixtureInfo( logml, c[["rowsFromInd"]], c[["data"]], c[["adjprior"]], c[["priorTerm"]], - NULL, inp, partitionSummary, popnames, fixedK + NULL, inp, partitionSummary, popnames, fixedK, verbose ) # Updateing results ========================================================== diff --git a/R/writeMixtureInfo.R b/R/writeMixtureInfo.R index 54e4556..97f2401 100644 --- a/R/writeMixtureInfo.R +++ b/R/writeMixtureInfo.R @@ -10,9 +10,10 @@ #' @param partitionSummary partitionSummary #' @param popnames popnames #' @param fixedK fixedK +#' @param verbose if \code{TRUE}, prints extra output information writeMixtureInfo <- function( logml, rowsFromInd, data, adjprior, priorTerm, outPutFile, inputFile, - partitionSummary, popnames, fixedK + partitionSummary, popnames, fixedK, verbose ) { changesInLogml <- list() ninds <- size(data, 1) / rowsFromInd @@ -30,15 +31,16 @@ writeMixtureInfo <- function( message("Output saved to", outPutFile) sink(outPutFile, split = TRUE) # save in text anyway. } - - dispLine() - cat("RESULTS OF INDIVIDUAL LEVEL MIXTURE ANALYSIS:\n") - cat("Data file: ", inputFile, "\n") - cat("Model: independent\n") - cat("Number of clustered individuals: ", ownNum2Str(ninds), "\n") - cat("Number of groups in optimal partition: ", ownNum2Str(npops), "\n") - cat("Log(marginal likelihood) of optimal partition: ", ownNum2Str(logml), "\n") - cat(" ") + if (verbose) { + dispLine() + cat("RESULTS OF INDIVIDUAL LEVEL MIXTURE ANALYSIS:\n") + cat("Data file: ", inputFile, "\n") + cat("Model: independent\n") + cat("Number of clustered individuals: ", ownNum2Str(ninds), "\n") + cat("Number of groups in optimal partition: ", ownNum2Str(npops), "\n") + cat("Log(marginal likelihood) of optimal partition: ", ownNum2Str(logml), "\n") + cat(" ") + } if (fid != -1) { append(fid, "RESULTS OF INDIVIDUAL LEVEL MIXTURE ANALYSIS:\n") append(fid, c("Data file: ", inputFile, "\n")) @@ -64,7 +66,7 @@ writeMixtureInfo <- function( } cluster_count <- length(unique(PARTITION)) - cat("Best Partition: ") + if (verbose) cat("Best Partition: ") if (fid != -1) { append(fid, c("Best Partition: ", "\n")) } @@ -96,7 +98,7 @@ writeMixtureInfo <- function( # Take one line and display it. new_line <- takeLine(text, 58) text <- (length(new_line) + 1):length(text) - cat(new_line) + if (verbose) cat(new_line) if (fid != -1) { append(fid, new_line) append(fid, "\n") @@ -108,7 +110,7 @@ writeMixtureInfo <- function( } } if (any(text != "")) { - cat(text) + if (verbose) cat(text) if (fid != -1) { append(fid, text) append(fid, "\n") @@ -117,12 +119,14 @@ writeMixtureInfo <- function( } if (npops > 1) { - cat("\n") - cat("\n") - cat( - "Changes in log(marginal likelihood)", - " if indvidual i is moved to group j:\n" - ) + if (verbose) { + cat("\n") + cat("\n") + cat( + "Changes in log(marginal likelihood)", + " if indvidual i is moved to group j:\n" + ) + } if (fid != -1) { append(fid, " ") append(fid, "\n") @@ -155,7 +159,7 @@ writeMixtureInfo <- function( for (i in 1:cluster_count) { ekarivi <- c(ekarivi, ownNum2Str(i), blanks(8 - floor(log10(i)))) } - cat(ekarivi) + if (verbose) cat(ekarivi) if (fid != -1) { append(fid, ekarivi) append(fid, "\n") @@ -175,16 +179,13 @@ writeMixtureInfo <- function( for (j in 1:npops) { rivi <- c(rivi, " ", logml2String(omaRound(muutokset[j]))) } - cat(rivi) + if (verbose) cat(rivi) if (fid != -1) { append(fid, rivi) append(fid, "\n") } } - - cat("\n") - cat("\n") - cat("KL-divergence matrix in PHYLIP format:\n") + if (verbose) cat("\n\nKL-divergence matrix in PHYLIP format:\n") dist_mat <- zeros(npops, npops) if (fid != -1) { @@ -210,7 +211,7 @@ writeMixtureInfo <- function( d[, , pop1] <- squeezed_COUNTS_prior / sum(squeezed_COUNTS_prior) } ekarivi <- as.character(npops) - cat(ekarivi) + if (verbose) cat(ekarivi) if (fid != -1) { append(fid, ekarivi) append(fid, "\n") @@ -238,20 +239,19 @@ writeMixtureInfo <- function( for (pop2 in 1:npops) { rivi <- c(rivi, kldiv2str(dist_mat[pop1, pop2])) } - cat(rivi) + if (verbose) cat(rivi) if (fid != -1) { append(fid, rivi) append(fid, "\n") } } } - - cat("\n") - cat("\n") - cat( - "List of sizes of 10 best visited partitions", - "and corresponding log(ml) values\n" - ) + if (verbose) { + cat( + "\n\nList of sizes of 10 best visited partitions", + "and corresponding log(ml) values\n" + ) + } if (fid != -1) { append(fid, " ") @@ -282,7 +282,7 @@ writeMixtureInfo <- function( " ", as.character(partitionSummary[part, 2]) ) - cat(line) + if (verbose) cat(line) if (fid != -1) { append(fid, line) append(fid, "\n") @@ -290,10 +290,7 @@ writeMixtureInfo <- function( } if (!fixedK) { - cat("\n") - cat("\n") - cat("Probabilities for number of clusters\n") - + if (verbose) cat("\n\nProbabilities for number of clusters\n") if (fid != -1) { append(fid, " ") append(fid, "\n") @@ -324,7 +321,7 @@ writeMixtureInfo <- function( line <- c( as.character(npopsTaulu[i]), " ", as.character(probs[i]) ) - cat(line, "\n") + if (verbose) cat(line, "\n") if (fid != -1) { append(fid, line) append(fid, "\n") diff --git a/man/writeMixtureInfo.Rd b/man/writeMixtureInfo.Rd index f30bde0..10f424d 100644 --- a/man/writeMixtureInfo.Rd +++ b/man/writeMixtureInfo.Rd @@ -14,7 +14,8 @@ writeMixtureInfo( inputFile, partitionSummary, popnames, - fixedK + fixedK, + verbose ) } \arguments{ @@ -37,6 +38,8 @@ writeMixtureInfo( \item{popnames}{popnames} \item{fixedK}{fixedK} + +\item{verbose}{if \code{TRUE}, prints extra output information} } \description{ Writes information about the mixture