Skip to content

Commit ece6df3

Browse files
authored
Merge pull request #371 from taraeicher/cmdstanr_patch
Made dependency on cmdstanr conditional, fixed other minor issues
2 parents 39d014e + 071b450 commit ece6df3

File tree

16 files changed

+211
-78
lines changed

16 files changed

+211
-78
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ jobs:
7070
python3 -m venv env
7171
source env/bin/activate
7272
echo "VIRTUAL ENV:" $VIRTUAL_ENV
73-
73+
7474
- name: Install reticulate
7575
run: |
7676
library("reticulate")

DESCRIPTION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: netZooR
22
Type: Package
33
Title: A menagerie of Methods for the inference and analysis of gene regulatory networks
4-
Version: 1.6.2
4+
Version: 1.6.3
55
Date: 2024-11-26
66
Authors@R: c(person("Tara", "Eicher",
77
email = "teicher@hsph.harvard.edu", role = c("aut"), comment = c(ORCID = "0000-0003-1809-4458")),
@@ -71,7 +71,6 @@ Imports:
7171
methods,
7272
dplyr,
7373
graphics,
74-
cmdstanr,
7574
GeneNet,
7675
loo,
7776
rARPACK,
@@ -95,8 +94,9 @@ Suggests:
9594
rmarkdown,
9695
pkgdown,
9796
dorothea,
97+
cmdstanr
9898
VignetteEngine: knitr
9999
VignetteBuilder: knitr
100-
RoxygenNote: 7.3.2
100+
RoxygenNote: 7.3.3
101101
BugReports: https://github.com/netZoo/netZooR/issues
102102
URL: https://github.com/netZoo/netZooR, https://netzoo.github.io/

R/CONDOR.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#' matrices in memory. Useful on a machine with low RAM. However, runtimes
2626
#' are (much) longer.
2727
#' @param deltaQmin convergence parameter determining the minimum required increase
28-
#' in the modularity for each iteration. Default is min(10^{-4},1/(number of edges)),
28+
#' in the modularity for each iteration. Default is min(10^(-4),1/(number of edges)),
2929
#' with number of edges determined by \code{nrow(condor.object$edges)}. User can
3030
#' set this parameter by passing a numeric value to deltaQmin.
3131
#' @return \code{condor.object} with \code{\link{condorModularityMax}} output

R/DRAGON.R

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -363,14 +363,12 @@ estimate_p_values_dragon = function(r, n, p1, p2, lambdas, kappa="estimate",seed
363363
#' @param gradient : method for estimating parameters of p-value distribution, applies only if p-val == TRUE. default = "finite_difference"; other option = "exact"
364364
#' @param verbose : verbosity level (TRUE/FALSE)
365365
#' @return A list of model results. cov : the shrunken covariance matrix
366-
#' \itemize{
367-
#' \item{\code{cov}}{ the shrunken covariance matrix}
368-
#' \item{\code{prec}}{ the shrunken precision matrix}
369-
#' \item{\code{ggm}}{ the shrunken Gaussian graphical model; matrix of partial correlations. Self-edges (diagonal elements) are set to zero.}
370-
#' \item{\code{lambdas}}{ Vector of omics-specific tuning parameters (lambda1, lambda2) for \code{layer1} and \code{layer2}}
371-
#' \item{\code{gammas}}{ Reparameterized tuning parameters; gamma = 1 - lambda^2}
372-
#' \item{\code{risk_grid}}{ Risk grid, for assessing optimization. Grid boundaries are in terms of gamma.}
373-
#' }
366+
#' \item{\code{cov}}{ the shrunken covariance matrix}
367+
#' \item{\code{prec}}{ the shrunken precision matrix}
368+
#' \item{\code{ggm}}{ the shrunken Gaussian graphical model; matrix of partial correlations. Self-edges (diagonal elements) are set to zero.}
369+
#' \item{\code{lambdas}}{ Vector of omics-specific tuning parameters (lambda1, lambda2) for \code{layer1} and \code{layer2}}
370+
#' \item{\code{gammas}}{ Reparameterized tuning parameters; gamma = 1 - lambda^2}
371+
#' \item{\code{risk_grid}}{ Risk grid, for assessing optimization. Grid boundaries are in terms of gamma.}
374372
#'
375373
#' @export
376374
dragon = function(layer1,layer2,pval = FALSE,gradient = "finite_difference", verbose = FALSE)

R/LIONESS.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ lionessPy <- function(expr_file, motif_file=NULL, ppi_file=NULL, computing="cpu"
164164
#' Options include "pearson".
165165
#' @param ncores int specifying the number of cores to be used. Default is 1.
166166
#' (Note: constructing panda networks can be memory-intensive, and the number of cores should take into consideration available memory.)
167-
#' @param union Aggregation mode between three input networks: Union (default), intersection, legacy (maps on motif network).
167+
#' @param mode 'legacy' refers to the processing mode in netZooPy<=0.5, 'union': takes the union of all TFs and genes across priors and fills the missing genes in the priors with zeros; 'intersection': intersects the input genes and TFs across priors and removes the missing TFs/genes. Default values is 'union'.
168168
#' @param ... additional arguments for panda analysis
169169
#' @keywords keywords
170170
#' @importFrom matrixStats rowSds

R/SEAHORSE.R

Lines changed: 50 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@
99
#' The measures of association
1010
#' for a numerical phenotype is Pearson correlation and
1111
#' for a categorical phenotype is the p-value of an ANOVA test
12-
#'
13-
#'
14-
#' Inputs:
12+
#'
13+
#' @import fgsea
1514
#' @param expression : gene expression matrix (normalized, and filtered)
1615
#' with rows as genes and columns as samples.
1716
#' Row and column names must be present.
@@ -24,7 +23,6 @@
2423
#' Types can be either "numeric" or "categorical"
2524
#' @param pathways : a list of pathways (e.g. KEGG, GO, Reactome etc.
2625
#' downloaded from http://www.gsea-msigdb.org/gsea/msigdb/human/collections.jsp)
27-
#'
2826
#' Outputs:
2927
#' @return results : a list containing three objects
3028
#' results$coexpression: a gene x gene Pearson correlation matrix.
@@ -41,7 +39,7 @@
4139
#' colnames(phenotype_data) = c("sex", "height")
4240
#' rownames(phenotype_data) = colnames(expression_data)
4341
#' phenotype_data$sex = c(rep("male", nrow(phenotype_data)/2), rep("female", nrow(phenotype_data)/2))
44-
#' phenotype_data$height = 65 + sample.int(10, nrow(phenotype_data), replace = T)
42+
#' phenotype_data$height = 65 + sample.int(10, nrow(phenotype_data), replace = TRUE)
4543
#'
4644
#' phenotype_dictionary = c("categorical", "numeric")
4745
#'
@@ -53,15 +51,46 @@
5351
#' # Run seahorse
5452
#' results <- seahorse(expression_data, phenotype_data, phenotype_dictionary, pathways)
5553
#'
56-
#'
57-
#'
58-
54+
#' @export
55+
seahorse <- function(expression, phenotype, phenotype_dictionary, pathways){
56+
set.seed(0)
57+
58+
results = list()
59+
60+
# Compute coexpression of genes
61+
results$coexpression = cor(t(expression), use="pairwise.complete.obs")
62+
63+
# Compute association of gene expression with phenotypes and run GSEA
64+
results$phenotype_association = list()
65+
results$GSEA = list()
66+
67+
for (i in 1:ncol(phenotype)){
68+
pheno = phenotype[,i]
69+
pheno_name = colnames(phenotype)[i]
70+
71+
if (phenotype_dictionary[i] == "numeric"){
72+
output_seahorse = gsea_numeric(expression, pheno, pathways)
73+
}else {output_seahorse = gsea_categorical(expression, pheno, pathways)}
74+
results$phenotype_association[[pheno_name]] = output_seahorse$cor
75+
results$GSEA[[pheno_name]] = output_seahorse$GSEA
76+
}
77+
return(results)
78+
}
5979

60-
# Function to run GSEA for a numeric phenotype
80+
#' Function to run GSEA for a numeric phenotype
81+
#' @param expression : gene expression matrix (normalized, and filtered)
82+
#' with rows as genes and columns as samples.
83+
#' Row and column names must be present.
84+
#' Row names must be HGNC symbols.
85+
#' Column names must match the row names of the phenotype matrix.
86+
#' @param pheno : phenotype matrix
87+
#' with rows as samples and columns as phenotype variables.
88+
#' @param pathways : a list of pathways (e.g. KEGG, GO, Reactome etc.
89+
#' downloaded from http://www.gsea-msigdb.org/gsea/msigdb/human/collections.jsp)
6190
#' @export
6291
#' @import fgsea
6392

64-
gsea_numeric <- function(expression, pheno, pathways, results){
93+
gsea_numeric <- function(expression, pheno, pathways){
6594
output_seahorse = list()
6695
output_seahorse$cor = list()
6796
output_seahorse$GSEA = list()
@@ -78,10 +107,19 @@ gsea_numeric <- function(expression, pheno, pathways, results){
78107
return(output_seahorse)
79108
}
80109

81-
# Function to run GSEA for a categorical phenotype
110+
#' Function to run GSEA for a categorical phenotype
82111
#' @import fgsea
112+
#' @param expression : gene expression matrix (normalized, and filtered)
113+
#' with rows as genes and columns as samples.
114+
#' Row and column names must be present.
115+
#' Row names must be HGNC symbols.
116+
#' Column names must match the row names of the phenotype matrix.
117+
#' @param pheno : phenotype matrix
118+
#' with rows as samples and columns as phenotype variables.
119+
#' @param pathways : a list of pathways (e.g. KEGG, GO, Reactome etc.
120+
#' downloaded from http://www.gsea-msigdb.org/gsea/msigdb/human/collections.jsp)
83121
#' @export
84-
gsea_categorical <- function(expression, pheno, pathways, results){
122+
gsea_categorical <- function(expression, pheno, pathways){
85123
output_seahorse = list()
86124
output_seahorse$cor = list()
87125
output_seahorse$GSEA = list()
@@ -96,32 +134,4 @@ gsea_categorical <- function(expression, pheno, pathways, results){
96134
output_seahorse$GSEA = fgseaRes
97135

98136
return(output_seahorse)
99-
}
100-
101-
# Main SEAHORSE function
102-
#' @import fgsea
103-
#' @export
104-
seahorse <- function(expression, phenotype, phenotype_dictionary, pathways){
105-
set.seed(0)
106-
107-
results = list()
108-
109-
# Compute coexpression of genes
110-
results$coexpression = cor(t(expression), use="pairwise.complete.obs")
111-
112-
# Compute association of gene expression with phenotypes and run GSEA
113-
results$phenotype_association = list()
114-
results$GSEA = list()
115-
116-
for (i in 1:ncol(phenotype)){
117-
pheno = phenotype[,i]
118-
pheno_name = colnames(phenotype)[i]
119-
120-
if (phenotype_dictionary[i] == "numeric"){
121-
output_seahorse = gsea_numeric(expression, pheno, pathways, results)
122-
}else {output_seahorse = gsea_categorical(expression, pheno, pathways, results)}
123-
results$phenotype_association[[pheno_name]] = output_seahorse$cor
124-
results$GSEA[[pheno_name]] = output_seahorse$GSEA
125-
}
126-
return(results)
127137
}

R/TIGER.R

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,12 @@
5353
#' @export
5454
#'
5555
#' @examples
56-
#' data(TIGER_expr)
57-
#' data(TIGER_prior)
58-
#' tiger(TIGER_expr,TIGER_prior)
56+
#' if (requireNamespace("cmdstanr", quietly = TRUE) && tryCatch({
57+
#' nzchar(cmdstanr::cmdstan_path())}, error = function(e) FALSE)) {
58+
#' data(TIGER_expr)
59+
#' data(TIGER_prior)
60+
#' tiger(TIGER_expr,TIGER_prior)
61+
#' }
5962
tiger = function(expr,prior,method="VB",TFexpressed = TRUE,
6063
signed=TRUE,baseline=TRUE,psis_loo = FALSE,
6164
seed=123,out_path=NULL,out_size = 300,

R/zzz.R

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
11

22
.onLoad <- function(...) {
3-
cmdstan_version <- cmdstanr::cmdstan_version(error_on_NA = FALSE)
4-
if (is.null(cmdstan_version)) {
5-
#stop("No CmdStan installation found. Run cmdstanr::install_cmdstan() to install.", call. = FALSE)
6-
cmdstanr::check_cmdstan_toolchain(fix = TRUE)
7-
cmdstanr::install_cmdstan()
8-
}
93
}

man/condorCluster.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/dragon.Rd

Lines changed: 6 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)