Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
timoast committed Dec 8, 2021
2 parents 10d950e + 2bf638b commit 63d61be
Show file tree
Hide file tree
Showing 27 changed files with 263 additions and 86 deletions.
16 changes: 9 additions & 7 deletions .github/workflows/cmd-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,24 @@ jobs:
- name: Query dependencies
run: |
install.packages('remotes')
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
saveRDS(remotes::dev_package_deps(), ".github/depends.Rds", version = 2)
shell: Rscript {0}

- name: Cache R packages
if: "!contains(github.event.head_commit.message, '/nocache') && runner.os != 'Linux'"
uses: actions/cache@v2
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ env.cache-version }}-${{ runner.os }}-biocversion-RELEASE_3_12-r-4.0-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ env.cache-version }}-${{ runner.os }}-biocversion-RELEASE_3_12-r-4.0-
key: ${{ env.cache-version }}-${{ runner.os }}-biocversion-RELEASE_3_12-r-4.0-2${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ env.cache-version }}-${{ runner.os }}-biocversion-RELEASE_3_12-r-4.0-2

- name: Cache R packages on Linux
if: "!contains(github.event.head_commit.message, '/nocache') && runner.os == 'Linux' "
uses: actions/cache@v2
with:
path: /home/runner/work/_temp/Library
key: ${{ env.cache-version }}-${{ runner.os }}-biocversion-RELEASE_3_12-r-4.0-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ env.cache-version }}-${{ runner.os }}-biocversion-RELEASE_3_12-r-4.0-
key: ${{ env.cache-version }}-${{ runner.os }}-biocversion-RELEASE_3_12-r-4.0-2${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ env.cache-version }}-${{ runner.os }}-biocversion-RELEASE_3_12-r-4.0-2

- name: Install Linux system dependencies
if: runner.os == 'Linux'
Expand Down Expand Up @@ -161,15 +161,15 @@ jobs:
## Pass #1 at installing dependencies
message(paste('****', Sys.time(), 'pass number 1 at installing dependencies: local dependencies ****'))
remotes::install_local(dependencies = TRUE, repos = BiocManager::repositories(), build_vignettes = TRUE, upgrade = TRUE)
remotes::install_local(repos = BiocManager::repositories(), build_vignettes = TRUE, upgrade = TRUE)
continue-on-error: true
shell: Rscript {0}

