From e1001f5b9e61d18822ac7317fdaa499b1b90b377 Mon Sep 17 00:00:00 2001 From: Soel Micheletti Date: Sat, 2 Sep 2023 16:07:40 +0200 Subject: [PATCH] Added COBRA method (#293) * 1.4.0 (#289) * add bioc information * update website * add crane and docs * update crane * update worflow * update crane * update workflows * update workflows * update workfolw * update workfolw * update workfolw * update workfolw * Update main.yml * Update main.yml * Update main.yml * fix lioness py * udpate lioness in R * include calculations python * update panda rm missing * update panda * update lioness joblib * revert commits * ALPACA fix to NAs in community assignement * version bump * revert lioness * update crane with alpaca changes * update lioness * update lioness python * fix test * update workflows * put back github actions * Fixed typo * Added LIONESS-pearson option + unit test * changed param labels in LIONESS example * updated docs for lioness() function * Update main.yml * Update main.yml * bump x.y.z version to even y prior to creation of RELEASE_3_15 branch * bump x.y.z version to odd y following creation of RELEASE_3_15 branch * Update DESCRIPTION * fix crane issue #240 * expanded PANDA and LIONESS description * update crane fix * added ALPACA, EGRET, and OTTER descriptions * Update README.md * typo in na.rm * update workflow * update workflow2 * fix-actions-3 * add r lib v2 * add r lib v2 * update condor test * update condor test * update condor test * update condor test * show testthat output * add pandoc and use cache * use built in check * use built in check * update actions with built in check * bump version * use built in coverage * use built in coverage * remove sudo * update actions * update actions * removed sudo from actions * ugrade to R42 * remove virtualenv * remove virtualenv * remove virtualenv * modify condor test * update condor test * update condor test * adding retiucualte to covr * adding retiucualte to covr * add panda test to coverignore * update actions * remove lioness tests from coverage * remove lioness tests from coverage * added MONSTER and SAMBAR * remove lionessR test * Added CONDOR and YARN * Update README.md * put back otter in rbuild * remove condor test * remove condor test * remove lioness docs * add lioness to buildingore * donttest lionesss * remove coverage from ubuntu test * remove rbuilignore * update rbuildignore * update rbuildignore * update rbuildignore * update rbuildignore * update rbuildignore * add back buildignore * add back buildignore * add back buildignore * add back buildignore * add back buildignore * add back buildignore * add back buildignore * add back buildignore * add back buildignore * add back buildignore * put back tests * add padanedge diff test * add back egeret test * add monster test * fix monster test * tolerance in expect equal * tolerance in expect equal * tolerance in expect equal * tolerance in expect equal * add sourceppi * fixed PANDA tests * modify panda test * update lioness test * fix expect message * update tests * update tests * update tests * update tests * update tests * update tests * reduced lioness test data * reduced lioness test data * reduced lioness test data * reduced lioness test data * reduce test size * updating bioc (#250) * updating bioc * remove empty lines * remove empty lines * update citation * update citation * update citation * Update README.md * Update README.md * Update main.yml * Update main.yml * Update .Rbuildignore * Update .Rbuildignore * update lioness test * removed two last lioness tests * removed two last lioness tests * removed two last lioness tests * no saving of lioness networks * no saving of lioness networks * no saving of lioness networks * no saving of lioness networks * update lioness test * lower sizeof test * update test data * update test data * update test data * reduce panda tests * remove old test data * remove old test data * Update main.yml * 1.1.16 update pandapy with header argument (#260) * trying collapse readme (#261) * trying collapse readme * collapse animal description * Update README.md * Fix news file formatting o was not rendering list properly * bump x.y.z version to even y prior to creation of RELEASE_3_16 branch * bump x.y.z version to odd y following creation of RELEASE_3_16 branch * update biconda (#265) * add spider (#269) * add spider * udpate spider * udpate spider * update spuder with degreeadjust * fix spider bug * DRAGON and unit tests work in progress (#267) - add DRAGON in R and unit tests * update lioness (#276) * update lioness code (#277) * Update LIONESS.R * Update LIONESS.R * Update LIONESS.R * add note about the function (#279) * add note about the function * Update sourcePPI.R * Update README.md * Update README.md * Update sourcePPI.R * Update sourcePPI.R * add details about sourcePPI (#280) * add parallelization option to lioness (#281) * 1.2.1 (#271) * add bioc information * update website * add crane and docs * update crane * update worflow * update crane * update workflows * update workflows * update workfolw * update workfolw * update workfolw * update workfolw * Update main.yml * Update main.yml * Update main.yml * fix lioness py * udpate lioness in R * include calculations python * update panda rm missing * update panda * update lioness joblib * revert commits * ALPACA fix to NAs in community assignement * version bump * revert lioness * update crane with alpaca changes * update lioness * update lioness python * fix test * update workflows * put back github actions * Fixed typo * Added LIONESS-pearson option + unit test * changed param labels in LIONESS example * updated docs for lioness() function * Update main.yml * Update main.yml * Update DESCRIPTION * fix crane issue #240 * expanded PANDA and LIONESS description * update crane fix * added ALPACA, EGRET, and OTTER descriptions * Update README.md * typo in na.rm * update workflow * update workflow2 * fix-actions-3 * add r lib v2 * add r lib v2 * update condor test * update condor test * update condor test * update condor test * show testthat output * add pandoc and use cache * use built in check * use built in check * update actions with built in check * bump version * use built in coverage * use built in coverage * remove sudo * update actions * update actions * removed sudo from actions * ugrade to R42 * remove virtualenv * remove virtualenv * remove virtualenv * modify condor test * update condor test * update condor test * adding retiucualte to covr * adding retiucualte to covr * add panda test to coverignore * update actions * remove lioness tests from coverage * remove lioness tests from coverage * added MONSTER and SAMBAR * remove lionessR test * Added CONDOR and YARN * Update README.md * put back otter in rbuild * remove condor test * remove condor test * remove lioness docs * add lioness to buildingore * donttest lionesss * remove coverage from ubuntu test * remove rbuilignore * update rbuildignore * update rbuildignore * update rbuildignore * update rbuildignore * update rbuildignore * add back buildignore * add back buildignore * add back buildignore * add back buildignore * add back buildignore * add back buildignore * add back buildignore * add back buildignore * add back buildignore * add back buildignore * put back tests * add padanedge diff test * add back egeret test * add monster test * fix monster test * tolerance in expect equal * tolerance in expect equal * tolerance in expect equal * tolerance in expect equal * add sourceppi * fixed PANDA tests * modify panda test * update lioness test * fix expect message * update tests * update tests * update tests * update tests * update tests * update tests * reduced lioness test data * reduced lioness test data * reduced lioness test data * reduced lioness test data * reduce test size * updating bioc (#250) * updating bioc * remove empty lines * remove empty lines * update citation * update citation * Update README.md * Update README.md * Update main.yml * Update main.yml * Update .Rbuildignore * Update .Rbuildignore * update lioness test * removed two last lioness tests * removed two last lioness tests * removed two last lioness tests * no saving of lioness networks * no saving of lioness networks * no saving of lioness networks * no saving of lioness networks * update lioness test * lower sizeof test * update test data * update test data * update test data * reduce panda tests * remove old test data * remove old test data * Update main.yml * 1.1.16 update pandapy with header argument (#260) * trying collapse readme (#261) * trying collapse readme * collapse animal description * Update README.md * update biconda (#265) * add spider (#269) * add spider * udpate spider * udpate spider * update spuder with degreeadjust * fix spider bug Co-authored-by: Kate Hoff Shutta Co-authored-by: katehoffshutta <43797774+katehoffshutta@users.noreply.github.com> * 1.2.2 (#273) - add DRAGON * add option to run lioness on multiple cores by using parallel::mclapply in place of lapply --------- Co-authored-by: Marouen Co-authored-by: Kate Hoff Shutta Co-authored-by: katehoffshutta <43797774+katehoffshutta@users.noreply.github.com> * fix monster error * fix monster * 1.3.2 * update tests * update bioc verssion * update monster test * update argument description * update argument description * changed date * updaate docs * update dragon verbose * update spider * add puma (#270) * add puma * update PUMA * updating mirna interactions * add PUMA in readme * Update PUMA.R * Create TIGER.R (#272) add TIGER.R * Add lioness update (#284) * update documentation * remove monster tests * reduce monstr test * update documentation * remove diffedge example * reduce monster tests * remove spider example * update monster examples * remove lioness tests * remove pada tests * add citation * update lioness append code * Update puma (#286) * update documentation * remove monster tests * reduce monstr test * update documentation * remove diffedge example * reduce monster tests * remove spider example * update monster examples * remove lioness tests * remove pada tests * add citation * fix puma examples * fix puma examples * update docs * Add TIGER (#283) * Create TIGER.R add TIGER.R * Add TIGER * compile TIGER 1. change the TIGER example to fit LazyData=F mode 2. document all the functions and required packages * DESCRIPTION depends Add cmdstanr to DESCRIPTION depends * onLoad install cmdstan * Update puma.Rd * Add data document --------- Co-authored-by: Marouen * Update DESCRIPTION * Add TIGER description to README file (#288) * Create TIGER.R add TIGER.R * Add TIGER * compile TIGER 1. change the TIGER example to fit LazyData=F mode 2. document all the functions and required packages * DESCRIPTION depends Add cmdstanr to DESCRIPTION depends * onLoad install cmdstan * Update puma.Rd * Add data document * Update README.md --------- Co-authored-by: Marouen --------- Co-authored-by: Kate Hoff Shutta Co-authored-by: Nitesh Turaga Co-authored-by: katehoffshutta <43797774+katehoffshutta@users.noreply.github.com> Co-authored-by: lshep Co-authored-by: J Wokaty Co-authored-by: Lauren Hsu <50427381+laurenhsu1@users.noreply.github.com> Co-authored-by: cchen22 <37237626+cchen22@users.noreply.github.com> * Added COBRA method --------- Co-authored-by: Marouen Co-authored-by: Kate Hoff Shutta Co-authored-by: Nitesh Turaga Co-authored-by: katehoffshutta <43797774+katehoffshutta@users.noreply.github.com> Co-authored-by: lshep Co-authored-by: J Wokaty Co-authored-by: Lauren Hsu <50427381+laurenhsu1@users.noreply.github.com> Co-authored-by: cchen22 <37237626+cchen22@users.noreply.github.com> --- DESCRIPTION | 5 +++-- R/COBRA.R | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 R/COBRA.R diff --git a/DESCRIPTION b/DESCRIPTION index aee01961..3f33aee1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -69,9 +69,10 @@ Imports: methods, dplyr, graphics, - cmdstanr, + cmdstanr, GeneNet, - loo + loo, + rARPACK License: GPL-3 Encoding: UTF-8 LazyData: false diff --git a/R/COBRA.R b/R/COBRA.R new file mode 100644 index 00000000..6b75dd74 --- /dev/null +++ b/R/COBRA.R @@ -0,0 +1,62 @@ +#' Run COBRA in R +#' +#' Description: +#' COBRA decomposes a (partial) gene co-expression matrix as a +#' linear combination of covariate-specific components. +#' It can be applied for batch correction, differential co-expression +#' analysis controlling for variables, and to understand the impact of +#' variables of interest to the observed co-expression. +#' +#' Inputs: +#' @param X : design matrix of size (n, q), n = number of samples, q = number of covariates +#' @param expressionData : gene expression as a matrix of size (g, n), g = number of genes +#' @param standardize : boolean flag to standardize the gene expression as a pre-processing step +#' +#' Outputs: +#' @return psi : impact of each covariate on the eigenvalues as a matrix of size (q, n) +#' @return Q : eigenvectors corresponding to non-zero eigenvalues as a list of length n +#' @return D : diagonal matrix of the original eigenvalues as a matrix of size (n, n) +#' @return G : (standardized) gene expression as a matrix of size (g, n) +#' +#' @examples +#' +#' g <- 100 # number of genes +#' n <- 10 # number of samples +#' q <- 2 # number of covariates +#' X <- X <- cbind(rep(1, n), rbinom(n, 1, 0.5)) +#' expressionData=matrix(rnorm(g*n, 1, 1), ncol = n, nrow = g) +#' +#' # Run COBRA algorithm +#' cobra_output <- cobra(X, expressionData) +#' +#' + +cobra <- function(X, expressionData, standardize=T){ + numSamples <- ncol(expressionData) + N <- min(ncol(expressionData),nrow(expressionData)) + + if (standardize){ + G_star <- expressionData-rowMeans(expressionData) + G <- (G_star/sqrt(rowSums(G_star^2))) + G <- as.matrix(G) + } else { + G <- expressionData + G <- (G/sqrt(rowSums(G^2))) + G <- as.matrix(G) + } + + eigenG <- eigs_sym(tcrossprod(G),N) + + Q <- eigenG$vectors + D <- diag(eigenG$values) + + hatmat <- ginv(crossprod(X))%*%t(X) + Qinv <- ginv(Q) + QinvG <- Qinv%*%(G) + + est <- t(sapply(seq_len(nrow(hatmat)), function(hatmatRow){ + diag(QinvG%*%(numSamples*diag(hatmat[hatmatRow,]))%*%t(QinvG)) + })) + + list(psi=est, Q=Q, D=eigenG$values, G=G) +} \ No newline at end of file