Skip to content

Commit

Permalink
version 0.99.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Meng Xu authored and cran-robot committed Oct 30, 2023
1 parent ace993f commit ab40a6c
Show file tree
Hide file tree
Showing 12 changed files with 207 additions and 83 deletions.
8 changes: 4 additions & 4 deletions DESCRIPTION
@@ -1,8 +1,8 @@
Type: Package
Package: inferCSN
Title: Inferring Cell-Specific Gene Regulatory Network
Version: 0.99.6
Date: 2023-10-26
Version: 0.99.7
Date: 2023-10-30
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>
Expand All @@ -25,7 +25,7 @@ LazyData: true
RoxygenNote: 7.2.3
Language: en-US
NeedsCompilation: yes
Packaged: 2023-10-27 08:50:49 UTC; MSI
Packaged: 2023-10-30 09:20:37 UTC; MSI
Author: Meng Xu [aut, cre] (<https://orcid.org/0000-0002-8300-1054>)
Repository: CRAN
Date/Publication: 2023-10-27 11:40:09 UTC
Date/Publication: 2023-10-30 10:30:02 UTC
22 changes: 11 additions & 11 deletions MD5
@@ -1,16 +1,16 @@
264f59c01e021e20821196770938a2ae *DESCRIPTION
a391abb051df2885c3f48d2f0b540673 *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
92b2747f3e12209d4ea369ba887a67e8 *R/inferCSN.R
04ca60f893ba9a71cff624d4829c186b *R/inferCSN.R
715a9aeffcf51cf83312d5c9d6ec328c *R/network.visualization.R
46e2da40b98966b3a562a7e424ad152f *R/sparse.regression.R
ef4b9e9703cb364732029f703ca9f1ce *R/utils.R
83182b662920b2607aed49c9d7b9cba0 *README.md
e30a750b6b3c4e66b49ba068ccb9de05 *README.md
191a298ed75823937c77adad132f746b *data/exampleGroundTruth.rda
975775272629b1e1438f9c89883e7728 *data/exampleMatrix.rda
57b1f401ca4e288993d509078d88d236 *man/acc.calculate.Rd
Expand All @@ -33,22 +33,22 @@ f7a5bfcd778f7d581b09d78d3eac0bb4 *man/inferCSN.Rd
fff4dcff1db51ae21b76613e1dfed1c5 *man/print.inferCSN.Rd
3fcd8c319587d585129534013633c858 *man/sparse.regression.Rd
73197635a9a5df894c4f5b4e88ca4e8c *man/sub.inferCSN.Rd
1e6750ed9d5f86b882e6a24591733b47 *src/BetaVector.cpp
0347ffda63bae663f9354d1e0b948d57 *src/BetaVector.cpp
dadb1987bfb2f80d199a2e25b02a051d *src/CDL012LogisticSwaps.cpp
64737baec03e2641f58d5681381874d6 *src/CDL012SquaredHingeSwaps.cpp
45e55da928a9a22670c9a7380e7469b1 *src/CDL012Swaps.cpp
b9f4edd41ee1ba186d768676b2bf79ee *src/DT2Matrix.cpp
6a4f677eff1881a88c670cf19c77773c *src/CDL012Swaps.cpp
2e4e9b0639d3f1afc4cf99411a293b67 *src/DT2Matrix.cpp
d4f2e65104193ad8b04b23281a39cd8c *src/Grid.cpp
51b6baa37f71f76d69bc5e178c98b8a7 *src/Grid1D.cpp
2ebc2a8b814581ce38dd0a53cf275ce5 *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
e447698f0493b967abd0e0aaf2eca2c2 *src/include/BetaVector.h
e9aab72b23846ad7db4b0fa1e2597d09 *src/include/CD.h
3006562807501591e7979d1b5af7c039 *src/include/CDL0.h
c9262d8cc37f5ad121511ab15f1ef234 *src/include/CDL012.h
da6865571ac3a696ef96d8d10c8b7c9a *src/include/CDL012Logistic.h
Expand All @@ -61,12 +61,12 @@ c36020aa6b5463f99a6265a18d745473 *src/include/CDL012LogisticSwaps.h
fa0e95061a24b8e548c611d4304664d0 *src/include/Grid.h
1e34795fcfd7f91aa821223794050e00 *src/include/Grid1D.h
5155c4b89da70421f47b4e82a0111866 *src/include/Grid2D.h
29346ba8476c3664856ab8f5ae9ff180 *src/include/GridParams.h
5f89a8eaba4ab540eb63046a1e83dbe6 *src/include/GridParams.h
3754bebf455414fb993fd10bfc967742 *src/include/Interface.h
68b70f6c4a8c08a8d7f6bb97746d3d49 *src/include/MakeCD.h
aea94cb863ab3243b5c681f9d905c175 *src/include/Model.h
8650499eeb16d4bf88397c8ed3c29c92 *src/include/Normalize.h
1dab88b0db3caf456c803e72434b8cf8 *src/include/Params.h
cdde68a3cfff76e8a18c34209800bea5 *src/include/Params.h
0816e979947d47e1e91c6327a62d641c *src/include/Test_Interface.h
f3a3cce4a45a5306180127b28e5aa66c *src/include/utils.h
82ebc8c76e0a000e5bf6e391edd49ff3 *src/utils.cpp
Expand Down
2 changes: 1 addition & 1 deletion R/inferCSN.R
Expand Up @@ -61,7 +61,7 @@ setGeneric("inferCSN",
maxSuppSize = NULL,
verbose = FALSE,
cores = 1) {
UseMethod(generic = "inferCSN")
UseMethod(generic = "inferCSN", object = matrix)
})