- name: Install dependencies pass 2
run: |
## Pass #2 at installing dependencies
message(paste('****', Sys.time(), 'pass number 2 at installing dependencies: any remaining dependencies ****'))
remotes::install_local(dependencies = TRUE, repos = BiocManager::repositories(), build_vignettes = TRUE, upgrade = TRUE)
remotes::install_local(repos = BiocManager::repositories(), build_vignettes = TRUE, upgrade = TRUE)
## For running the checks
message(paste('****', Sys.time(), 'installing rcmdcheck and BiocCheck ****'))
Expand All @@ -194,6 +194,8 @@ jobs:
- name: Run CMD check
env:
_R_CHECK_CRAN_INCOMING_: false
_R_CHECK_DEPENDS_ONLY_: true
_R_CHECK_FORCE_SUGGESTS_: false
run: |
rcmdcheck::rcmdcheck(
args = c("--no-build-vignettes", "--no-manual", "--timings"),
Expand Down
9 changes: 5 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: Signac
Title: Analysis of Single-Cell Chromatin Data
Version: 1.4.0
Date: 2021-09-20
Version: 1.5.0
Date: 2021-12-07
Authors@R: c(
person(given = 'Tim', family = 'Stuart', email = 'tstuart@nygenome.org', role = c('aut', 'cre'), comment = c(ORCID = '0000-0002-3044-0897')),
person(given = 'Avi', family = 'Srivastava', email = 'asrivastava@nygenome.org', role = 'aut', comment = c(ORCID = '0000-0001-9798-2079')),
Expand All @@ -12,14 +12,14 @@ Description: A framework for the analysis and exploration of single-cell chromat
The 'Signac' package contains functions for quantifying single-cell chromatin data,
computing per-cell quality control metrics, dimension reduction
and normalization, visualization, and DNA sequence motif analysis.
Reference: Stuart et al. (2020) <doi:10.1101/2020.11.09.373613>.
Reference: Stuart et al. (2021) <doi:10.1038/s41592-021-01282-5>.
Depends:
R (>= 4.0.0),
methods
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.1.1
RoxygenNote: 7.1.2
URL: https://github.com/timoast/signac, https://satijalab.org/signac
BugReports: https://github.com/timoast/signac/issues
LinkingTo: Rcpp
Expand Down Expand Up @@ -75,6 +75,7 @@ Collate:
'quantification.R'
'utilities.R'
'visualization.R'
'zzz.R'
Suggests:
testthat (>= 2.1.0),
chromVAR,
Expand Down
17 changes: 17 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# Signac 1.5.0

Bug fixes:

* Fixed bug in `FeatureMatrix()` when cells information not present in Fragment object ([#803](https://github.com/timoast/signac/issues/803))
* Fixed bug in object merging ([#804](https://github.com/timoast/signac/issues/804))
* Add ability to run `LinkPeaks()` using Ensembl IDs ([#858](https://github.com/timoast/signac/issues/858))
* Fix issue in `GeneActivity()` when gene names are `NA` ([#865](https://github.com/timoast/signac/issues/865))
* Fix bug in `FeatureMatrix()` when only one region supplied
* Allow negative values in `ExpressionPlot()` when using scaled data ([#893](https://github.com/timoast/signac/issues/893))

Other changes:

* Added `idf` parameter to `RunTFIDF()` to use precomputed IDF vector
* Added `gene.id` parameter to `GeneActivity()` to allow output genes named using gene ID ([#837](https://github.com/timoast/signac/issues/837))
* Added `sep` parameter to `ConnectionsToLinks()` ([#841](https://github.com/timoast/signac/issues/841))

# Signac 1.4.0

Bug fixes:
Expand Down
49 changes: 38 additions & 11 deletions R/links.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ GetLinkedGenes <- function(
#' CCAN that it belongs to in the second column.
#' @param threshold Threshold for retaining a coaccessible site. Links with
#' a value less than or equal to this threshold will be discarded.
#' @param sep Separators to use for strings encoding genomic coordinates.
#' First element is used to separate the chromosome from the coordinates, second
#' element is used to separate the start from end coordinate.
#'
#' @export
#' @importFrom GenomicRanges start end makeGRangesFromDataFrame
Expand All @@ -94,11 +97,16 @@ GetLinkedGenes <- function(
#'
#' @concept links
#' @return Returns a \code{\link[GenomicRanges]{GRanges}} object
ConnectionsToLinks <- function(conns, ccans = NULL, threshold = 0) {
ConnectionsToLinks <- function(
conns,
ccans = NULL,
threshold = 0,
sep = c("-", "-")
) {
# add chromosome information
chr1 <- stri_split_fixed(str = conns$Peak1, pattern = "-")
chr1 <- stri_split_fixed(str = conns$Peak1, pattern = sep[[1]])
conns$chr1 <- unlist(x = chr1)[3 * (seq_along(along.with = chr1)) - 2]
chr2 <- stri_split_fixed(str = conns$Peak2, pattern = "-")
chr2 <- stri_split_fixed(str = conns$Peak2, pattern = sep[[1]])
conns$chr2 <- unlist(x = chr2)[3 * (seq_along(along.with = chr2)) - 2]

# filter out trans-chr links
Expand All @@ -124,8 +132,8 @@ ConnectionsToLinks <- function(conns, ccans = NULL, threshold = 0) {
}

# extract genomic regions
coords.1 <- StringToGRanges(regions = conns$Peak1, sep = c("-", "-"))
coords.2 <- StringToGRanges(regions = conns$Peak2, sep = c("-", "-"))
coords.1 <- StringToGRanges(regions = conns$Peak1, sep = sep)
coords.2 <- StringToGRanges(regions = conns$Peak2, sep = sep)
chr <- seqnames(x = coords.1)

# find midpoints
Expand Down Expand Up @@ -187,6 +195,8 @@ ConnectionsToLinks <- function(conns, ccans = NULL, threshold = 0) {
#' p-value equal or greater than this value will be removed from the output.
#' @param score_cutoff Minimum absolute value correlation coefficient for a link
#' to be retained
#' @param gene.id Set to TRUE if genes in the expression assay are named
#' using gene IDs rather than gene names.
#' @param verbose Display messages
#'
#' @importFrom Seurat GetAssayData
Expand Down Expand Up @@ -227,6 +237,7 @@ LinkPeaks <- function(
n_sample = 200,
pvalue_cutoff = 0.05,
score_cutoff = 0.05,
gene.id = FALSE,
verbose = TRUE
) {
if (!inherits(x = object[[peak.assay]], what = "ChromatinAssay")) {
Expand Down Expand Up @@ -274,14 +285,12 @@ LinkPeaks <- function(
peaks.keep <- peakcounts > min.cells
genes.keep <- genecounts > min.cells
peak.data <- peak.data[peaks.keep, ]
if (is.null(x = genes.use)) {
expression.data <- expression.data[genes.keep, ]
} else {
if (!is.null(x = genes.use)) {
genes.keep <- intersect(
x = names(x = genes.keep[genes.keep]), y = genes.use
)
expression.data <- expression.data[genes.keep, , drop = FALSE]
}
expression.data <- expression.data[genes.keep, , drop = FALSE]
if (verbose) {
message(
"Testing ",
Expand All @@ -292,7 +301,20 @@ LinkPeaks <- function(
)
}
genes <- rownames(x = expression.data)
gene.coords.use <- gene.coords[gene.coords$gene_name %in% genes,]
if (gene.id) {
gene.coords.use <- gene.coords[gene.coords$gene_id %in% genes,]
gene.coords.use$gene_name <- gene.coords.use$gene_id
} else {
gene.coords.use <- gene.coords[gene.coords$gene_name %in% genes,]
}
if (length(x = gene.coords.use) == 0) {
stop("Could not find gene coordinates for requested genes")
}
if (length(x = gene.coords.use) < nrow(x = expression.data)) {
message("Found gene coordinates for ",
length(x = gene.coords.use),
" genes")
}
peaks <- granges(x = object[[peak.assay]])
peaks <- peaks[peaks.keep]
peak_distance_matrix <- DistanceToTSS(
Expand Down Expand Up @@ -518,7 +540,12 @@ LinksToGRanges <- function(linkmat, gene.coords, sep = c("-", "-")) {
#' @importFrom GenomicRanges resize
#
# @return Returns a sparse matrix
DistanceToTSS <- function(peaks, genes, distance = 200000, sep = c("-", "-")) {
DistanceToTSS <- function(
peaks,
genes,
distance = 200000,
sep = c("-", "-")
) {
tss <- resize(x = genes, width = 1, fix = 'start')
genes.extended <- suppressWarnings(
expr = Extend(
Expand Down
4 changes: 2 additions & 2 deletions R/objects.R
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,7 @@ merge.ChromatinAssay <- function(
if (all(count_nonzero > 0)) {
merged.counts <- RowMergeSparseMatrices(
mat1 = all.counts[[1]],
mat2 = all.counts[[2:length(x = all.counts)]]
mat2 = all.counts[2:length(x = all.counts)]
)
reduced.ranges <- StringToGRanges(regions = rownames(x = merged.counts))
} else {
Expand All @@ -1167,7 +1167,7 @@ merge.ChromatinAssay <- function(
if (all(data_nonzero > 0)) {
merged.data <- RowMergeSparseMatrices(
mat1 = all.data[[1]],
mat2 = all.data[[2:length(x = all.data)]]
mat2 = all.data[2:length(x = all.data)]
)
reduced.ranges <- SetIfNull(
x = reduced.ranges,
Expand Down
42 changes: 36 additions & 6 deletions R/preprocessing.R
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,8 @@ RegionStats.Seurat <- function(
#' \eqn{IDF}.
#' }
#' @param scale.factor Which scale factor to use. Default is 10000.
#' @param idf A precomputed IDF vector to use. If NULL, compute based on the
#' input data matrix.
#' @param verbose Print progress
#' @rdname RunTFIDF
#' @importFrom Matrix colSums rowSums Diagonal tcrossprod
Expand All @@ -566,6 +568,7 @@ RunTFIDF.default <- function(
assay = NULL,
method = 1,
scale.factor = 1e4,
idf = NULL,
verbose = TRUE,
...
) {
Expand All @@ -587,18 +590,41 @@ RunTFIDF.default <- function(
} else {
tf <- tcrossprod(x = object, y = Diagonal(x = 1 / npeaks))
}
rsums <- rowSums(x = object)
if (any(rsums == 0)) {
warning("Some features contain 0 total counts")
if (!is.null(x = idf)) {
precomputed_idf <- TRUE
if (!inherits(x = idf, what = "numeric")) {
stop("idf parameter must be a numeric vector")
}
if (length(x = idf) != nrow(x = object)) {
stop("Length of supplied IDF vector does not match",
" number of rows in input matrix")
}
if (any(idf == 0)) {
stop("Supplied IDF values cannot be zero")
}
if (verbose) {
message("Using precomputed IDF vector")
}
} else {
precomputed_idf <- FALSE
rsums <- rowSums(x = object)
if (any(rsums == 0)) {
warning("Some features contain 0 total counts")
}
idf <- ncol(x = object) / rsums
}
idf <- ncol(x = object) / rsums

if (method == 2) {
idf <- log(1 + idf)
if (!precomputed_idf) {
idf <- log(1 + idf)
}
} else if (method == 3) {
slot(object = tf, name = "x") <- log1p(
x = slot(object = tf, name = "x") * scale.factor
)
idf <- log(1 + idf)
if (!precomputed_idf) {
idf <- log(1 + idf)
}
}
norm.data <- Diagonal(n = length(x = idf), x = idf) %*% tf
if (method == 1) {
Expand Down Expand Up @@ -626,6 +652,7 @@ RunTFIDF.Assay <- function(
assay = NULL,
method = 1,
scale.factor = 1e4,
idf = NULL,
verbose = TRUE,
...
) {
Expand All @@ -634,6 +661,7 @@ RunTFIDF.Assay <- function(
method = method,
assay = assay,
scale.factor = scale.factor,
idf = idf,
verbose = verbose,
...
)
Expand All @@ -658,6 +686,7 @@ RunTFIDF.Seurat <- function(
assay = NULL,
method = 1,
scale.factor = 1e4,
idf = NULL,
verbose = TRUE,
...
) {
Expand All @@ -668,6 +697,7 @@ RunTFIDF.Seurat <- function(
assay = assay,
method = method,
scale.factor = scale.factor,
idf = idf,
verbose = verbose,
...
)
Expand Down
Loading

0 comments on commit 63d61be

Please sign in to comment.