Skip to content

Commit

Permalink
update_v1.0.2 (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
zmccaw-insitro authored Oct 21, 2024
1 parent fa3ec9e commit 1922a94
Show file tree
Hide file tree
Showing 15 changed files with 140 additions and 337 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: AllelicSeries
Title: Allelic Series Test
Version: 0.1.0.1
Version: 0.1.0.2
Authors@R:
c(person(given = "Zachary",
family = "McCaw",
Expand Down Expand Up @@ -33,7 +33,7 @@ LinkingTo:
Rcpp,
RcppArmadillo
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.2
Suggests:
knitr,
rmarkdown,
Expand Down
4 changes: 2 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ export(ASBTSS)
export(ASKAT)
export(ASKATSS)
export(Aggregator)
export(BaseCountsSS)
export(BaselineSS)
export(COAST)
export(COASTSS)
export(CalcSumstats)
export(Comparator)
export(Counts)
export(DGP)
export(GenomicControl)
export(IVWSS)
export(OLS)
export(SumCountSS)
export(isPD)
exportClasses(COAST)
exportClasses(DfOrNULL)
Expand Down
44 changes: 16 additions & 28 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,46 +105,34 @@ isPD <- function(x, force_symmetry = FALSE, tau = 1e-8) {
.Call(`_AllelicSeries_isPD`, x, force_symmetry, tau)
}

#' Inverse Variance Meta-Analysis
#'
#' @param anno (snps x 1) annotation vector with values in c(0, 1, 2).
#' @param beta (snps x 1) vector of effect sizes for
#' the coding genetic variants within a gene.
#' @param ld (snps x snps) matrix of correlations among the genetic variants.
#' @param se (snps x 1) vector of standard errors for the effect sizes.
#' @param weights (3 x 1) vector of annotation category weights.
#' @return Data.frame with the following columns \itemize{
#' \item anno: gene annotation
#' \item beta_meta: meta-analyzed effect size
#' \item se_meta: standard error of the meta-analyzed effect size
#' }
IVWCpp <- function(anno, beta, se, ld, weights) {
.Call(`_AllelicSeries_IVWCpp`, anno, beta, se, ld, weights)
AnnoMat <- function(anno) {
.Call(`_AllelicSeries_AnnoMat`, anno)
}

#' Category Correlation
#' Baseline Counts Test from Sumstats
#'
#' Calculates an estimate of the correlations across the total burdens
#' of rare variants within each category {BMV, DMV, PTV}. To enable this
#' calculation, an assumption of Hardy-Weinberg Equilibrium is made, which
#' was found to provide good performance empirically.
#'
#' @param anno (snps x 1) annotation vector with values in c(0, 1, 2).
#' @param anno (snps x 1) annotation vector.
#' @param beta (snps x 1) vector of effect sizes for
#' the coding genetic variants within a gene.
#' @param ld (snps x snps) matrix of correlations among the genetic variants.
#' @param maf (snps x 1) vector of minor allele frequencies.
CatCor <- function(anno, ld, maf) {
.Call(`_AllelicSeries_CatCor`, anno, ld, maf)
#' @param se (snps x 1) vector of standard errors for the effect sizes.
#' @return Numeric p-value.
#' @export
BaselineSS <- function(anno, beta, ld, se) {
.Call(`_AllelicSeries_BaselineSS`, anno, beta, ld, se)
}

#' Baseline Counts Test from Sumstats
#' Allelic Sum Test from Sumstats
#'
#' @param anno (snps x 1) annotation vector.
#' @param beta (snps x 1) vector of effect sizes for
#' the coding genetic variants within a gene.
#' @param ld (snps x snps) matrix of correlations among the genetic variants.
#' @param se (snps x 1) vector of standard errors for the effect sizes.
#' @param weights (3 x 1) vector of annotation category weights.
#' @return Numeric p-value.
#' @export
BaseCountsSS <- function(beta, ld, se) {
.Call(`_AllelicSeries_BaseCountsSS`, beta, ld, se)
SumCountSS <- function(anno, beta, ld, se, weights) {
.Call(`_AllelicSeries_SumCountSS`, anno, beta, ld, se, weights)
}

45 changes: 12 additions & 33 deletions R/allelic_series_sumstats.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ DEFAULT_WEIGHTS <- c(1, 2, 3)
#' @param maf (snps x 1) vector of minor allele frequencies. Although ideally
#' provided, defaults to the zero vector.
#' @param method Method for aggregating across categories:
#' {"none", "sum"}. Default: "none".
#' ("none", "sum"). Default: "none".
#' @param weights (3 x 1) vector of annotation category weights.
#' @return Numeric p-value of the allelic series burden test.
#' @examples
Expand Down Expand Up @@ -74,45 +74,24 @@ ASBTSS <- function(
if (is.null(maf)) {maf <- rep(0, n_snps)}
if (!is_pd) {ld <- ld + eps * diag(n_snps)}

# Per-category summary statistics.
category_sumstats <- IVWSS(
anno = anno,
beta = beta,
se = se,
ld = ld,
weights = weights
)

# Category correlation matrix.
r3 <- CatCor(anno = anno, ld = ld, maf = maf)
if (!isPD(r3)) {r3 <- r3 + eps * diag(3)}

# Run burden test.
if (method == "none") {

pval <- BaseCountsSS(
beta = category_sumstats$beta_meta,
ld = r3,
se = category_sumstats$se_meta
pval <- BaselineSS(
anno = anno,
beta = beta,
ld = ld,
se = se
)

} else if (method == "sum") {

key <- (category_sumstats$se_meta > 0)
n_nz <- sum(key)

gene_sumstats <- IVWSS(
anno = rep(0, n_nz),
beta = category_sumstats$beta_meta[key],
ld = r3[key, key, drop = FALSE],
se = category_sumstats$se_meta[key],
weights = rep(1, n_nz)
)

pval <- BaseCountsSS(
beta = gene_sumstats$beta_meta[1],
se = gene_sumstats$se_meta[1],
ld = diag(1)
pval <- SumCountSS(
anno = anno,
beta = beta,
ld = ld,
se = se,
weights = weights
)

} else {
Expand Down
6 changes: 3 additions & 3 deletions R/allelic_series_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ DEFAULT_WEIGHTS <- c(1, 2, 3)
#' @param drop_empty Drop empty columns? Default: TRUE.
#' @param indicator Convert raw counts to indicators? Default: FALSE.
#' @param method Method for aggregating across categories:
#' {"none", "max", "sum"}. Default: "none".
#' ("none", "max", "sum"). Default: "none".
#' @param min_mac Minimum minor allele count for inclusion. Default: 0.
#' @param weights Annotation category weights.
#' @return (n x 3) Numeric matrix without weighting, (n x 1) numeric matrix
Expand Down Expand Up @@ -104,8 +104,8 @@ Aggregator <- function(
#' @param covar (n x p) covariate matrix. Defaults to an (n x 1) intercept.
#' @param indicator Convert raw counts to indicators?
#' @param is_pheno_binary Is the phenotype binary? Default: FALSE.
#' @param method Method for aggregating across categories: {"none", "max",
#' "sum"}. Default: "none".
#' @param method Method for aggregating across categories: ("none", "max",
#' "sum"). Default: "none".
#' @param min_mac Minimum minor allele count for inclusion. Default: 0.
#' @param score_test Run a score test? If FALSE, performs a Wald test.
#' @param weights (3 x 1) annotation category weights.
Expand Down
42 changes: 0 additions & 42 deletions R/meta_analysis.R

This file was deleted.

4 changes: 2 additions & 2 deletions man/ASBT.Rd

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

2 changes: 1 addition & 1 deletion man/ASBTSS.Rd

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

2 changes: 1 addition & 1 deletion man/Aggregator.Rd

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

8 changes: 5 additions & 3 deletions man/BaseCountsSS.Rd → man/BaselineSS.Rd

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

21 changes: 0 additions & 21 deletions man/CatCor.Rd

This file was deleted.

37 changes: 0 additions & 37 deletions man/IVWSS.Rd

This file was deleted.

22 changes: 9 additions & 13 deletions man/IVWCpp.Rd → man/SumCountSS.Rd

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

Loading

0 comments on commit 1922a94

Please sign in to comment.