Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
^README_cache$
^README_files$
^LICENSE\.md$
^data-raw$
18 changes: 12 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: CASE
Title: Cell-type-specific And Shared EQTL fine-mapping
Version: 0.2.1
Version: 0.2.2
Authors@R: c(
person("Chen", "Lin", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-9821-2578")),
Expand All @@ -16,12 +16,18 @@ Imports:
magrittr,
MASS,
mvtnorm,
stats,
CorBin,
mvsusieR,
susieR
stats
Encoding: UTF-8
RoxygenNote: 7.3.1
Suggests:
testthat (>= 3.0.0)
knitr,
rmarkdown,
testthat (>= 3.0.0),
scales,
ggplot2,
susieR
Config/testthat/edition: 3
Depends:
R (>= 2.10)
LazyData: true
VignetteBuilder: knitr
7 changes: 0 additions & 7 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,14 @@ export(CASE)
export(CASE_test)
export(CASE_train)
export(get_credible_sets)
importFrom(CorBin,cBern)
importFrom(MASS,ginv)
importFrom(magrittr,"%>%")
importFrom(mvsusieR,create_mixture_prior)
importFrom(mvsusieR,mvsusie_rss)
importFrom(mvtnorm,rmvnorm)
importFrom(stats,cor)
importFrom(stats,cov2cor)
importFrom(stats,lm)
importFrom(stats,p.adjust)
importFrom(stats,pnorm)
importFrom(stats,qchisq)
importFrom(stats,qnorm)
importFrom(stats,quantile)
importFrom(stats,rmultinom)
importFrom(stats,rnorm)
importFrom(stats,sd)
importFrom(susieR,susie_rss)
52 changes: 0 additions & 52 deletions R/Example.R

This file was deleted.

12 changes: 12 additions & 0 deletions R/data.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#' Example Data
#'
#' An example data of three traits for the CASE fine-mapping illustration.
#'
#' @format ## `example_data`
#' A list contains 3 elements:
#' \describe{
#' \item{Y}{500 by 3 matrix of phenotype.}
#' \item{X}{500 by 1000 matrix of genotype. This is created by R package `CorBin`}
#' \item{B}{1000 by 3 matrix of eQTL effects. Only the 10th and 950th SNPs have eQTL effects.}
#' }
"example_data"
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
# CASE: Cell-type-specific And Shared EQTL Fine-mapping

`CASE` is a R package for multi-trait fine-mapping analysis, focusing on single-cell eQTL fine-mapping.
`CASE` is an R package designed for multi-trait fine-mapping analysis, with a particular focus on single-cell eQTL fine-mapping.

## 1. Installation

``` r
#install.packages("devtools")
# Install the devtools package if you haven't already
# install.packages("devtools")

devtools::install_github("leaffur/CASE")
```

## 2. Quick Start

After `library(CASE)` in R, please use `?CASE` command for simple examples.
For an introductory overview, please refer to the vignettes provided in the package.

After loading the package with `library(CASE)`, you can access simple examples and guidance using the `?CASE` command in R.

This is an early version of CASE, and we welcome any feedback or suggestions for improvement.
24 changes: 24 additions & 0 deletions data-raw/example_data.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## code to prepare `example_data` dataset goes here
library(CorBin)

set.seed(1024)
N = 500
M = 1000
C = 3

X = cbind(cBern(N, rep(0.3, M/4), rho = 0.95, type = "DCP"),
cBern(N, rep(0.3, M/2), rho = 0.85, type = "DCP"),
cBern(N, rep(0.3, M/4), rho = 0.98, type = "DCP"))

B = matrix(0, M, C)
idx1 = 10
idx2 = 950
B[idx1, ] = c(sqrt(0.3), sqrt(0.2), sqrt(0.1))
B[idx2, ] = c(sqrt(0.25), sqrt(0.15), 0)

e = matrix(rnorm(N * C), N, C)
Y = X %*% B + e

example_data = list(Y = Y, X = X, B = B)

usethis::use_data(example_data, overwrite = TRUE)
Binary file added data/example_data.rda
Binary file not shown.
22 changes: 22 additions & 0 deletions man/example_data.Rd

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

2 changes: 2 additions & 0 deletions vignettes/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.html
*.R
104 changes: 104 additions & 0 deletions vignettes/Introduction_to_CASE.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
---
title: "Introduction to CASE for multi-trait fine-mapping"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Introduction_to_CASE}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```

This Vignette is a draft and will be further updated.

First, load necessary packages.

```{r setup}
library(CASE)
library(ggplot2)
library(susieR)
```

```{r}
data("example_data")
X = example_data$X
Y = example_data$Y
B = example_data$B

N = nrow(X)
M = ncol(X)
C = ncol(Y)
cat("sample size =", N, "\n",
"SNP size =", M, "\n",
"Cell type number =", C, "\n")
```

Let's have a look at how the Linkage Disequilibrium (LD) of the example data looks like.

```{r}
R = cor(X)

df <- expand.grid(seq(M), seq(M))
df$corr <- as.vector(R)

g2 = ggplot(df, aes(x = Var1, y = Var2, fill = corr)) +
geom_tile() +
scale_fill_gradient2(low = "blue", mid = "white", high = "red", limits = c(-1, 1),
midpoint = 0, na.value = NA,
guide = guide_colorbar(
barwidth = 1, barheight = 7, title.position = "top", oob = scales::oob_squish
)
) +
xlab("") +
ylab("") +
theme(aspect.ratio = 1, axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5),
strip.background = element_rect(fill = "white", color = "white"),
panel.border = element_rect(colour = "black", fill = NA,
linewidth = 1),
strip.text = element_text(color = "black", size = 20),
text = element_text(size = 20)) +
labs(fill = "corr")
print(g2)
```

```{r}
print(which(B != 0, arr.ind = TRUE))
idx1 = 10
idx2 = 950
B[c(idx1, idx2), ]
```

```{r}
Z = matrix(0, M, C)
for (i in 1:M){
m1 = summary(lm(Y ~ X[, i]))
Z[i, ] = sapply(m1, function(x) x$coefficients[2, 3])
}
Z[c(idx1, idx2), ]
```

Run SuSiE (a single-trait fine-mapping method) seperately.

```{r}
for (c in 1:C){
f1 = susie_rss(z = Z[, c], R = R, n = N)
print(f1$sets)
}
```

Jointly studying three traits together improves the power of identifying the causal variants.

```{r}
fit <- CASE(Z = Z, R = R, N = rep(N, C))
print(fit$sets)
```


```{r}
sessionInfo()
```
Loading