Skip to content

Commit 2019e21

Browse files
authored
Update CASE_models.R
1 parent a5c947d commit 2019e21

1 file changed

Lines changed: 29 additions & 16 deletions

File tree

R/CASE_models.R

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#' @param hatS M * C matrix of standard errors of the estimated effects. Alternative summary data (together with hatB) to be provided instead of Z.
1111
#' @param N either C vector of the sample size, or C * C matrix of the sample size (diagonal) and ovelaps (off-diagonal). If provided with a vector, CASE assumes that each pair of traits overlaps with their minimal sample size.
1212
#' @param V (optional) C * C covariance (correlation) matrix for the noise between traits. If not provided, the default is an identity matrix.
13+
#' @param verbose (optional) logical, whether to print logging information. Default = TRUE.
1314
#' @param ... additional arguments.
1415
#' @return A \code{"CASE_training"} object with the following elements:
1516
#' \item{pi:}{L-vector, the prior probabilities of sharing patterns.}
@@ -18,11 +19,12 @@
1819
#' @importFrom magrittr %>%
1920
#' @importFrom stats pnorm qchisq cov2cor
2021
#' @export
21-
CASE_train <- function(Z = NULL, R, hatB = NULL, hatS = NULL, N, V = NULL, ...){
22+
CASE_train <- function(Z = NULL, R, hatB = NULL, hatS = NULL, N, V = NULL, verbose = TRUE, ...){
2223
args = list(...)
23-
24-
cat("Start Prior fitting.", "\n")
25-
24+
25+
if (verbose){
26+
cat("Start Prior fitting.", "\n")
27+
}
2628
if (is.null(Z)){
2729
Z = hatB / hatS
2830
}
@@ -91,7 +93,9 @@ CASE_train <- function(Z = NULL, R, hatB = NULL, hatS = NULL, N, V = NULL, ...){
9193
pi.in = M1 / M0
9294
M <- nrow(R)
9395
if (M1 == 0){
94-
cat("No marginally significant variants in the inputs.", "\n")
96+
if (verbose){
97+
cat("No marginally significant variants in the inputs.", "\n")
98+
}
9599
return(list(pi = 1, U = list(matrix(0, C, C)), V = V, n.iter = 0))
96100
}
97101

@@ -103,8 +107,6 @@ CASE_train <- function(Z = NULL, R, hatB = NULL, hatS = NULL, N, V = NULL, ...){
103107

104108
# MCEM steps
105109
for (kk in 1:n.iter){
106-
# cat("\n iter:", kk, " ")
107-
108110
# E-step
109111
## MC step
110112
# init
@@ -137,7 +139,9 @@ CASE_train <- function(Z = NULL, R, hatB = NULL, hatS = NULL, N, V = NULL, ...){
137139
L = length(patterns)
138140

139141
if (L <= 1){
140-
cat("Estimates no eQTL effects in the CASE prior fitting step.", "\n")
142+
if (verbose){
143+
cat("Estimates no eQTL effects in the CASE prior fitting step.", "\n")
144+
}
141145
pi = 1
142146
names(pi) = patterns
143147
U = U[length(U)]
@@ -216,7 +220,9 @@ CASE_train <- function(Z = NULL, R, hatB = NULL, hatS = NULL, N, V = NULL, ...){
216220
}
217221

218222
if (length(pi) <= 1){
219-
cat("Estimated no eQTL effects in the CASE prior fitting step.", "\n")
223+
if (verbose){
224+
cat("Estimated no eQTL effects in the CASE prior fitting step.", "\n")
225+
}
220226
return(list(pi = pi, U = U, V = V, n.iter = kk, pi.in = pi.in, M1 = M1))
221227
}
222228

@@ -251,7 +257,9 @@ CASE_train <- function(Z = NULL, R, hatB = NULL, hatS = NULL, N, V = NULL, ...){
251257

252258
L = length(U)
253259
if (L <= 1){
254-
cat("Estimated no eQTL effects in the CASE prior fitting step.", "\n")
260+
if (verbose){
261+
cat("Estimated no eQTL effects in the CASE prior fitting step.", "\n")
262+
}
255263
return(list(pi = pi, U = U, V = V, n.iter = kk, pi.in = pi.in, M1 = M1))
256264
}
257265

@@ -283,6 +291,7 @@ CASE_train <- function(Z = NULL, R, hatB = NULL, hatS = NULL, N, V = NULL, ...){
283291
#' @param hatS M * C matrix of standard errors of the estimated effects. Alternative summary data (together with hatB) to be provided instead of Z.
284292
#' @param N either 1 or C vector of the sample size, or C * C matrix of the sample size (diagonal) and overlaps (off-diagonal). If provided with a vector, CASE assumes that each pair of traits overlaps with their minimal sample size.
285293
#' @param CASE_training A \code{"CASE_training"} object.
294+
#' @param verbose (optional) logical, whether to print logging information. Default = TRUE.
286295
#' @param ... additional arguments.
287296
#' @return A \code{"CASE"} object with the following elements:
288297
#' \item{pi:}{L-vector, the prior probabilities of sharing patterns.}
@@ -293,12 +302,14 @@ CASE_train <- function(Z = NULL, R, hatB = NULL, hatS = NULL, N, V = NULL, ...){
293302
#' @importFrom magrittr %>%
294303
#' @importFrom stats sd
295304
#' @export
296-
CASE_test <- function(Z = NULL, R, hatB = NULL, hatS = NULL, N, CASE_training, ...){
305+
CASE_test <- function(Z = NULL, R, hatB = NULL, hatS = NULL, N, CASE_training, verbose = TRUE, ...){
297306
# Here V is V adjusted for sample sizes
298307
#### Testing ####
299308
args = list(...)
300-
cat("Start Posterior Analysis.", "\n")
301-
309+
if (verbose){
310+
cat("Start Posterior Analysis.", "\n")
311+
}
312+
302313
U = CASE_training$U
303314
V = CASE_training$V
304315
pi = CASE_training$pi
@@ -365,15 +376,17 @@ CASE_test <- function(Z = NULL, R, hatB = NULL, hatS = NULL, N, CASE_training, .
365376
#' Obtain credible sets for any multi-trait fine-mapping results.
366377
#' @param pips (M * C),The pips of SNPs.
367378
#' @param R M * M matrix of LD.
379+
#' @param verbose (optional) logical, whether to print logging information. Default = TRUE.
368380
#' @param cor.min minimum correlation in the credible sets
369381
#' @param coverage_thres threshold for the sum of PIPs.
370382
#' @param ruled_out excluding SNPs with PIPs less than the threshold.
371383
#' @return a length C list of credible sets.
372384
#' @importFrom magrittr %>%
373385
#' @export
374-
get_credible_sets <- function(pips, R, cor.min = 0.5, coverage_thres = 0.95, ruled_out = 1e-4){
375-
cat("Start getting credible sets.", "\n")
376-
386+
get_credible_sets <- function(pips, R, verbose = TRUE, cor.min = 0.5, coverage_thres = 0.95, ruled_out = 1e-4){
387+
if (verbose){
388+
cat("Start getting credible sets.", "\n")
389+
}
377390
pips = as.matrix(pips)
378391
C = ncol(pips)
379392
css = vector("list", C)

0 commit comments

Comments
 (0)