Skip to content

Commit

Permalink
Added COBRA method (#293)
Browse files Browse the repository at this point in the history
* 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 <kshutta@umass.edu>
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 <marouenbg@users.noreply.github.com>
Co-authored-by: Kate Hoff Shutta <kshutta@umass.edu>
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 <marouenbg@users.noreply.github.com>

* 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 <marouenbg@users.noreply.github.com>

---------

Co-authored-by: Kate Hoff Shutta <kshutta@umass.edu>
Co-authored-by: Nitesh Turaga <nitesh.turaga@gmail.com>
Co-authored-by: katehoffshutta <43797774+katehoffshutta@users.noreply.github.com>
Co-authored-by: lshep <lori.shepherd@roswellpark.org>
Co-authored-by: J Wokaty <jennifer.wokaty@sph.cuny.edu>
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 <marouenbg@users.noreply.github.com>
Co-authored-by: Kate Hoff Shutta <kshutta@umass.edu>
Co-authored-by: Nitesh Turaga <nitesh.turaga@gmail.com>
Co-authored-by: katehoffshutta <43797774+katehoffshutta@users.noreply.github.com>
Co-authored-by: lshep <lori.shepherd@roswellpark.org>
Co-authored-by: J Wokaty <jennifer.wokaty@sph.cuny.edu>
Co-authored-by: Lauren Hsu <50427381+laurenhsu1@users.noreply.github.com>
Co-authored-by: cchen22 <37237626+cchen22@users.noreply.github.com>
  • Loading branch information
9 people committed Sep 2, 2023
1 parent e92699b commit e1001f5
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ Imports:
methods,
dplyr,
graphics,
cmdstanr,
cmdstanr,
GeneNet,
loo
loo,
rARPACK
License: GPL-3
Encoding: UTF-8
LazyData: false
Expand Down
62 changes: 62 additions & 0 deletions R/COBRA.R
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit e1001f5

Please sign in to comment.