Skip to content

Commit

Permalink
merge dev
Browse files Browse the repository at this point in the history
  • Loading branch information
evanbiederstedt committed Dec 12, 2021
2 parents 8fd3395 + 0c711cd commit 11ead19
Show file tree
Hide file tree
Showing 18 changed files with 53 additions and 30 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ sccore*.tar.gz
sccore.Rcheck
*.o
*.so
.idea
13 changes: 11 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
## Upcoming
# Changelog

## [1.0.1] - December 11 2021

### Changed

## [1.0.0] - Oct 7 2021
- Clarify roxygen2 documentation, `palette` arguments
- Fixed `l.max` parameter in `smoothSignalOnGraph`, added validation for graph connectivity
- `extendMatrix` doesn't drop dimensions anymore
- Fixed processing of `mc.allow.recursive` for `n.cores=1` in `plapply`
- Export `heatFilter()`

## [1.0.0] - October 7 2021


### Changed

Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: sccore
Title: Core Utilities for Single-Cell RNA-Seq
Version: 1.0.0
Version: 1.0.1
Authors@R: c(person("Viktor","Petukhov", email="viktor.s.petuhov@ya.ru", role="aut"), person("Ramus","Rydbirk", email="rasmus.rydbirk@bric.ku.dk", role="aut"), person("Peter", "Kharchenko", email = "peter_kharchenko@hms.harvard.edu", role = "aut"), person("Evan","Biederstedt", email="evan.biederstedt@gmail.com", role=c("aut", "cre")))
Description: Core utilities for single-cell RNA-seq data analysis. Contained within are utility functions for working with differential expression (DE) matrices and count matrices, a collection of functions for manipulating and plotting data via 'ggplot2', and functions to work with cell graphs and cell embeddings. Graph-based methods include embedding kNN cell graphs into a UMAP <doi:10.21105/joss.00861>, collapsing vertices of each cluster in the graph, and propagating graph labels.
License: GPL-3
Expand Down Expand Up @@ -33,7 +33,7 @@ Suggests:
ggrastr (>= 0.1.7),
rmumps,
testthat
RoxygenNote: 7.1.1
RoxygenNote: 7.1.2
LinkingTo: Rcpp, RcppArmadillo, RcppProgress, RcppEigen
NeedsCompilation: yes
SystemRequirements: C++11
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export(extendMatrix)
export(fac2col)
export(getClusterGraph)
export(graphToAdjList)
export(heatFilter)
export(mergeCountMatrices)
export(multi2dend)
export(plapply)
Expand Down
12 changes: 8 additions & 4 deletions R/graphs.R
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ propagateLabelsDiffusion <- function(graph, labels, max.iters=100, diffusion.fad
#' @return smoothed values for `x`
#' @family graph smoothing
#'
#' @keywords internal
#' @export
heatFilter <- function(x, l.max, order=1, offset=0, beta=30) {
exp(-beta * abs(x / l.max - offset) ** order)
}
Expand Down Expand Up @@ -396,9 +396,8 @@ smoothChebyshev <- function(lap, coeffs, signal, l.max, n.cores=1, progress.chun
#' @param l.max maximal eigenvalue of `lap` (default=NULL). If NULL, estimated from `lap`.
#' @param m numeric Maximum order of Chebyshev coeff to compute (default=50)
#' @family graph smoothing
#'
#' @export
#'
#' @keywords internal
smoothSignalOnGraph <- function(signal, filter, graph=NULL, lap=NULL, l.max=NULL, m=50, ...) {
if (is.null(lap)) {
if (is.null(graph)){
Expand All @@ -419,7 +418,12 @@ smoothSignalOnGraph <- function(signal, filter, graph=NULL, lap=NULL, l.max=NULL
}
}

l.max <- irlba::partial_eigen(lap, n=1)$values
if (is.null(l.max)) {
if (!igraph::is_connected(graph))
stop("The provided graph is not connected. It has to be connected to estimate l.max.")

l.max <- irlba::partial_eigen(lap, n=1)$values
}
coeffs <- computeChebyshevCoeffs(function(x) filter(x, l.max), m=m, l.max)
sig.smoothed <- smoothChebyshev(lap, coeffs, signal, l.max, ...)

Expand Down
15 changes: 7 additions & 8 deletions R/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ NULL
#' plapply(1:10, square, n.cores=1, progress=TRUE)
#'
#' @export
plapply <- function(..., progress=FALSE, n.cores=parallel::detectCores(), mc.preschedule=FALSE, fail.on.error=FALSE) {
plapply <- function(..., progress=FALSE, n.cores=parallel::detectCores(), mc.preschedule=FALSE, mc.allow.recursive=FALSE, fail.on.error=FALSE) {
if (progress) {
result <- pbmcapply::pbmclapply(..., mc.cores=n.cores, mc.preschedule=mc.preschedule)
result <- pbmcapply::pbmclapply(..., mc.cores=n.cores, mc.preschedule=mc.preschedule, mc.allow.recursive=mc.allow.recursive)
} else if(n.cores > 1) {
result <- parallel::mclapply(..., mc.cores=n.cores, mc.preschedule=mc.preschedule)
result <- parallel::mclapply(..., mc.cores=n.cores, mc.preschedule=mc.preschedule, mc.allow.recursive=mc.allow.recursive)
} else {
# fall back on lapply
result <- lapply(...)
}

Expand Down Expand Up @@ -118,15 +117,15 @@ sn <- function(x) {
#' @return Matrix with new columns but rows retained
#' @examples
#' library(dplyr)
#' geneUnion <- lapply(conosClusterList, colnames) %>% Reduce(union, .)
#' extendMatrix(conosClusterList[[1]], col.names=geneUnion)
#' gene.union <- lapply(conosClusterList, colnames) %>% Reduce(union, .)
#' extendMatrix(conosClusterList[[1]], col.names=gene.union)
#'
#' @export
extendMatrix <- function(mtx, col.names) {
new.names <- setdiff(col.names, colnames(mtx))
ext.mtx <- matrix(0, nrow=nrow(mtx), ncol=length(new.names))
ext.mtx <- Matrix::sparseMatrix(i=NULL, j=NULL, x=integer(), dims=c(nrow(mtx), length(new.names)))
colnames(ext.mtx) <- new.names
return(cbind(mtx, ext.mtx)[,col.names])
return(cbind(mtx, ext.mtx)[,col.names,drop=FALSE])
}

#' Merge list of count matrices into a common matrix, entering 0s for the missing entries
Expand Down
10 changes: 6 additions & 4 deletions R/plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ val2col <- function(x, gradientPalette=NULL, zlim=NULL, gradient.range.quantile=
#' Encodes logic of how to handle named-vector and functional palettes. Used primarily within embeddingGroupPlot()
#'
#' @param groups vector of cluster labels, names contain cell names
#' @param palette function, which accepts number of colors and return list of colors (i.e. see 'colorRampPalette')
#' @param palette vector or list or function (default=NULL). Accepts number of colors and return list of colors (i.e. see 'colorRampPalette')
#' @param unclassified.cell.color Color for unclassified cells (default='gray50')
#' @return vector or palette
fac2palette <- function(groups, palette, unclassified.cell.color='gray50') {
Expand All @@ -131,7 +131,9 @@ fac2palette <- function(groups, palette, unclassified.cell.color='gray50') {
return(cols)
} else {
# just take first n?
if(length(palette)<length(levels(groups))) stop("provided palette does not have enough colors to show ",length(levels(groups))," levels")
if(length(palette)<length(levels(groups))) {
stop("provided palette does not have enough colors to show ",length(levels(groups))," levels")
}
return(stats::setNames(palette[1:length(levels(groups))],levels(groups)))
}
}
Expand All @@ -143,7 +145,7 @@ fac2palette <- function(groups, palette, unclassified.cell.color='gray50') {
#' @param values values by which the color gradient is determined
#' @param gradient.range.quantile numeric Trimming quantile (default=1). Either a single number or two numbers - for lower and upper quantile.
#' @param color.range either a vector of two values explicitly specifying the values corresponding to the start/end of the gradient, or string "symmetric" or "all" (default="symmetric"). "symmetric": range will fit data, but will be symmetrized around zeros, "all": gradient will match the span of the range of the data (after gradient.range.quantile)
#' @param palette an optional palette fucntion (default=NULL). The default becomes blue-gray90-red; if the values do not straddle 0, then truncated gradients (blue-gray90 or gray90-red) will be used
#' @param palette an optional palette (default=NULL). The default becomes blue-gray90-red; if the values do not straddle 0, then truncated gradients (blue-gray90 or gray90-red) will be used
#' @param midpoint optional midpoint (default=NULL). Set for the center of the resulting range by default
#' @param oob function to determine what to do with the values outside of the range (default =scales::squish). Refer to 'oob' parameter in ggplot
#' @param return.fill boolean Whether to return fill gradients instead of color (default=FALSE)
Expand Down Expand Up @@ -379,7 +381,7 @@ styleEmbeddingPlot <- function(gg, plot.theme=NULL, title=NULL, legend.position=
#' @param size point size (default=0.8)
#' @param title plot title (default=NULL)
#' @param plot.theme theme for the plot (default=NULL)
#' @param palette function, which accepts number of colors and return list of colors (i.e. see 'colorRampPalette') (default=NULL)
#' @param palette vector or list or function (default=NULL). Accepts number of colors and return list of colors (i.e. see 'colorRampPalette') (default=NULL)
#' @param color.range controls range, in which colors are estimated (default="symmetric"). Pass "all" to estimate range based on all values of "colors", pass "data" to estimate it only based on colors, presented in the embedding. Alternatively you can pass vector of length 2 with (min, max) values.
#' @param font.size font size for cluster labels (default=c(3, 7)). It can either be single number for constant font size or pair (min, max) for font size depending on cluster size
#' @param show.ticks show ticks and tick labels (default=FALSE)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ If you find `sccore` useful for your publication, please cite:
```
Viktor Petukhov, Ramus Rydbirk, Peter Kharchenko and Evan Biederstedt
(2021). sccore: Core Utilities for Single-Cell RNA-Seq. R package
version 1.0.0. https://github.com/kharchenkolab/sccore
version 1.0.1. https://github.com/kharchenkolab/sccore
```
2 changes: 1 addition & 1 deletion man/embeddingColorsPlot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/embeddingGroupPlot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/embeddingPlot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/extendMatrix.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/fac2palette.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/heatFilter.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions man/plapply.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/smoothSignalOnGraph.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/val2ggcol.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

using namespace Rcpp;

#ifdef RCPP_USE_GLOBAL_ROSTREAM
Rcpp::Rostream<true>& Rcpp::Rcout = Rcpp::Rcpp_cout_get();
Rcpp::Rostream<false>& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get();
#endif

// as_factor
Rcpp::List as_factor(const std::vector<std::string>& vals);
RcppExport SEXP _sccore_as_factor(SEXP valsSEXP) {
Expand Down

0 comments on commit 11ead19

Please sign in to comment.