Skip to content

Commit

Permalink
version 0.99.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Meng Xu authored and cran-robot committed Oct 11, 2023
0 parents commit 3580092
Show file tree
Hide file tree
Showing 75 changed files with 9,800 additions and 0 deletions.
31 changes: 31 additions & 0 deletions DESCRIPTION
@@ -0,0 +1,31 @@
Type: Package
Package: inferCSN
Title: Inferring Cell-Specific Gene Regulatory Network
Version: 0.99.0
Date: 2023-10-5
Authors@R:
person("Meng", "Xu", email = "mengxu98@qq.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-8300-1054"))
Maintainer: Meng Xu <mengxu98@qq.com>
Description: A method for inferring cell-specific gene regulatory network from single-cell sequencing data.
biocViews: CellBiology, GeneExpression
License: MIT + file LICENSE
URL: https://mengxu98.github.io/inferCSN/
BugReports: https://github.com/mengxu98/inferCSN/issues
Depends: R (>= 3.3.0)
Imports: ComplexHeatmap, data.table, doParallel, dplyr, foreach,
ggnetwork, ggplot2, ggraph, Matrix, methods, parallel,
patchwork, progress, purrr, Rcpp, stats, utils
Suggests: circlize, gtools, igraph, precrec, pROC, testthat (>= 3.0.0),
tidygraph
LinkingTo: Rcpp, RcppArmadillo
Config/Needs/website: mengxu98/mxtemplate
Config/testthat/edition: 3
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.2.3
Language: en-US
NeedsCompilation: yes
Packaged: 2023-10-11 10:12:14 UTC; MSI
Author: Meng Xu [aut, cre] (<https://orcid.org/0000-0002-8300-1054>)
Repository: CRAN
Date/Publication: 2023-10-11 18:20:02 UTC
2 changes: 2 additions & 0 deletions LICENSE
@@ -0,0 +1,2 @@
YEAR: 2023
COPYRIGHT HOLDER: Meng Xu
74 changes: 74 additions & 0 deletions MD5
@@ -0,0 +1,74 @@
4f85a6b11ecd75afdcce423ae15ef005 *DESCRIPTION
7c52ffa536a7ee404a1970079f438922 *LICENSE
b48ef5d987897d838df5226751680a0f *NAMESPACE
5e08e4dbc7bfa1bf575f7672aff13441 *R/RcppExports.R
4a8c3c169d90a573af79901ddb0ca2c9 *R/auc.calculate.R
ed324fe13967373f0ebff75d176d8d6b *R/compute.gene.rank.R
643ade498aab0c7b5410cb03dbb9a50d *R/data.R
569f9ac6273c770b4acbc3eb65b362fb *R/inferCSN-package.R
716a11cb5bd17fa513da07611efc9f3b *R/inferCSN.R
715a9aeffcf51cf83312d5c9d6ec328c *R/network.visualization.R
b4a2e0f8aea24b0352519f018bdd63e5 *R/sparse.regression.R
ef4b9e9703cb364732029f703ca9f1ce *R/utils.R
82246917ca7839687f6d51eb34f8eec0 *README.md
191a298ed75823937c77adad132f746b *data/exampleGroundTruth.rda
975775272629b1e1438f9c89883e7728 *data/exampleMatrix.rda
9b9c13ac9a7e999c4e4cdb362fc26e8e *man/acc.calculate.Rd
8380f5d6933f4f8e23c17f11c7c50423 *man/auc.calculate.Rd
ff07637def41124927f3c7f2c46f1bed *man/check.parameters.Rd
cd8c767751171c96e056e3d80893d6e8 *man/coef.inferCSN.Rd
18a544c85e9b0245e63f713998214767 *man/compute.gene.rank.Rd
0e2acac6074c6d1148f7157f2166271e *man/contrast.networks.Rd
7bead10dd1c0c7852051d259b0740edd *man/dynamic.networks.Rd
554c357e8f5247ccc09bb4b0230833c9 *man/exampleGroundTruth.Rd
1ec939db9239789791c034ef6bfd2265 *man/exampleMatrix.Rd
6311a5f421c0bbf0b94debea489ffb13 *man/figures/inferCSN.svg
34c2dd574f80faa89edea7cebdbb042c *man/inferCSN-package.Rd
54bbfb391679a8b0ca879d51303498c4 *man/inferCSN.Rd
814dd419ee7301a4e93848a20890ad01 *man/inferCSN.fit.Rd
af3a9d9f4bbf39e214377b9920d4d3b0 *man/is.scalar.Rd
0e559044dc2fe9b06b8d39132892e548 *man/net.format.Rd
447aa592fb38dba8e88937ed73204801 *man/network.heatmap.Rd
e9d98b090265e8645318543f37e8bf24 *man/predict.inferCSN.Rd
1b4a2a6e2c1eed3ca4a3a0003c5c97f6 *man/print.inferCSN.Rd
3fcd8c319587d585129534013633c858 *man/sparse.regression.Rd
73197635a9a5df894c4f5b4e88ca4e8c *man/sub.inferCSN.Rd
1e6750ed9d5f86b882e6a24591733b47 *src/BetaVector.cpp
dadb1987bfb2f80d199a2e25b02a051d *src/CDL012LogisticSwaps.cpp
64737baec03e2641f58d5681381874d6 *src/CDL012SquaredHingeSwaps.cpp
45e55da928a9a22670c9a7380e7469b1 *src/CDL012Swaps.cpp
b9f4edd41ee1ba186d768676b2bf79ee *src/DT2Matrix.cpp
d4f2e65104193ad8b04b23281a39cd8c *src/Grid.cpp
51b6baa37f71f76d69bc5e178c98b8a7 *src/Grid1D.cpp
8748c274ffef69c8dc7f2c0f88228b22 *src/Grid2D.cpp
09837ef4410ca3aa193eb60b7a8f681b *src/Interface.cpp
c2fbbe606dbc01e99513a08efa77bb27 *src/Makevars
c2fbbe606dbc01e99513a08efa77bb27 *src/Makevars.win
41bc93afdbfbce896558b943b882d7e7 *src/Normalize.cpp
bcd102094770a2e20628f6cb0dfc4684 *src/RcppExports.cpp
b8da420687f2f9943625f9c8cddda799 *src/Test_Interface.cpp
053756d599fb6942fb1959c5f54f4157 *src/include/BetaVector.h
d10d7cbeac8dd66edb8abfe537ba2e83 *src/include/CD.h
3006562807501591e7979d1b5af7c039 *src/include/CDL0.h
c9262d8cc37f5ad121511ab15f1ef234 *src/include/CDL012.h
da6865571ac3a696ef96d8d10c8b7c9a *src/include/CDL012Logistic.h
c36020aa6b5463f99a6265a18d745473 *src/include/CDL012LogisticSwaps.h
75978be275c2af4e57318dda1d2ee505 *src/include/CDL012SquaredHinge.h
6acf66ba1b050b4869097aa56ed7cb10 *src/include/CDL012SquaredHingeSwaps.h
8d625ee2d1001e5fbd827359787faa78 *src/include/CDL012Swaps.h
3c65caa73f70506f9914640898d13c6a *src/include/CDSwaps.h
3e191a22fe2bee08cfd53dd8cd32f8a1 *src/include/FitResult.h
fa0e95061a24b8e548c611d4304664d0 *src/include/Grid.h
1e34795fcfd7f91aa821223794050e00 *src/include/Grid1D.h
5155c4b89da70421f47b4e82a0111866 *src/include/Grid2D.h
29346ba8476c3664856ab8f5ae9ff180 *src/include/GridParams.h
3754bebf455414fb993fd10bfc967742 *src/include/Interface.h
68b70f6c4a8c08a8d7f6bb97746d3d49 *src/include/MakeCD.h
aea94cb863ab3243b5c681f9d905c175 *src/include/Model.h
8650499eeb16d4bf88397c8ed3c29c92 *src/include/Normalize.h
060e465c4585fd95bb6ca465645051b3 *src/include/Params.h
0816e979947d47e1e91c6327a62d641c *src/include/Test_Interface.h
f3a3cce4a45a5306180127b28e5aa66c *src/include/utils.h
82ebc8c76e0a000e5bf6e391edd49ff3 *src/utils.cpp
38d99785124ecc9d873a36f2f4fff8c6 *tests/testthat.R
33d718ae56a0c2bca1ffe606a3e8d47f *tests/testthat/test-inferCSN.R
34 changes: 34 additions & 0 deletions NAMESPACE
@@ -0,0 +1,34 @@
# Generated by roxygen2: do not edit by hand

S3method(coef,inferCSN)
S3method(coef,inferCSNCV)
S3method(predict,inferCSN)
S3method(predict,inferCSNCV)
S3method(print,inferCSN)
S3method(print,inferCSNCV)
export(acc.calculate)
export(auc.calculate)
export(check.parameters)
export(compute.gene.rank)
export(contrast.networks)
export(dynamic.networks)
export(inferCSN)
export(inferCSN.fit)
export(is.scalar)
export(net.format)
export(network.heatmap)
export(sparse.regression)
export(sub.inferCSN)
exportMethods(inferCSN)
import(Matrix)
import(ggnetwork)
import(ggplot2)
import(ggraph)
import(patchwork)
importFrom(Rcpp,evalCpp)
importFrom(methods,as)
importFrom(methods,is)
importFrom(stats,coef)
importFrom(stats,predict)
importFrom(utils,methods)
useDynLib(inferCSN)
99 changes: 99 additions & 0 deletions R/RcppExports.R
@@ -0,0 +1,99 @@
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

DT2Matrix <- function(weightDT) {
.Call('_inferCSN_DT2Matrix', PACKAGE = 'inferCSN', weightDT)
}

inferCSNFit_sparse <- function(X, y, Loss, Penalty, Algorithm, NnzStopNum, G_ncols, G_nrows, Lambda2Max, Lambda2Min, PartialSort, MaxIters, rtol, atol, ActiveSet, ActiveSetNum, MaxNumSwaps, ScaleDownFactor, ScreenSize, LambdaU, Lambdas, ExcludeFirstK, Intercept, withBounds, Lows, Highs) {
.Call('_inferCSN_inferCSNFit_sparse', PACKAGE = 'inferCSN', X, y, Loss, Penalty, Algorithm, NnzStopNum, G_ncols, G_nrows, Lambda2Max, Lambda2Min, PartialSort, MaxIters, rtol, atol, ActiveSet, ActiveSetNum, MaxNumSwaps, ScaleDownFactor, ScreenSize, LambdaU, Lambdas, ExcludeFirstK, Intercept, withBounds, Lows, Highs)
}

inferCSNFit_dense <- function(X, y, Loss, Penalty, Algorithm, NnzStopNum, G_ncols, G_nrows, Lambda2Max, Lambda2Min, PartialSort, MaxIters, rtol, atol, ActiveSet, ActiveSetNum, MaxNumSwaps, ScaleDownFactor, ScreenSize, LambdaU, Lambdas, ExcludeFirstK, Intercept, withBounds, Lows, Highs) {
.Call('_inferCSN_inferCSNFit_dense', PACKAGE = 'inferCSN', X, y, Loss, Penalty, Algorithm, NnzStopNum, G_ncols, G_nrows, Lambda2Max, Lambda2Min, PartialSort, MaxIters, rtol, atol, ActiveSet, ActiveSetNum, MaxNumSwaps, ScaleDownFactor, ScreenSize, LambdaU, Lambdas, ExcludeFirstK, Intercept, withBounds, Lows, Highs)
}

inferCSNCV_sparse <- function(X, y, Loss, Penalty, Algorithm, NnzStopNum, G_ncols, G_nrows, Lambda2Max, Lambda2Min, PartialSort, MaxIters, rtol, atol, ActiveSet, ActiveSetNum, MaxNumSwaps, ScaleDownFactor, ScreenSize, LambdaU, Lambdas, nfolds, seed, ExcludeFirstK, Intercept, withBounds, Lows, Highs) {
.Call('_inferCSN_inferCSNCV_sparse', PACKAGE = 'inferCSN', X, y, Loss, Penalty, Algorithm, NnzStopNum, G_ncols, G_nrows, Lambda2Max, Lambda2Min, PartialSort, MaxIters, rtol, atol, ActiveSet, ActiveSetNum, MaxNumSwaps, ScaleDownFactor, ScreenSize, LambdaU, Lambdas, nfolds, seed, ExcludeFirstK, Intercept, withBounds, Lows, Highs)
}

inferCSNCV_dense <- function(X, y, Loss, Penalty, Algorithm, NnzStopNum, G_ncols, G_nrows, Lambda2Max, Lambda2Min, PartialSort, MaxIters, rtol, atol, ActiveSet, ActiveSetNum, MaxNumSwaps, ScaleDownFactor, ScreenSize, LambdaU, Lambdas, nfolds, seed, ExcludeFirstK, Intercept, withBounds, Lows, Highs) {
.Call('_inferCSN_inferCSNCV_dense', PACKAGE = 'inferCSN', X, y, Loss, Penalty, Algorithm, NnzStopNum, G_ncols, G_nrows, Lambda2Max, Lambda2Min, PartialSort, MaxIters, rtol, atol, ActiveSet, ActiveSetNum, MaxNumSwaps, ScaleDownFactor, ScreenSize, LambdaU, Lambdas, nfolds, seed, ExcludeFirstK, Intercept, withBounds, Lows, Highs)
}

cor_matrix <- function(p, base_cor) {
.Call('_inferCSN_cor_matrix', PACKAGE = 'inferCSN', p, base_cor)
}

R_matrix_column_get_dense <- function(mat, col) {
.Call('_inferCSN_R_matrix_column_get_dense', PACKAGE = 'inferCSN', mat, col)
}

R_matrix_column_get_sparse <- function(mat, col) {
.Call('_inferCSN_R_matrix_column_get_sparse', PACKAGE = 'inferCSN', mat, col)
}

R_matrix_rows_get_dense <- function(mat, rows) {
.Call('_inferCSN_R_matrix_rows_get_dense', PACKAGE = 'inferCSN', mat, rows)
}

R_matrix_rows_get_sparse <- function(mat, rows) {
.Call('_inferCSN_R_matrix_rows_get_sparse', PACKAGE = 'inferCSN', mat, rows)
}

R_matrix_vector_schur_product_dense <- function(mat, u) {
.Call('_inferCSN_R_matrix_vector_schur_product_dense', PACKAGE = 'inferCSN', mat, u)
}

R_matrix_vector_schur_product_sparse <- function(mat, u) {
.Call('_inferCSN_R_matrix_vector_schur_product_sparse', PACKAGE = 'inferCSN', mat, u)
}

R_matrix_vector_divide_dense <- function(mat, u) {
.Call('_inferCSN_R_matrix_vector_divide_dense', PACKAGE = 'inferCSN', mat, u)
}

R_matrix_vector_divide_sparse <- function(mat, u) {
.Call('_inferCSN_R_matrix_vector_divide_sparse', PACKAGE = 'inferCSN', mat, u)
}

R_matrix_column_sums_dense <- function(mat) {
.Call('_inferCSN_R_matrix_column_sums_dense', PACKAGE = 'inferCSN', mat)
}

R_matrix_column_sums_sparse <- function(mat) {
.Call('_inferCSN_R_matrix_column_sums_sparse', PACKAGE = 'inferCSN', mat)
}

R_matrix_column_dot_dense <- function(mat, col, u) {
.Call('_inferCSN_R_matrix_column_dot_dense', PACKAGE = 'inferCSN', mat, col, u)
}

R_matrix_column_dot_sparse <- function(mat, col, u) {
.Call('_inferCSN_R_matrix_column_dot_sparse', PACKAGE = 'inferCSN', mat, col, u)
}

R_matrix_column_mult_dense <- function(mat, col, u) {
.Call('_inferCSN_R_matrix_column_mult_dense', PACKAGE = 'inferCSN', mat, col, u)
}

R_matrix_column_mult_sparse <- function(mat, col, u) {
.Call('_inferCSN_R_matrix_column_mult_sparse', PACKAGE = 'inferCSN', mat, col, u)
}

R_matrix_normalize_dense <- function(mat_norm) {
.Call('_inferCSN_R_matrix_normalize_dense', PACKAGE = 'inferCSN', mat_norm)
}

R_matrix_normalize_sparse <- function(mat_norm) {
.Call('_inferCSN_R_matrix_normalize_sparse', PACKAGE = 'inferCSN', mat_norm)
}

R_matrix_center_dense <- function(mat, X_normalized, intercept) {
.Call('_inferCSN_R_matrix_center_dense', PACKAGE = 'inferCSN', mat, X_normalized, intercept)
}

R_matrix_center_sparse <- function(mat, X_normalized, intercept) {
.Call('_inferCSN_R_matrix_center_sparse', PACKAGE = 'inferCSN', mat, X_normalized, intercept)
}

128 changes: 128 additions & 0 deletions R/auc.calculate.R
@@ -0,0 +1,128 @@
#' @title AUC value calculate
#'
#' @param weightDT The weight data table of network
#' @param groundTruth Ground truth for calculate AUC
#' @param plot If true, draw and print figure of AUC
#' @param lineColor The color of line in the figure
#' @param lineWidth The width of line in the figure
#'
#' @import patchwork
#' @import ggplot2
#'
#' @return AUC values and figure
#' @export
#'
#' @examples
#' library(inferCSN)
#' data("exampleMatrix")
#' data("exampleGroundTruth")
#' weightDT <- inferCSN(exampleMatrix)
#' auc <- auc.calculate(weightDT, exampleGroundTruth, plot = TRUE)
#' head(auc)
#'
auc.calculate <- function(weightDT,
groundTruth,
plot = FALSE,
lineColor = "#1563cc",
lineWidth = 1) {
# Check input data
colnames(weightDT) <- c("regulator", "target", "weight")
weightDT$weight <- abs(as.numeric(weightDT$weight))

if (ncol(groundTruth) > 2) groundTruth <- groundTruth[, 1:2]
names(groundTruth) <- c("regulator", "target")
groundTruth$label <- rep(1, nrow(groundTruth))

gold <- merge(weightDT, groundTruth,
by = c("regulator", "target"),
all.x = TRUE)
gold$label[is.na(gold$label)] <- 0

aucCurves <- precrec::evalmod(scores = gold$weight,
labels = gold$label)

auc <- attr(aucCurves, "auc")

aucMetric <- data.frame(AUROC = rep(0.000, 1),
AUPRC = rep(0.000, 1),
ACC = rep(0.000, 1))
aucMetric[1, "AUROC"] <- sprintf("%0.3f", auc$aucs[1])
aucMetric[1, "AUPRC"] <- sprintf("%0.3f", auc$aucs[2])
aucMetric[1, "ACC"] <- sprintf("%0.3f", acc.calculate(gold))
if (plot) {
# Separate data
aurocDf <- subset(fortify(aucCurves),
curvetype == "ROC")
auprcDf <- subset(fortify(aucCurves),
curvetype == "PRC")

# Plot
auroc <- ggplot(aurocDf, aes(x = x, y = y)) +
geom_line(color = lineColor,
linewidth = lineWidth) +
geom_abline(slope = lineWidth,
color = lineColor,
linetype = "dotted",
linewidth = lineWidth) +
labs(title = paste("AUROC:", aucMetric[1]),
x = "False positive rate",
y = "True positive rate") +
xlim(0, 1) +
ylim(0, 1) +
coord_fixed() +
theme_bw()

auprc <- ggplot(auprcDf, aes(x = x, y = y)) +
geom_line(color = lineColor,
linewidth = 1) +
labs(title = paste("AUPRC:", aucMetric[2]),
x = "Recall",
y = "Precision") +
xlim(0, 1) +
ylim(0, 1) +
coord_fixed() +
theme_bw()

# Combine two plots by `patchwork` package
p <- auroc + auprc
print(p)
}

return(aucMetric)
}

#' ACC calculate
#'
#' @param gold Data
#'
#' @return ACC
#' @export
#'
acc.calculate <- function(gold) {
results <- pROC::roc(gold$label ~ gold$weight,
direction = "<",
levels = c(0, 1))

# After this operation, '0' indicate positive
reverseLabel <- 2 - as.numeric(as.factor(gold$label))

sensitivities <- results$sensitivities
specificities <- results$specificities
selectValue <- sensitivities + specificities - 1
cutValueResults <- results$thresholds[selectValue == max(selectValue)]
selectSensitivities <- sensitivities[selectValue == max(selectValue)]

cutValue <- cutValueResults[selectSensitivities == max(selectSensitivities)]

predictorBinary <- rep(0, length(results$predictor))
predictorBinary[results$predictor >= cutValue] <- 1
predictorBinary <- as.factor(predictorBinary)
levels(predictorBinary) <- c("0", "1")
predictorBinary <- factor(predictorBinary, levels = c(1, 0))

pre <- as.vector(table(predictorBinary, reverseLabel))

acc <- (pre[1] + pre[4]) / sum(pre)

return(acc)
}

0 comments on commit 3580092

Please sign in to comment.