Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kate dev #241

Merged
merged 9 commits into from
Mar 1, 2022
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
33 changes: 25 additions & 8 deletions R/LIONESS.R
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,33 @@ lionessPy <- function(expr_file, motif_file=NULL, ppi_file=NULL, computing="cpu"
#' "coopNet" is the cooperative network
#' @examples
#' data(pandaToyData)
#' linonessRes <- lioness(pandaToyData$motif,
#' pandaToyData$expression[,1:3],pandaToyData$ppi,hamming=1,progress=FALSE)
#' lionessRes <- lioness(expr = pandaToyData$expression[,1:3], motif = pandaToyData$motif, ppi = pandaToyData$ppi,hamming=1,progress=FALSE)
#' @references
#' Kuijjer, M.L., Tung, M., Yuan, G., Quackenbush, J. and Glass, K., 2015.
#' Estimating sample-specific regulatory networks. arXiv preprint arXiv:1505.06440.
lioness <- function(motif,expr,ppi=NULL, network.inference.method, ...){
N <- ncol(expr)
lioness = function(expr, motif = NULL, ppi = NULL, network.inference.method = "panda", ...){
N <- ncol(expr)
if(network.inference.method == "panda")
{
fullnet <- panda(motif, expr, ppi, ...)
lapply(seq_len(N), function(i){
print(paste("Computing network for sample ",i))
N*fullnet@regNet - (N-1)* panda(motif, expr[,-i], ppi, ...)@regNet
})
return(lapply(seq_len(N), function(i) {
print(paste("Computing network for sample ", i))
N * fullnet@regNet - (N - 1) * panda(motif, expr[, -i],
ppi, ...)@regNet
}))
}
if(network.inference.method == "pearson")
{
fullnet <- cor(t(expr))

return(lapply(seq_len(N), function(i) {
print(paste("Computing network for sample ", i))
N * fullnet - (N - 1) * cor(t(expr[,-i]))
}))
}
if(!(network.inference.method %in% c("panda","pearson")))
{
stop(paste(c("The method",network.inference.method,"is not yet supported."),collapse=" "))
geterrmessage()
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ devtools::check()
```

The master branch on github should always be in good shape, so please to pull request to the **devel** branch.
If the contribution is specific to pandaR, please contribute to its seperate GitHub page by [pull request](https://github.com/jnpaulson/pandaR).
If the contribution is specific to pandaR, please contribute to its separate GitHub page by [pull request](https://github.com/jnpaulson/pandaR).

## License
The software is free and is licensed under the GNU General License v3.0, see the file [LICENSE](LICENSE) for details.
Expand Down
15 changes: 10 additions & 5 deletions man/lioness.Rd

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

50 changes: 50 additions & 0 deletions tests/testthat/test-lioness.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,55 @@ test_that("lionessPy() function works", {

})

test_that("lioness() function works for network.inference.method = 'panda'", {

print("[LIONESS] lioness() This test needs to be implemented!")
# expect_equal(1,-1) # dummy test failure
})

test_that("lioness() function works for network.inference.method = 'pearson'", {

# create toy data
x1 = c(1,1,2,3)
x2 = c(1,2,3,4)
X = matrix(c(x1,x2),ncol=2,byrow=F)

# extract correlation networks needed for LIONESS
fullNet = cor(X)
subNet1 = cor(X[-1,])
subNet2 = cor(X[-2,])
subNet3 = cor(X[-3,])
subNet4 = cor(X[-4,])

# construct LIONESS sample-specific correlation networks manually
N = 4
ssNet1 = N*(fullNet-subNet1) + subNet1
ssNet2 = N*(fullNet-subNet2) + subNet2
ssNet3 = N*(fullNet-subNet3) + subNet3
ssNet4 = N*(fullNet-subNet4) + subNet4

# run LIONESS on the toy data
lionessNets = lioness(expr=t(X),network.inference.method="pearson")

# assert equal
# there is no file I/O or rounding here
# so differences should be machine zero in R
expect_equal(lionessNets[[1]],ssNet1,tolerance=1e-15)
expect_equal(lionessNets[[2]],ssNet2,tolerance=1e-15)
expect_equal(lionessNets[[3]],ssNet3,tolerance=1e-15)
expect_equal(lionessNets[[4]],ssNet4,tolerance=1e-15)

})

test_that("lioness() function throws appropriate error for undefined network.inference.method", {

# create toy data
x1 = c(1,1,2,3)
x2 = c(1,2,3,4)
X = matrix(c(x1,x2),ncol=2,byrow=F)

# run LIONESS on the toy data w/undefined method
expect_error(lioness(expr=t(X),network.inference.method="divination"))

})