Skip to content

Commit 1c83c8a

Browse files
authored
Merge pull request #18 from leaffur/working
pre-filtering improvement
2 parents 2380e37 + 702bdf3 commit 1c83c8a

5 files changed

Lines changed: 39 additions & 15 deletions

File tree

CASE_R_package.Rproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Version: 1.0
2+
ProjectId: 2241ace3-378b-4e48-bb0a-ef8f1b97ac60
23

34
RestoreWorkspace: Default
45
SaveWorkspace: Default

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: CASE
33
Title: Cell-type-specific And Shared EQTL fine-mapping
4-
Version: 0.3.0
4+
Version: 0.3.1
55
Authors@R: c(
66
person("Chen", "Lin", , "c.lin@yale.edu", role = c("aut", "cre"),
77
comment = c(ORCID = "0000-0001-9821-2578")),
@@ -18,7 +18,7 @@ Imports:
1818
mvtnorm,
1919
stats
2020
Encoding: UTF-8
21-
RoxygenNote: 7.3.1
21+
RoxygenNote: 7.3.2
2222
Suggests:
2323
knitr,
2424
rmarkdown,

R/CASE.R

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,30 @@ CASE <- function(Z = NULL, R, hatB = NULL, hatS = NULL, N, V = NULL, cs = TRUE,
8181
hatS = hatBS$hatS
8282

8383
# V = estimate_null_correlation_simple(mash_set_data(do.call(rbind, raw.data$hatB), do.call(rbind, raw.data$hatS)))
84-
85-
m1 <- CASE_train(hatB = hatB, hatS = hatS, V = V, R = R, N = N, Z = NULL, verbose = verbose, ...)
84+
sump = 2 - 2 * pnorm(abs(hatB / hatS))
85+
sumfdr = apply(sump, 2, function(x) p.adjust(x, method = "fdr"))
86+
C = ncol(sumfdr)
87+
88+
# no strong signals in all cell types, or low SNP numbers
89+
if (sum(sumfdr <= 0.2) == 0){
90+
if (verbose){
91+
cat("No FDR-significant variants in the inputs.", "\n")
92+
}
93+
m1 = list(pi = 1, n.iter = 0)
94+
} else if (nrow(sump) <= 20){
95+
if (verbose){
96+
cat("Too few SNPs in the data (<=20).", "\n")
97+
}
98+
m1 = list(pi = 1, n.iter = 0)
99+
} else{
100+
m1 <- CASE_train(hatB = hatB, hatS = hatS, V = V, R = R, N = N, Z = NULL, verbose = verbose, ...)
101+
}
86102

87103
res <- CASE_test(hatB = hatB, hatS = hatS, R = R, N = N, CASE_training = m1, Z = NULL, verbose = verbose, ...)
88104
t2 = Sys.time()
89105
res$time = difftime(t2, t1, units = "secs")
90106
if (cs){
91-
res$sets <- get_credible_sets(res$pip, R = R, verbose = verbose)
107+
res$sets <- get_credible_sets(pips = res$pip, R = R, verbose = verbose)
92108
}
93109

94110
return(res)

R/CASE_models.R

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,17 @@ CASE_train <- function(Z = NULL, R, hatB = NULL, hatS = NULL, N, V = NULL, verbo
8080
## Train with only marginally significant SNPs
8181
M0 = nrow(R)
8282
ME_p <- 2 - 2 * pnorm(abs(hatB / hatS), 0, 1)
83-
significant_thres = ifelse("significant_thres" %in% names(args), args$significant_thres, 1e-1)
84-
idx <- which(ME_p <= significant_thres, arr.ind = TRUE)[, 1] %>% unique
83+
significant_thres = ifelse("significant_thres" %in% names(args),
84+
args$significant_thres,
85+
ifelse(sqrt(6) / sqrt(diag(N)) >= 0.05, sqrt(6) / sqrt(diag(N)), 0.05))
86+
if (C == 1){
87+
idx <- which(ME_p <= significant_thres)
88+
} else{
89+
idx <- which(t(apply(ME_p, 1, function(x) x <= significant_thres)), arr.ind = TRUE)[, 1] %>% unique
90+
}
91+
8592
if (length(idx) == 1){
86-
idx = c(idx - 1, idx, idx + 1)
93+
idx = idx + (-2):2
8794
idx = idx[idx >= 1 & idx <= nrow(hatB)]
8895
}
8996
hatB = hatB[idx, ]
@@ -96,7 +103,7 @@ CASE_train <- function(Z = NULL, R, hatB = NULL, hatS = NULL, N, V = NULL, verbo
96103
if (verbose){
97104
cat("No marginally significant variants in the inputs.", "\n")
98105
}
99-
return(list(pi = 1, U = list(matrix(0, C, C)), V = V, n.iter = 0))
106+
return(list(pi = 1, n.iter = 0))
100107
}
101108

102109
J <- 0
@@ -310,10 +317,6 @@ CASE_test <- function(Z = NULL, R, hatB = NULL, hatS = NULL, N, CASE_training, v
310317
cat("Start Posterior Analysis.", "\n")
311318
}
312319

313-
U = CASE_training$U
314-
V = CASE_training$V
315-
pi = CASE_training$pi
316-
317320
if (is.null(Z)){
318321
Z = hatB / hatS
319322
}
@@ -322,15 +325,19 @@ CASE_test <- function(Z = NULL, R, hatB = NULL, hatS = NULL, N, CASE_training, v
322325
hatBS = transform_Z(Z, N)
323326
hatB = hatBS$hatB
324327
hatS = hatBS$hatS
325-
328+
326329
C <- ncol(hatB)
327330
M <- nrow(R)
328331

332+
pi = CASE_training$pi
329333
if (length(pi) <= 1){
330334
post_mean = pip = matrix(0, M, C)
331-
return(list(pi = pi, U = U, V = V, pip = pip, post_mean = post_mean))
335+
return(list(pip = pip, post_mean = post_mean))
332336
}
333337

338+
U = CASE_training$U
339+
V = CASE_training$V
340+
334341
L = length(U)
335342
## MC step
336343
gBc = gB_coef(U, V)

data/example_data.rda

7 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)