Skip to content

Commit

Permalink
Merge branch 'silence-writeMixtureInfo' into develop
Browse files Browse the repository at this point in the history
* silence-writeMixtureInfo:
  Added verbose argument to writeMixtureInfo()
  Increment version number to 0.0.0.9023
  • Loading branch information
wleoncio committed Sep 11, 2023
2 parents e3f14ee + ceaf7ec commit bde3be6
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 43 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
2 changes: 1 addition & 1 deletion R/greedyMix.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 ==========================================================
Expand Down
77 changes: 37 additions & 40 deletions R/writeMixtureInfo.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"))
Expand All @@ -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"))
}
Expand Down Expand Up @@ -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")
Expand All @@ -108,7 +110,7 @@ writeMixtureInfo <- function(
}
}
if (any(text != "")) {
cat(text)
if (verbose) cat(text)
if (fid != -1) {
append(fid, text)
append(fid, "\n")
Expand All @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -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) {
Expand All @@ -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")
Expand Down Expand Up @@ -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, " ")
Expand Down Expand Up @@ -282,18 +282,15 @@ writeMixtureInfo <- function(
" ",
as.character(partitionSummary[part, 2])
)
cat(line)
if (verbose) cat(line)
if (fid != -1) {
append(fid, line)
append(fid, "\n")
}
}

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")
Expand Down Expand Up @@ -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")
Expand Down
5 changes: 4 additions & 1 deletion man/writeMixtureInfo.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bde3be6

Please sign in to comment.