From 88bddfa74468f79fe22fe48f5b50b89a077ce33e Mon Sep 17 00:00:00 2001 From: Evan Biederstedt Date: Tue, 10 Aug 2021 12:27:46 -0400 Subject: [PATCH 1/5] update version, readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 59266e1..d05a26a 100644 --- a/README.md +++ b/README.md @@ -238,5 +238,5 @@ The R package can be cited as: ``` Viktor Petukhov, Nikolas Barkas, Peter Kharchenko, and Evan Biederstedt (2021). conos: Clustering on Network of Samples. R -package version 1.4.2. +package version 1.4.3. ``` \ No newline at end of file From 919842d600e8c302938bf7f77235df575cdc4c1c Mon Sep 17 00:00:00 2001 From: viktor_petukhov Date: Thu, 30 Sep 2021 13:48:45 -0400 Subject: [PATCH 2/5] fail.on.error=TRUE in some plapplys --- R/conclass.R | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/R/conclass.R b/R/conclass.R index 6eac787..461989e 100644 --- a/R/conclass.R +++ b/R/conclass.R @@ -154,7 +154,7 @@ Conos <- R6::R6Class("Conos", lock_objects=FALSE, #' @return joint graph to be used for downstream analysis #' @examples #' con <- Conos$new(small_panel.preprocessed, n.cores=1) - #' con$buildGraph(k=10, k.self=5, space='PCA', ncomps=10, n.odgenes=20, matching.method='mNN', + #' con$buildGraph(k=10, k.self=5, space='PCA', ncomps=10, n.odgenes=20, matching.method='mNN', #' metric='angular', score.component.variance=TRUE, verbose=TRUE) #' #' @@ -381,7 +381,7 @@ Conos <- R6::R6Class("Conos", lock_objects=FALSE, groups %<>% as.factor() %>% droplevels() # TODO: add Seurat '%ni%' <- Negate('%in%') - if ('Pagoda2' %ni% class(self$samples[[1]])){ + if ('Pagoda2' %ni% class(self$samples[[1]])) { stop("Only Pagoda2 objects are supported for marker genes") } @@ -396,7 +396,8 @@ Conos <- R6::R6Class("Conos", lock_objects=FALSE, de.genes %<>% lapply(function(x) if ((length(x) > 0) && (nrow(x) > 0)) subset(x, complete.cases(x)) else x) de.genes %<>% names() %>% setNames(., .) %>% - sccore::plapply(function(n) appendSpecificityMetricsToDE(de.genes[[n]], groups.clean, n, p2.counts=cm.merged, append.auc=append.auc), progress=verbose, n.cores=self$n.cores) + sccore::plapply(function(n) appendSpecificityMetricsToDE(de.genes[[n]], groups.clean, n, p2.counts=cm.merged, append.auc=append.auc), + progress=verbose, n.cores=self$n.cores, fail.on.error=TRUE) } if (verbose) message("All done!") @@ -418,7 +419,7 @@ Conos <- R6::R6Class("Conos", lock_objects=FALSE, #' @return invisible list containing identified communities (groups) and the full community detection result (result); The results are stored in $clusters$name slot in the conos object. Each such slot contains an object with elements: $results which stores the raw output of the community detection method, and $groups which is a factor on cells describing the resulting clustering. The later can be used, for instance, in plotting: con$plotGraph(groups=con$clusters$leiden$groups). If test.stability==TRUE, then the result object will also contain a $stability slot. #' @examples #' con <- Conos$new(small_panel.preprocessed, n.cores=1) - #' con$buildGraph(k=10, k.self=5, space='PCA', ncomps=10, n.odgenes=20, matching.method='mNN', + #' con$buildGraph(k=10, k.self=5, space='PCA', ncomps=10, n.odgenes=20, matching.method='mNN', #' metric='angular', score.component.variance=TRUE, verbose=TRUE) #' con$findCommunities(method = igraph::walktrap.community, steps=5) #' @@ -851,7 +852,7 @@ Conos <- R6::R6Class("Conos", lock_objects=FALSE, #' @param count.matrix Alternative gene count matrix to correct (rows: genes, columns: cells; has to be dense matrix). Default: joint count matrix for all datasets. #' @param normalize boolean Whether to normalize values (default=TRUE) #' @return smoothed expression of the input genes - #' + #' correctGenes=function(genes=NULL, n.od.genes=500, fading=10.0, fading.const=0.5, max.iters=15, tol=5e-3, name='diffusion', verbose=TRUE, count.matrix=NULL, normalize=TRUE) { edges <- igraph::as_edgelist(self$graph) edge.weights <- igraph::edge.attributes(self$graph)$weight @@ -1065,7 +1066,7 @@ Conos <- R6::R6Class("Conos", lock_objects=FALSE, if(any(is.na(mi))) { # some pairs are missing if(verbose) message('running ',sum(is.na(mi)),' additional ',space,' space pairs ') xl2 <- sccore::plapply(which(is.na(mi)), function(i) { - if(space=='CPCA') { + if (space=='CPCA') { xcp <- quickCPCA(self$samples[sn.pairs[,i]],data.type=data.type,ncomps=ncomps,n.odgenes=n.odgenes,verbose=FALSE,var.scale=var.scale, score.component.variance=score.component.variance) } else if(space=='JNMF') { xcp <- quickJNMF(self$samples[sn.pairs[,i]],data.type=data.type,n.comps=ncomps,n.odgenes=n.odgenes,var.scale=var.scale,verbose=FALSE,max.iter=3e3) @@ -1078,7 +1079,7 @@ Conos <- R6::R6Class("Conos", lock_objects=FALSE, } if(verbose) cat(".") xcp - }, n.cores=self$n.cores, mc.preschedule=(space=='PCA'), progress=FALSE) + }, n.cores=self$n.cores, mc.preschedule=(space=='PCA'), progress=FALSE, fail.on.error=TRUE) names(xl2) <- apply(sn.pairs[,which(is.na(mi)),drop=FALSE],2,paste,collapse='.vs.') xl2 <- xl2[!unlist(lapply(xl2,is.null))] From 9ba916cb7e853ca058a5bf180ae9f489e2bc1b29 Mon Sep 17 00:00:00 2001 From: evanbiederstedt Date: Mon, 8 Nov 2021 15:54:39 -0500 Subject: [PATCH 3/5] re-add getGeneExpression for Seurat, circleci changes --- .Rbuildignore | 3 ++- .circleci/config.yml | 20 ++++++++++++++++++++ .gitignore | 1 + CHANGELOG.md | 8 ++++++++ DESCRIPTION | 4 ++-- R/access_wrappers.R | 21 +++++++++++++++++++++ README.md | 4 ++-- man/Conos.Rd | 8 ++++---- src/RcppExports.cpp | 5 +++++ 9 files changed, 65 insertions(+), 9 deletions(-) create mode 100644 .circleci/config.yml diff --git a/.Rbuildignore b/.Rbuildignore index 61298ac..13c26ae 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -10,4 +10,5 @@ CHANGELOG.md ^vignettes\figure$ docker CONTRIBUTING.md -data-raw \ No newline at end of file +data-raw +^\.circleci$ \ No newline at end of file diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..d6fb8a1 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,20 @@ +version: 2 +jobs: + build: + docker: + - image: rocker/verse:4.0.3 + environment: + _R_CHECK_FORCE_SUGGESTS_: false + steps: + - checkout + - run: + name: Install package dependencies + command: R -e "devtools::install_deps(dep = TRUE)" + - run: + name: Build package + command: R CMD build . + - run: + name: Check package + command: R CMD check --no-manual *tar.gz + - store_test_results: + path: tmp/tests diff --git a/.gitignore b/.gitignore index 42eef11..effcf90 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ .RData .Ruserdata conos*.tar.gz +conos*Rcheck \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 293bda8..6ab2c71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ ## Upcoming +## [1.4.4] - 2021-11-08 + +### Changed +- Added `fail.on.error=TRUE` in some plapplys +- Re-added `getGeneExpression()` methods for Seurat (lost in merge 552408f) +- Switched to CircleCI + + ## [1.4.3] - 2021-02-08 ### Changed diff --git a/DESCRIPTION b/DESCRIPTION index 72308f2..9b734ea 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: conos Title: Clustering on Network of Samples -Version: 1.4.3 +Version: 1.4.4 Authors@R: c(person("Viktor","Petukhov", email="viktor.s.petuhov@ya.ru", role="aut"), person("Nikolas","Barkas", email="nikolas_barkas@hms.harvard.edu", role="aut"), person("Peter", "Kharchenko", email = "peter_kharchenko@hms.harvard.edu", role = "aut"), person("Weiliang", "Qiu", email = "weiliang.qiu@gmail.com", role = c("ctb")), person("Evan", "Biederstedt", email="evan.biederstedt@gmail.com", role=c("aut", "cre"))) Description: Wires together large collections of single-cell RNA-seq datasets, which allows for both the identification of recurrent cell clusters and the propagation of information between datasets in multi-sample or atlas-scale collections. 'Conos' focuses on the uniform mapping of homologous cell types across heterogeneous sample collections. For instance, users could investigate a collection of dozens of peripheral blood samples from cancer patients combined with dozens of controls, which perhaps includes samples of a related tissue such as lymph nodes. This package interacts with data available through the 'conosPanel' package, which is available in a 'drat' repository. To access this data package, see the instructions at . The size of the 'conosPanel' package is approximately 12 MB. License: GPL-3 @@ -34,7 +34,7 @@ Imports: stats, tools, utils -RoxygenNote: 7.1.1 +RoxygenNote: 7.1.2 Suggests: AnnotationDbi, BiocParallel, diff --git a/R/access_wrappers.R b/R/access_wrappers.R index 3e16a64..b968c09 100644 --- a/R/access_wrappers.R +++ b/R/access_wrappers.R @@ -215,6 +215,27 @@ getGeneExpression.default <- function(sample, gene) { return(stats::setNames(rep(NA, ncol(count.matrix)), colnames(count.matrix))) } +setMethod("getGeneExpression", signature("Seurat"), function(sample, gene) { + checkSeuratV3() + ## https://satijalab.org/seurat/essential_commands.html + if (gene %in% rownames(Seurat::GetAssayData(object = sample))){ + ## rownames(data) are gene names + return(Seurat::GetAssayData(object = sample)[gene, ]) + } + + return(stats::setNames(rep(NA, ncol(Seurat::GetAssayData(object = sample))), colnames(Seurat::GetAssayData(object = sample)))) +}) + +setMethod("getGeneExpression", signature("seurat"), function(sample, gene) { + ## https://satijalab.org/seurat/essential_commands.html + if (gene %in% rownames(sample@data)){ + ## rownames(data) are gene names + return(sample@data[gene, ]) + } + + return(stats::setNames(rep(NA, ncol(sample@data)), colnames(sample@data))) +}) + #' Access raw count matrix from sample #' diff --git a/README.md b/README.md index d05a26a..1d064e5 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build Status](https://travis-ci.com/kharchenkolab/conos.svg?branch=master)](https://travis-ci.com/github/kharchenkolab/conos) +[![](https://circleci.com/gh/kharchenkolab/conos.svg?style=svg)](https://app.circleci.com/pipelines/github/kharchenkolab/conos) [![CRAN status](https://www.r-pkg.org/badges/version/conos)](https://cran.r-project.org/package=conos) [![CRAN downloads](https://cranlogs.r-pkg.org/badges/conos)](https://cran.r-project.org/package=conos) @@ -238,5 +238,5 @@ The R package can be cited as: ``` Viktor Petukhov, Nikolas Barkas, Peter Kharchenko, and Evan Biederstedt (2021). conos: Clustering on Network of Samples. R -package version 1.4.3. +package version 1.4.4. ``` \ No newline at end of file diff --git a/man/Conos.Rd b/man/Conos.Rd index 11e10d8..583cd8a 100644 --- a/man/Conos.Rd +++ b/man/Conos.Rd @@ -20,7 +20,7 @@ con <- Conos$new(small_panel.preprocessed, n.cores=1) ## ------------------------------------------------ con <- Conos$new(small_panel.preprocessed, n.cores=1) -con$buildGraph(k=10, k.self=5, space='PCA', ncomps=10, n.odgenes=20, matching.method='mNN', +con$buildGraph(k=10, k.self=5, space='PCA', ncomps=10, n.odgenes=20, matching.method='mNN', metric='angular', score.component.variance=TRUE, verbose=TRUE) @@ -30,7 +30,7 @@ con$buildGraph(k=10, k.self=5, space='PCA', ncomps=10, n.odgenes=20, matching.me ## ------------------------------------------------ con <- Conos$new(small_panel.preprocessed, n.cores=1) -con$buildGraph(k=10, k.self=5, space='PCA', ncomps=10, n.odgenes=20, matching.method='mNN', +con$buildGraph(k=10, k.self=5, space='PCA', ncomps=10, n.odgenes=20, matching.method='mNN', metric='angular', score.component.variance=TRUE, verbose=TRUE) con$findCommunities(method = igraph::walktrap.community, steps=5) @@ -287,7 +287,7 @@ joint graph to be used for downstream analysis \subsection{Examples}{ \if{html}{\out{
}} \preformatted{con <- Conos$new(small_panel.preprocessed, n.cores=1) -con$buildGraph(k=10, k.self=5, space='PCA', ncomps=10, n.odgenes=20, matching.method='mNN', +con$buildGraph(k=10, k.self=5, space='PCA', ncomps=10, n.odgenes=20, matching.method='mNN', metric='angular', score.component.variance=TRUE, verbose=TRUE) @@ -388,7 +388,7 @@ invisible list containing identified communities (groups) and the full community \subsection{Examples}{ \if{html}{\out{
}} \preformatted{con <- Conos$new(small_panel.preprocessed, n.cores=1) -con$buildGraph(k=10, k.self=5, space='PCA', ncomps=10, n.odgenes=20, matching.method='mNN', +con$buildGraph(k=10, k.self=5, space='PCA', ncomps=10, n.odgenes=20, matching.method='mNN', metric='angular', score.component.variance=TRUE, verbose=TRUE) con$findCommunities(method = igraph::walktrap.community, steps=5) diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index da2d7ff..6e53b23 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -8,6 +8,11 @@ using namespace Rcpp; +#ifdef RCPP_USE_GLOBAL_ROSTREAM +Rcpp::Rostream& Rcpp::Rcout = Rcpp::Rcpp_cout_get(); +Rcpp::Rostream& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get(); +#endif + // RjnmfC arma::field RjnmfC(arma::mat Xs, arma::mat Xu, int k, double alpha, double lambda, double epsilon, int maxiter, bool verbose); RcppExport SEXP _conos_RjnmfC(SEXP XsSEXP, SEXP XuSEXP, SEXP kSEXP, SEXP alphaSEXP, SEXP lambdaSEXP, SEXP epsilonSEXP, SEXP maxiterSEXP, SEXP verboseSEXP) { From 587acd43d7cb1567296cd11230445b9adc5b985a Mon Sep 17 00:00:00 2001 From: evanbiederstedt Date: Mon, 8 Nov 2021 16:06:43 -0500 Subject: [PATCH 4/5] fix method docs --- R/access_wrappers.R | 2 ++ man/getGeneExpression.Rd | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/R/access_wrappers.R b/R/access_wrappers.R index b968c09..81fd5e4 100644 --- a/R/access_wrappers.R +++ b/R/access_wrappers.R @@ -215,6 +215,7 @@ getGeneExpression.default <- function(sample, gene) { return(stats::setNames(rep(NA, ncol(count.matrix)), colnames(count.matrix))) } +#' @rdname getGeneExpression setMethod("getGeneExpression", signature("Seurat"), function(sample, gene) { checkSeuratV3() ## https://satijalab.org/seurat/essential_commands.html @@ -226,6 +227,7 @@ setMethod("getGeneExpression", signature("Seurat"), function(sample, gene) { return(stats::setNames(rep(NA, ncol(Seurat::GetAssayData(object = sample))), colnames(Seurat::GetAssayData(object = sample)))) }) +#' @rdname getGeneExpression setMethod("getGeneExpression", signature("seurat"), function(sample, gene) { ## https://satijalab.org/seurat/essential_commands.html if (gene %in% rownames(sample@data)){ diff --git a/man/getGeneExpression.Rd b/man/getGeneExpression.Rd index 187c00c..461ec43 100644 --- a/man/getGeneExpression.Rd +++ b/man/getGeneExpression.Rd @@ -4,6 +4,8 @@ \alias{getGeneExpression} \alias{getGeneExpression,Pagoda2-method} \alias{getGeneExpression,Conos-method} +\alias{getGeneExpression,Seurat-method} +\alias{getGeneExpression,seurat-method} \title{Access gene expression from sample} \usage{ getGeneExpression(sample, gene) @@ -11,6 +13,10 @@ getGeneExpression(sample, gene) \S4method{getGeneExpression}{Pagoda2}(sample, gene) \S4method{getGeneExpression}{Conos}(sample, gene) + +\S4method{getGeneExpression}{Seurat}(sample, gene) + +\S4method{getGeneExpression}{seurat}(sample, gene) } \arguments{ \item{sample}{sample from which to access gene expression} From bd6f6bdb912734164f7fc2cab1c40006eda3a12c Mon Sep 17 00:00:00 2001 From: evanbiederstedt Date: Mon, 8 Nov 2021 16:09:26 -0500 Subject: [PATCH 5/5] update sccore version --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 9b734ea..d8c4363 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -30,7 +30,7 @@ Imports: reshape2, rlang, Rtsne, - sccore (> 0.1.2), + sccore (>= 1.0.0), stats, tools, utils