Skip to content

Commit

Permalink
Add utility method to convert matrices to dgCMatrix
Browse files Browse the repository at this point in the history
  • Loading branch information
saketkc committed Aug 19, 2022
1 parent 6c5d284 commit 3146ea9
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 11 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: sctransform
Type: Package
Title: Variance Stabilizing Transformations for Single Cell UMI Data
Version: 0.3.3.9000
Version: 0.3.3.9001
Date: 2022-01-10
Authors@R: c(
person(given = "Christoph", family = "Hafemeister", email = "christoph.hafemeister@nyu.edu", role = "aut", comment = c(ORCID = "0000-0001-6365-8254")),
Expand All @@ -13,7 +13,7 @@ Description: A normalization method for single-cell UMI count data using a
negative binomial regression model with regularized parameters. As part of the
same regression framework, this package also provides functions for
batch correction, and data correction. See Hafemeister and Satija (2019)
<doi:10.1186/s13059-019-1874-1>, and Choudhary and Satija (2021) <doi:10.1101/2021.07.07.451498>
<doi:10.1186/s13059-019-1874-1>, and Choudhary and Satija (2022) <doi:10.1186/s13059-021-02584-9>
for more details.
URL: https://github.com/satijalab/sctransform
BugReports: https://github.com/satijalab/sctransform/issues
Expand Down
2 changes: 1 addition & 1 deletion R/denoise.R
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ correct_counts <- function(x, umi, cell_attr = x$cell_attr, scale_factor = NA, v
y.res <- mu + pearson_residual * sqrt(variance)
y.res <- round(y.res, 0)
y.res[y.res < 0] <- 0
corrected_data[[length(corrected_data) + 1]] <- as(as(as(y.res, "dMatrix"), "generalMatrix"), "CsparseMatrix")
corrected_data[[length(corrected_data) + 1]] <- make.sparse(mat = y.res)
if (verbosity > 1) {
setTxtProgressBar(pb, i)
}
Expand Down
2 changes: 1 addition & 1 deletion R/generate.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ generate <- function(vst_out, genes = rownames(vst_out$model_pars_fit),
x <- MASS::rnegbin(n = length(gene.mu), mu = gene.mu, theta = theta[gene])
return(x)
}))
x.sim <- as(as(as(x.sim, "dMatrix"), "generalMatrix"), "CsparseMatrix")
x.sim <- make.sparse(mat = x.sim)
return(x.sim)
}
9 changes: 9 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -524,3 +524,12 @@ get_nz_median2 <- function(umi){
return (median(umi@x))
}

#' Convert a given matrix to dgCMatrix
#'
#' @param matrix Input matrix
#'
#' @return A dgCMatrix
make.sparse <- function(mat){
mat <- as(object = mat, Class = "Matrix")
return (as(object = as(object = as(object = mat, Class = "dMatrix"), Class = "generalMatrix"), Class = "CsparseMatrix"))
}
2 changes: 1 addition & 1 deletion R/vst.R
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ vst <- function(umi,
} else {
rv$umi_corrected <- sctransform::correct(rv, do_round = TRUE, do_pos = TRUE, scale_factor = scale_factor,
verbosity = verbosity)
rv$umi_corrected <- as(as(as(rv$umi_corrected, "dMatrix"), "generalMatrix"), "CsparseMatrix")
rv$umi_corrected <- make.sparse(mat = rv$umi_corrected)
}
}

Expand Down
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# sctransform
## R package for normalization and variance stabilization of single-cell RNA-seq data using regularized negative binomial regression

The sctransform package was developed by Christoph Hafemeister in [Rahul Satija's lab](https://satijalab.org/) at the New York Genome Center and described in [Hafemeister and Satija, Genome Biology 2019](https://genomebiology.biomedcentral.com/articles/10.1186/s13059-019-1874-1). Recent updates are described in [(Choudhary and Satija, Genome Biology, in press)](https://doi.org/10.1101/2021.07.07.451498). Core functionality of this package has been integrated into [Seurat](https://satijalab.org/seurat/), an R package designed for QC, analysis, and exploration of single cell RNA-seq data.
The sctransform package was developed by Christoph Hafemeister in [Rahul Satija's lab](https://satijalab.org/) at the New York Genome Center and described in [Hafemeister and Satija, Genome Biology 2019](https://genomebiology.biomedcentral.com/articles/10.1186/s13059-019-1874-1). Recent updates are described in [(Choudhary and Satija, Genome Biology, 2022)](https://doi.org/10.1186/s13059-021-02584-9).
Core functionality of this package has been integrated into [Seurat](https://satijalab.org/seurat/), an R package designed for QC, analysis, and exploration of single cell RNA-seq data.

## Quick start

Expand Down Expand Up @@ -43,15 +44,12 @@ Available vignettes:
- [Using sctransform in Seurat](https://htmlpreview.github.io/?https://github.com/satijalab/sctransform/blob/supp_html/supplement/seurat.html)
- [Examples of how to perform normalization, feature selection, integration, and differential expression with sctransform v2 regularization](https://satijalab.org/seurat/articles/sctransform_v2_vignette.html)

## Known Issues

* `node stack overflow` error when Rfast package is loaded. The Rfast package does not play nicely with the future.apply package. Try to avoid loading the Rfast package. See discussions: https://github.com/RfastOfficial/Rfast/issues/5 https://github.com/satijalab/sctransform/issues/108

Please use [the issue tracker](https://github.com/satijalab/sctransform/issues) if you encounter a problem

## References

- Hafemeister, C. & Satija, R. Normalization and variance stabilization of single-cell RNA-seq data using regularized negative binomial regression. Genome Biol 20, 296 (December 23, 2019). [https://doi.org/10.1186/s13059-019-1874-1](https://doi.org/10.1186/s13059-019-1874-1). An early version of this work was used in the paper [Developmental diversification of cortical inhibitory interneurons, Nature 555, 2018](https://github.com/ChristophH/in-lineage).
- Hafemeister, C. & Satija, R. Normalization and variance stabilization of single-cell RNA-seq data using regularized negative binomial regression. Genome Biology 20, 296 (2019). [https://doi.org/10.1186/s13059-019-1874-1](https://doi.org/10.1186/s13059-019-1874-1). An early version of this work was used in the paper [Developmental diversification of cortical inhibitory interneurons, Nature 555, 2018](https://github.com/ChristophH/in-lineage).

- Choudhary, S. & Satija, R. Comparison and evaluation of statistical error models for scRNA-seq. bioRxiv (2021). [https://doi.org/10.1101/2021.07.07.451498](https://doi.org/10.1101/2021.07.07.451498)
- Choudhary, S. & Satija, R. Comparison and evaluation of statistical error models for scRNA-seq. Genome Biology 23.1 (2022). [https://doi.org/10.1186/s13059-021-02584-9](https://doi.org/10.1186/s13059-021-02584-9)

0 comments on commit 3146ea9

Please sign in to comment.