Skip to content

Commit

Permalink
fix the jaccard_coef bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaojieqiu committed Nov 17, 2017
1 parent 72baf13 commit 149ec97
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 13 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ Imports:
stats,
biocViews,
RANN(>= 2.5),
Rcpp
Rcpp (>= 0.12.0)
LinkingTo: Rcpp
Suggests:
destiny,
Hmisc,
Expand All @@ -71,4 +72,3 @@ biocViews: Sequencing, RNASeq, GeneExpression, DifferentialExpression,
Clustering, MultipleComparison, QualityControl
Packaged: 2014-04-07 21:31:54 UTC; sarora
RoxygenNote: 6.0.1
LinkingTo: Rcpp
7 changes: 7 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
Monocle 2.0.0 Series NEWS
================================================================================
Version 2.6.0
--------------------------------------------------------------------------------
o knn-based density peak clustering is not general for all datasets. Rolled back to
the previous densityPeak clustering algorithm and set it to be the default algorithm.
A new Louvain clustering algorithm for dealing with large datasets (like > 500 k cells)
is added.
o A few bug fixes for importCDS, exportCDS functions.

Version 2.5.0
--------------------------------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion R/clustering.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,12 @@ clusterGenes<-function(expr_matrix, k, method=function(x){as.dist((1 - cor(Matri
#' @importFrom igraph graph.data.frame cluster_louvain modularity membership
#' @import ggplot2
#' @importFrom RANN nn2
#' @useDynLib monocle
#' @references Rodriguez, A., & Laio, A. (2014). Clustering by fast search and find of density peaks. Science, 344(6191), 1492-1496. doi:10.1126/science.1242072
#' @references Vincent D. Blondel, Jean-Loup Guillaume, Renaud Lambiotte, Etienne Lefebvre: Fast unfolding of communities in large networks. J. Stat. Mech. (2008) P10008
#' @references Jacob H. Levine and et.al. Data-Driven Phenotypic Dissection of AML Reveals Progenitor-like Cells that Correlate with Prognosis. Cell, 2015.
#'
#' @useDynLib monocle
#'
#' @export

clusterCells <- function(cds,
Expand Down
10 changes: 5 additions & 5 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
using namespace Rcpp;

// jaccard_coeff
NumericMatrix jaccard_coeff(NumericMatrix idx, bool weight);
RcppExport SEXP _monocle_jaccard_coeff(SEXP idxSEXP, SEXP weightSEXP) {
NumericMatrix jaccard_coeff(SEXP R_idx, SEXP R_weight);
RcppExport SEXP _monocle_jaccard_coeff(SEXP R_idxSEXP, SEXP R_weightSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< NumericMatrix >::type idx(idxSEXP);
Rcpp::traits::input_parameter< bool >::type weight(weightSEXP);
rcpp_result_gen = Rcpp::wrap(jaccard_coeff(idx, weight));
Rcpp::traits::input_parameter< SEXP >::type R_idx(R_idxSEXP);
Rcpp::traits::input_parameter< SEXP >::type R_weight(R_weightSEXP);
rcpp_result_gen = Rcpp::wrap(jaccard_coeff(R_idx, R_weight));
return rcpp_result_gen;
END_RCPP
}
Expand Down
15 changes: 10 additions & 5 deletions src/clustering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@ using namespace Rcpp;
// Weights of both i->j and j->i are recorded if they have intersection. In this case
// w(i->j) should be equal to w(j->i). In some case i->j has weights while j<-i has no
// intersections, only w(i->j) is recorded. This is determinded in code `if(u>0)`.
// In this way, the undirected graph is symmetrized by halfing the weight
// in code `weights(r, 2) = u/(2.0*ncol - u)/2`.
// The original method described in the phenograph paper is used to calculate the weight.
//
// Author: Chen Hao, Date: 25/09/2015; updated by Xiaojie Qiu Nov. 12, 2017


// [[Rcpp::export]]
NumericMatrix jaccard_coeff(NumericMatrix idx, bool weight) {
NumericMatrix jaccard_coeff_cpp(NumericMatrix idx, bool weight) {
int nrow = idx.nrow(), ncol = idx.ncol(), r = 0;
NumericMatrix weights(nrow*ncol, 3);

Expand Down Expand Up @@ -52,6 +49,14 @@ NumericMatrix jaccard_coeff(NumericMatrix idx, bool weight) {
return weights;
}

// [[Rcpp::export]]
NumericMatrix jaccard_coeff(SEXP R_idx, SEXP R_weight) {
NumericMatrix idx(R_idx);
bool weight = as<bool>(R_weight);

return jaccard_coeff_cpp(idx, weight);
}

/***
edges$C = jaccard_dist
edges = subset(edges, C != 0)
Expand Down

0 comments on commit 149ec97

Please sign in to comment.