#' @rdname inferCSN
Expand Down
12 changes: 7 additions & 5 deletions README.md
Expand Up @@ -6,19 +6,21 @@

<!-- badges: end -->

## **Introduction**

[*`inferCSN`*](https://mengxu98.github.io/inferCSN/) is an package for inferring cell-specific gene regulatory network from single-cell sequencing data.

<img src="man/figures/inferCSN.svg" width="75%"/>

## **Install**
## **Installation**

### [*`CRAN`*](https://github.com/cran)
You can install the released version from [*`CRAN`*](https://github.com/cran) use:

``` r
install.packages("inferCSN")
```

### Using [*`pak`*](https://github.com/r-lib/pak)
You can install the development version from [*`GitHub`*](https://github.com/mengxu98/inferCSN) use [*`pak`*](https://github.com/r-lib/pak):

``` r
if (!require("pak", quietly = TRUE)) {
Expand All @@ -27,13 +29,13 @@ if (!require("pak", quietly = TRUE)) {
pak::pak("mengxu98/inferCSN")
```

### Using *`git clone`*
You can also install the development version use *`git clone`* to automatically handle some issues related to dependencies:

``` bash
git clone https://github.com/mengxu98/inferCSN.git
cd inferCSN
sh scripts/requirements.sh
R CMD INSTALL .
R CMD INSTALL . --library=/your/lib/path
```

## **Usage**
Expand Down
33 changes: 13 additions & 20 deletions src/BetaVector.cpp
Expand Up @@ -7,65 +7,59 @@
std::vector<std::size_t> nnzIndicies(const arma::vec& B){
// Returns a vector of the Non Zero Indicies of B
const arma::ucolvec nnzs_indicies = arma::find(B);
return arma::conv_to<std::vector<std::size_t>>::from(nnzs_indicies);
return arma::conv_to<std::vector<std::size_t>>::from(nnzs_indicies);
}

// std::vector<std::size_t> nnzIndicies(const arma::sp_mat& B){
// std::vector<std::size_t> nnzIndicies(const arma::sp_mat& B) {
// // Returns a vector of the Non Zero Indicies of B
// std::vector<std::size_t> S;
// arma::sp_mat::const_iterator it;
// const arma::sp_mat::const_iterator it_end = B.end();
// for(it = B.begin(); it != it_end; ++it)
// {
// for(it = B.begin(); it != it_end; ++it) {
// S.push_back(it.row());
// }
// return S;
// return S;
// }

std::vector<std::size_t> nnzIndicies(const arma::vec& B, const std::size_t low){
// Returns a vector of the Non Zero Indicies of a slice of B starting at low
// This is for NoSelectK situations
const arma::vec B_slice = B.subvec(low, B.n_rows-1);
const arma::ucolvec nnzs_indicies = arma::find(B_slice);
return arma::conv_to<std::vector<std::size_t>>::from(nnzs_indicies);
return arma::conv_to<std::vector<std::size_t>>::from(nnzs_indicies);
}

// std::vector<std::size_t> nnzIndicies(const arma::sp_mat& B, const std::size_t low){
// // Returns a vector of the Non Zero Indicies of B
// std::vector<std::size_t> S;
//
//
//
// arma::sp_mat::const_iterator it;
// const arma::sp_mat::const_iterator it_end = B.end();
//
//
// for(it = B.begin(); it != it_end; ++it)
// {
//
// for(it = B.begin(); it != it_end; ++it) {
// if (it.row() >= low){
// S.push_back(it.row());
// }
// }
// return S;
// return S;
// }


std::size_t n_nonzero(const arma::vec& B){
const arma::vec nnzs = arma::nonzeros(B);
return nnzs.n_rows;

}

// std::size_t n_nonzero(const arma::sp_mat& B){
// return B.n_nonzero;
//
// }

bool has_same_support(const arma::vec& B1, const arma::vec& B2){
if (B1.size() != B2.size()){
return false;
}
std::size_t n = B1.n_rows;

bool same_support = true;
for (std::size_t i = 0; i < n; i++){
same_support = same_support && ((B1.at(i) != 0) == (B2.at(i) != 0));
Expand All @@ -74,14 +68,14 @@ bool has_same_support(const arma::vec& B1, const arma::vec& B2){
}

// bool has_same_support(const arma::sp_mat& B1, const arma::sp_mat& B2){
//
//
// if (B1.n_nonzero != B2.n_nonzero) {
// return false;
// } else { // same number of nnz and Supp is sorted
// arma::sp_mat::const_iterator i1, i2;
// const arma::sp_mat::const_iterator i1_end = B1.end();
//
//
//
//
// for(i1 = B1.begin(), i2 = B2.begin(); i1 != i1_end; ++i1, ++i2)
// {
// if(i1.row() != i2.row())
Expand All @@ -92,4 +86,3 @@ bool has_same_support(const arma::vec& B1, const arma::vec& B2){
// return true;
// }
// }

18 changes: 15 additions & 3 deletions src/CDL012Swaps.cpp
Expand Up @@ -14,7 +14,17 @@ FitResult<T> CDL012Swaps<T>::_Fit() {
auto result = CDL012<T>(*(this->X), this->y, this->P).Fit(); // result will be maintained till the end
this->B = result.B;
this->b0 = result.b0;
double objective = result.Objective;

// Remove the following 1 line and line-93 to emilate warning:
// CDL012Swaps.cpp:97:16: required from here
// CDL012Swaps.cpp:17:12: warning: variable 'objective' set but not used [-Wunused-but-set-variable]
// 17 | double objective = result.Objective;
// | ^~~~~~~~~
// CDL012Swaps.cpp: In instantiation of 'FitResult<T> CDL012Swaps<T>::_Fit() [with T = arma::SpMat<double>]':
// CDL012Swaps.cpp:98:16: required from here
// CDL012Swaps.cpp:17:12: warning: variable 'objective' set but not used [-Wunused-but-set-variable]
// double objective = result.Objective;

this->P.Init = 'u';

bool foundbetter = false;
Expand All @@ -26,7 +36,7 @@ FitResult<T> CDL012Swaps<T>::_Fit() {
foundbetter = false;

// TODO: shuffle NNz Indices to prevent bias.
//std::shuffle(std::begin(Order), std::end(Order), engine);
// std::shuffle(std::begin(Order), std::end(Order), engine);

// TODO: This calculation is already preformed in a previous step
// Can be pulled/stored
Expand Down Expand Up @@ -79,7 +89,9 @@ FitResult<T> CDL012Swaps<T>::_Fit() {
// Rcpp::Rcout << "Swap Objective " << result.Objective << " \n";
// Rcpp::Rcout << "Old Objective " << objective << " \n";
this->B = result.B;
objective = result.Objective;

// objective = result.Objective;

foundbetter = true;
break;
}
Expand Down
33 changes: 23 additions & 10 deletions src/DT2Matrix.cpp
@@ -1,4 +1,5 @@
#include <Rcpp.h>

using namespace Rcpp;

// [[Rcpp::export]]
Expand Down Expand Up @@ -32,16 +33,6 @@ NumericMatrix DT2Matrix(DataFrame weightDT) {
// #' @return Weight matrix
// #' @export
// #'
// #' @examples
// #' Rcpp::sourceCpp("src/DT2Matrix.cpp")
// #' library(inferCSN)
// #' data("exampleMatrix")
// #' weightDT <- inferCSN(exampleMatrix, verbose = TRUE)
// #' weightMatrix <- DT2Matrix(weightDT)
// #' genes <- gtools::mixedsort(unique(c(weightDT$regulator, weightDT$target)))
// #' weightMatrix <- weightMatrix[genes, genes]
// #' weightMatrixR <- DT2MatrixR(weightDT)
// #'
// DT2MatrixR <- function(weightDT) {
// colnames(weightDT) <- c("regulator", "target", "weight")
// genes <- gtools::mixedsort(unique(c(weightDT$regulator, weightDT$target)))
Expand All @@ -57,3 +48,25 @@ NumericMatrix DT2Matrix(DataFrame weightDT) {
//
// return(weightMatrix)
// }
//
// DT2MatrixR2 <- function(weightDT) {
// weightMatrix <- reshape2::acast(weightDT, regulator ~ target)[genes, genes]
// weightMatrix[is.na(weightMatrix)] <- 0
// return(weightMatrix)
// }
//
// #' @examples
// Rcpp::sourceCpp("src/DT2Matrix.cpp")
// library(inferCSN)
// data("exampleMatrix")
// weightDT <- inferCSN(exampleMatrix, verbose = TRUE)
// weightMatrix <- DT2Matrix(weightDT)
// genes <- gtools::mixedsort(unique(c(weightDT$regulator, weightDT$target)))
// weightMatrix <- weightMatrix[genes, genes]
// weightMatrixR <- DT2MatrixR(weightDT)
// weightMatrixR2 <- DT2MatrixR2(weightDT)
//
// # Using `bench` package to evaluate the two versions of this function
// bench::mark(DT2MatrixR(weightDT),
// DT2Matrix(weightDT)[genes, genes],
// DT2MatrixR2(weightDT))
21 changes: 15 additions & 6 deletions src/Grid1D.cpp
Expand Up @@ -191,12 +191,21 @@ std::vector<std::unique_ptr<FitResult<T>>> Grid1D<T>::Fit() {

std::vector<std::size_t> Spnew = nnzIndicies(result->B);

bool samesupp = false;

if (Spold == Spnew) {
samesupp = true;
scaledown = true;
}
// Remove the following 5 lines to emilate warning:
// Grid1D.cpp: In instantiation of 'std::vector<std::unique_ptr<FitResult<T> > > Grid1D<T>::Fit() [with T = arma::Mat<double>]':
// Grid1D.cpp:234:16: required from here
// Grid1D.cpp:194:26: warning: variable 'samesupp' set but not used [-Wunused-but-set-variable]
// 194 | bool samesupp = false;
// | ^~~~~~~~
// Grid1D.cpp: In instantiation of 'std::vector<std::unique_ptr<FitResult<T> > > Grid1D<T>::Fit() [with T = arma::SpMat<double>]':
// Grid1D.cpp:235:16: required from here
// Grid1D.cpp:194:26: warning: variable 'samesupp' set but not used [-Wunused-but-set-variable]
// bool samesupp = false;

// if (Spold == Spnew) {
// samesupp = true;
// scaledown = true;
// }

// if (samesupp) {
// scaledown = true;
Expand Down
1 change: 0 additions & 1 deletion src/include/BetaVector.h
Expand Up @@ -7,7 +7,6 @@
* arma::vec implementation
*/


using beta_vector = arma::vec;
//using beta_vector = arma::sp_mat;

Expand Down

0 comments on commit ab40a6c

Please sign in to comment.