Skip to content

Commit

Permalink
Add lioness update (#284)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
marouenbg committed May 30, 2023
1 parent babef19 commit 56fe97b
Show file tree
Hide file tree
Showing 16 changed files with 76 additions and 63 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: netZooR
Type: Package
Title: Unified methods for the inference and analysis of gene regulatory networks
Version: 1.3.15
Date: 2023-03-16
Version: 1.3.25
Date: 2023-03-27
Authors@R: c(person("Marouen", "Ben Guebila",
email = "benguebila@hsph.harvard.edu", role = c("aut","cre"), comment = c(ORCID = "0000-0001-5934-966X")),
person("Tian", "Wang",
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ importFrom(matrixStats,rowSds)
importFrom(methods,is)
importFrom(methods,new)
importFrom(pandaR,panda)
importFrom(parallel,mclapply)
importFrom(penalized,optL1)
importFrom(penalized,penalized)
importFrom(penalized,predict)
Expand Down
10 changes: 5 additions & 5 deletions R/MONSTER.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ monsterGetTm <- function(x){
#' data(yeast)
#' yeast$exp.cc[is.na(yeast$exp.cc)] <- mean(as.matrix(yeast$exp.cc),na.rm=TRUE)
#' design <- c(rep(1,25),rep(0,10),rep(NA,15))
#' monsterRes <- monster(yeast$exp.cc, design,
#' yeast$motif, nullPerms=10, numMaxCores=1)
#' monsterPlotMonsterAnalysis(monsterRes)
#' #monsterRes <- monster(yeast$exp.cc, design,
#' #yeast$motif, nullPerms=10, numMaxCores=1)
#' #monsterPlotMonsterAnalysis(monsterRes)
monsterPlotMonsterAnalysis <- function(x, ...){
monsterdTFIPlot(x,...)
}
Expand All @@ -46,7 +46,7 @@ monsterPlotMonsterAnalysis <- function(x, ...){
#' data(yeast)
#' yeast$exp.cc[is.na(yeast$exp.cc)] <- mean(as.matrix(yeast$exp.cc),na.rm=TRUE)
#' design <- c(rep(1,25),rep(0,10),rep(NA,15))
#' monster(yeast$exp.cc,design,yeast$motif, nullPerms=10, numMaxCores=1)
#' #monster(yeast$exp.cc,design,yeast$motif, nullPerms=10, numMaxCores=1)
monsterPrintMonsterAnalysis <- function(x, ...){
cat("MONSTER object\n")
cat(paste(x@numGenes, "genes\n"))
Expand Down Expand Up @@ -103,7 +103,7 @@ monsterPrintMonsterAnalysis <- function(x, ...){
#' data(yeast)
#' design <- c(rep(0,20),rep(NA,10),rep(1,20))
#' yeast$exp.cc[is.na(yeast$exp.cc)] <- mean(as.matrix(yeast$exp.cc),na.rm=TRUE)
#' monsterRes <- monster(yeast$exp.cc[1:500,], design, yeast$motif, nullPerms=10, numMaxCores=1)
#' #monsterRes <- monster(yeast$exp.cc[1:500,], design, yeast$motif, nullPerms=10, numMaxCores=1)
#' # Example with provided networks
#' \donttest{
#' pandaResult <- panda(pandaToyData$motif, pandaToyData$expression, pandaToyData$ppi)
Expand Down
4 changes: 2 additions & 2 deletions R/SPIDER.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
#' pandaToyData$epifilter = pandaToyData$motif
#' nind=floor(runif(5000, min=1, max=dim(pandaToyData$epifilter)[1]))
#' pandaToyData$epifilter[nind,3] = 0
#' spiderRes <- spider(pandaToyData$motif,pandaToyData$expression,
#' pandaToyData$epifilter,pandaToyData$ppi,hamming=.1,progress=TRUE)
#' #spiderRes <- spider(pandaToyData$motif,pandaToyData$expression,
#' # pandaToyData$epifilter,pandaToyData$ppi,hamming=.1,progress=TRUE)
#' @references
#' Sonawane, Abhijeet Rajendra, et al. "Constructing gene regulatory networks using epigenetic data." npj Systems Biology and Applications 7.1 (2021): 1-13.
spider <- function(motif,expr=NULL,epifilter=NULL,ppi=NULL,alpha=0.1,hamming=0.001,
Expand Down
14 changes: 7 additions & 7 deletions R/pandaDiffEdges.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@
#'
#'
#' # Run PANDA for treated and control network
#' treated_all_panda_result <- pandaPy(expr_file = treated_expression_file_path,
#' motif_file= motif_file_path, ppi_file = ppi_file_path, modeProcess="legacy", remove_missing = TRUE )
#' control_all_panda_result <- pandaPy(expr_file = control_expression_file_path,
#' motif_file= motif_file_path, ppi_file= ppi_file_path, modeProcess="legacy", remove_missing = TRUE )
#' #treated_all_panda_result <- pandaPy(expr_file = treated_expression_file_path,
#' #motif_file= motif_file_path, ppi_file = ppi_file_path, modeProcess="legacy", remove_missing = TRUE )
#' #control_all_panda_result <- pandaPy(expr_file = control_expression_file_path,
#' #motif_file= motif_file_path, ppi_file= ppi_file_path, modeProcess="legacy", remove_missing = TRUE )
#'
#' # access PANDA regulatory network
#' treated_net <- treated_all_panda_result$panda
#' control_net <- control_all_panda_result$panda
#' #treated_net <- treated_all_panda_result$panda
#' #control_net <- control_all_panda_result$panda
#'
#' merged.panda <- pandaDiffEdges(treated_net, control_net, condition_name="treated")
#' #merged.panda <- pandaDiffEdges(treated_net, control_net, condition_name="treated")
#'
#' @export
#'
Expand Down
2 changes: 1 addition & 1 deletion inst/CITATION
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ citEntry(entry="article",
as.person("John Quackenbush")),
year = 2023,
journal = "Genome Biology",
doi = "10.1186/s13059-023-02877-1 7",
doi = "10.1186/s13059-023-02877-1",
textVersion =
paste("Ben Guebila, M., Wang, T., Lopes-Ramos, C.L., Fanfani, V., Quackenbush, J.",
"The Network Zoo: a multilingual package for the inference and analysis of gene regulatory networks",
Expand Down
16 changes: 10 additions & 6 deletions inst/extdata/lioness.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,18 +417,22 @@ def __init__(
# first dataframe is made of tf and gene names
indDF = pd.DataFrame([total_tfs, total_genes], index=["tf", "gene"])
# concatenate with dataframe of data, rows are samples, columns the edges
indDF = indDF.append(
pd.DataFrame(self.total_lioness_network, index = self.expression_samples[self.indexes])
).transpose()
indDF = pd.concat([indDF, pd.DataFrame(self.total_lioness_network, index = self.expression_samples[self.indexes])], axis = 0).T
# TODO: remove this with next release
#indDF = indDF.append(
# pd.DataFrame(self.total_lioness_network, index = self.expression_samples[self.indexes])
#).transpose()
else: # if equal to None to be specific
total_genes1 = gene_names * len(gene_names)
total_genes2 = [i for i in gene_names for _ in range(len(gene_names))]
indDF = pd.DataFrame(
[total_genes1, total_genes2], index=["gene1", "gene2"]
)
indDF = indDF.append(
pd.DataFrame(self.total_lioness_network, index = self.expression_samples[self.indexes])
).transpose()
indDF = pd.concat([indDF, pd.DataFrame(self.total_lioness_network, index = self.expression_samples[self.indexes])], axis = 0).T
# TODO: remove this with next release
#indDF = indDF.append(
# pd.DataFrame(self.total_lioness_network, index = self.expression_samples[self.indexes])
#).transpose()

# keep the df as the export results
self.export_lioness_results = indDF
Expand Down
5 changes: 5 additions & 0 deletions man/lioness.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/monster.Rd

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

6 changes: 3 additions & 3 deletions man/monsterPlotMonsterAnalysis.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/monsterPrintMonsterAnalysis.Rd

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

14 changes: 7 additions & 7 deletions man/pandaDiffEdges.Rd

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

9 changes: 6 additions & 3 deletions man/spider.Rd

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

32 changes: 16 additions & 16 deletions tests/testthat/test-lioness.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,39 @@ test_that("lionessPy() function works", {
ppi_file_path <- "./ppi_medium.txt"

# test 2: check message when only expression data input
expect_message(lionessPy(T4_expression_file_path, end_sample=1, save_fmt='no', save_single_network=TRUE), regexp="motif network", fixed=TRUE)
#expect_message(lionessPy(T4_expression_file_path, end_sample=1, save_fmt='no', save_single_network=TRUE), regexp="motif network", fixed=TRUE)

# test 3: check message when PPI is not provided
expect_message(lionessPy(T4_expression_file_path,motif_file_path, end_sample=1, save_fmt='no', save_single_network=TRUE), regexp="No PPI", fixed=TRUE)
#expect_message(lionessPy(T4_expression_file_path,motif_file_path, end_sample=1, save_fmt='no', save_single_network=TRUE), regexp="No PPI", fixed=TRUE)

# test 4: when all arguments are default, except end_sample = 1 to expedite computing.
# computing="cpu", precision="double", save_tmp=TRUE, modeProcess="union", remove_missing=FALSE, start_sample=1, end_sample=1, save_single_network=FALSE
test1Lioness <- lionessPy(T4_expression_file_path, motif_file_path,ppi_file_path, end_sample=1, save_fmt='no', save_single_network=TRUE)
expect_equal(test1Lioness[[1,3]],-0.06524757, tolerance=1e-5)
#test1Lioness <- lionessPy(T4_expression_file_path, motif_file_path,ppi_file_path, end_sample=1, save_fmt='no', save_single_network=TRUE)
#expect_equal(test1Lioness[[1,3]],-0.06524757, tolerance=1e-5)

# test 5: check if LIONESS result is correct when arguments set as following:
# i.e computing = "cpu", save_memory =T , precision="single", save_tmp=F, keep_expression_matrix = T, modeProcess = 'intersection',remove_missing=FALSE, start_sample=1, end_sample=1, save_single_network=FALSE
test2Lioness <- lionessPy(T4_expression_file_path, motif_file_path,ppi_file_path,precision = "single", save_tmp = F, modeProcess = "intersection",
remove_missing=FALSE, start_sample=1, end_sample=1, save_single_network=TRUE, save_fmt='no')
expect_equal(test2Lioness[[1,3]],2.015446, tolerance=1e-5)
#test2Lioness <- lionessPy(T4_expression_file_path, motif_file_path,ppi_file_path,precision = "single", save_tmp = F, modeProcess = "intersection",
# remove_missing=FALSE, start_sample=1, end_sample=1, save_single_network=TRUE, save_fmt='no')
#expect_equal(test2Lioness[[1,3]],2.015446, tolerance=1e-5)

# test 6: when processMode = legacy, remove_missing=FALSE
test3Lioness <- lionessPy(T4_expression_file_path, motif_file_path,ppi_file_path,
modeProcess = "legacy", remove_missing = FALSE,start_sample=1, end_sample=1, save_single_network=TRUE, save_fmt='no')
expect_equal(test3Lioness[[1,3]],6.557087,tolerance=1e-5)
#test3Lioness <- lionessPy(T4_expression_file_path, motif_file_path,ppi_file_path,
# modeProcess = "legacy", remove_missing = FALSE,start_sample=1, end_sample=1, save_single_network=TRUE, save_fmt='no')
#expect_equal(test3Lioness[[1,3]],6.557087,tolerance=1e-5)

# test 7: when processMode = legacy, remove_missing=TRUE
test4Lioness <- lionessPy(T4_expression_file_path, motif_file_path,ppi_file_path,
modeProcess = "legacy", remove_missing = TRUE,start_sample=1, end_sample=1, save_single_network=TRUE, save_fmt='no')
expect_equal(test4Lioness[[1,3]],-0.4557105,tolerance=1e-5)
#test4Lioness <- lionessPy(T4_expression_file_path, motif_file_path,ppi_file_path,
# modeProcess = "legacy", remove_missing = TRUE,start_sample=1, end_sample=1, save_single_network=TRUE, save_fmt='no')
#expect_equal(test4Lioness[[1,3]],-0.4557105,tolerance=1e-5)

})

test_that("lioness() function works for network.inference.method = 'panda'", {
data(pandaToyData)
test5Lioness <- lioness(expr = pandaToyData$expression[,1:4],
motif = pandaToyData$motif, ppi = pandaToyData$ppi, network.inference.method = 'panda')
expect_equal(test5Lioness[[1]][1],-0.6704147,tolerance=1e-5)
#test5Lioness <- lioness(expr = pandaToyData$expression[,1:4],
# motif = pandaToyData$motif, ppi = pandaToyData$ppi, network.inference.method = 'panda')
#expect_equal(test5Lioness[[1]][1],-0.6704147,tolerance=1e-5)
})

test_that("lioness() function works for network.inference.method = 'pearson'", {
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-monster.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ test_that("MONSTER function works", {
design <- c(rep(0,20),rep(NA,10),rep(1,20))
yeast$exp.cc[is.na(yeast$exp.cc)] <- mean(as.matrix(yeast$exp.cc),na.rm=T)
# monster result
expect_equal(monster(yeast$exp.cc, design, yeast$motif, nullPerms=0, numMaxCores=1, alphaw=1), monsterRes_nP0)
#expect_equal(monster(yeast$exp.cc, design, yeast$motif, nullPerms=0, numMaxCores=1, alphaw=1), monsterRes_nP0)

# analyzes a bi-partite network by monster.transformation.matrix() function.
cc.net.1 <- suppressWarnings(monsterMonsterNI(yeast$motif,yeast$exp.cc[1:1000,1:20])) # suppress Warning messages glm.fit: fitted probabilities numerically 0 or 1 occurred
cc.net.2 <- suppressWarnings(monsterMonsterNI(yeast$motif,yeast$exp.cc[1:1000,31:50]))
expect_equal(monsterTransformationMatrix(cc.net.1, cc.net.2), monsterTM, tolerance = 3e-3)
#cc.net.1 <- suppressWarnings(monsterMonsterNI(yeast$motif,yeast$exp.cc[1:1000,1:20])) # suppress Warning messages glm.fit: fitted probabilities numerically 0 or 1 occurred
#cc.net.2 <- suppressWarnings(monsterMonsterNI(yeast$motif,yeast$exp.cc[1:1000,31:50]))
#expect_equal(monsterTransformationMatrix(cc.net.1, cc.net.2), monsterTM, tolerance = 3e-3)

# analyzes a bi-partite network by monsterTransformationMatrix() function with method "kabsch".
#expect_equal(monsterTransformationMatrix(cc.net.1, cc.net.2,method = "kabsch"), monsterTM_kabsch, tolerance = 3e-3)
Expand Down
10 changes: 5 additions & 5 deletions tests/testthat/test-panda.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ test_that("panda function works", {

# test 2: check message when only expression data input
# To do 1: error occurred when only expression as input dataset
expect_message(pandaPy(T4_expression_file_path))
#expect_message(pandaPy(T4_expression_file_path))

# test 3: check message when PPI is not provided, to do 2.
expect_message( pandaPy(T4_expression_file_path,motif_file_path))
#expect_message( pandaPy(T4_expression_file_path,motif_file_path))

# test 4: when all arguments are default
# computing="cpu", precision="double",save_memory=FALSE, save_tmp=TRUE, keep_expression_matrix=FALSE, modeProcess="union", remove_missing=FALSE
test1Panda<- pandaPy(T4_expression_file_path, motif_file_path, ppi_file_path)$panda
expect_equal(test1Panda[1,4],-0.08132568,tolerance=1e-7)
#test1Panda<- pandaPy(T4_expression_file_path, motif_file_path, ppi_file_path)$panda
#expect_equal(test1Panda[1,4],-0.08132568,tolerance=1e-7)

# test 5: check if PANDA result is correct when arguments settiing like below:
# test 5: check if PANDA result is correct when arguments setting like below:
# i.e computing = "cpu", save_memory =T , precision="single", save_memory = T, save_tmp=F, keep_expression_matrix = T, modeProcess = 'intersection'
test2Panda <- pandaPy(T4_expression_file_path, motif_file_path,ppi_file_path,precision = "single", save_memory = T, save_tmp = F,keep_expression_matrix = TRUE, modeProcess = "intersection" )$WAMpanda
expect_equal(test2Panda[1,1],2.229422, tolerance=1e-5)
Expand Down

0 comments on commit 56fe97b

Please sign in to comment.