Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
hpliner committed Sep 3, 2022
2 parents a082514 + 626a4fc commit ca6772b
Show file tree
Hide file tree
Showing 63 changed files with 20,676 additions and 405 deletions.
7 changes: 4 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: cicero
Type: Package
Title: Precict cis-co-accessibility from single-cell chromatin accessibility data
Version: 1.11.1
Title: Predict cis-co-accessibility from single-cell chromatin accessibility data
Version: 1.13.4
Authors@R: c(
person("Hannah", "Pliner", email = "hpliner@uw.edu", role = c("aut", "cre")),
person("Cole", "Trapnell", email = "coletrap@uw.edu", role = c("aut")))
Expand Down Expand Up @@ -40,10 +40,11 @@ Imports:
tidyr,
VGAM (>= 1.0-5),
utils
RoxygenNote: 7.1.0
RoxygenNote: 7.1.2
Suggests:
AnnotationDbi (>= 1.38.2),
knitr,
markdown,
rmarkdown,
rtracklayer (>= 1.36.6),
testthat,
Expand Down
4 changes: 2 additions & 2 deletions R/aggregate.R
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ aggregate_by_cell_bin <- function(cds, group_col) {
lowerDetectionLimit=0))

compart_cds <- detectGenes(compart_cds, min_expr=0.1)
compart_cds <- estimateSizeFactors(compart_cds)
compart_cds <- estimateDispersions(compart_cds)
compart_cds <- estimateSizeFactorsSimp(compart_cds)
compart_cds <- estimateDispersionsSimp(compart_cds)

fData(compart_cds)$use_for_ordering <- FALSE

Expand Down
32 changes: 27 additions & 5 deletions R/runCicero.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@
#' @param size_factor_normalize Logical, should accessibility values be
#' normalized by size factor?
#' @param silent Logical, should warning and info messages be printed?
#' @param return_agg_info Logical, should a list of the assignments of cells to
#' aggregated bins be output? When \code{TRUE}, this function returns a list
#' of two items, first, the aggregated CDS object and second, a data.frame
#' with the binning information.
#'
#' @details Aggregation of similar cells is done using a k-nearest-neighbors
#' graph and a randomized "bagging" procedure. Details are available in the
#' publication that accompanies this package. Run \code{citation("cicero")}
#' for publication details. KNN is calculated using
#' \code{\link[FNN]{knn.index}}
#'
#' @return Aggregated CDS object.
#' @return Aggregated CDS object. If return_agg_info is \code{TRUE}, a list
#' of the aggregated CDS object and a data.frame of aggregation info.
#' @export
#'
#' @examples
Expand All @@ -46,7 +51,8 @@ make_cicero_cds <- function(cds,
k=50,
summary_stats = NULL,
size_factor_normalize = TRUE,
silent = FALSE) {
silent = FALSE,
return_agg_info = FALSE) {

assertthat::assert_that(is(cds, "CellDataSet"))
assertthat::assert_that(is.data.frame(reduced_coordinates) |
Expand All @@ -73,6 +79,7 @@ make_cicero_cds <- function(cds,
}
assertthat::assert_that(is.logical(size_factor_normalize))
assertthat::assert_that(is.logical(silent))
assertthat::assert_that(is.logical(return_agg_info))

reduced_coordinates <- as.data.frame(reduced_coordinates)

Expand Down Expand Up @@ -128,12 +135,24 @@ make_cicero_cds <- function(cds,
"\nMean shared cells bin-bin: ", mean(shared),
"\nMedian shared cells bin-bin: ", median(shared)))

if (mean(shared)/k > .1) warning("On average, more than 10% of cells are shared between paired bins.")
if (mean(shared)/k > .1)
warning("On average, more than 10% of cells are shared between paired bins.")
}

exprs_old <- exprs(cds)

mask <- sapply(seq_len(nrow(cell_sample)), function(x) seq_len(ncol(exprs_old)) %in% cell_sample[x,,drop=FALSE])
mask <- sapply(seq_len(nrow(cell_sample)),
function(x) seq_len(ncol(exprs_old)) %in% cell_sample[x,,drop=FALSE])

if (return_agg_info) {
row.names(mask) <- colnames(exprs_old)
colnames(mask) <- paste0("agg_", chosen)
agg_map <- reshape2::melt(mask)
agg_map <- agg_map[agg_map$value,]
agg_map$value <- NULL
names(agg_map) <- c("cell", "agg_cell")
}

mask <- Matrix::Matrix(mask)
new_exprs <- exprs_old %*% mask

Expand Down Expand Up @@ -176,7 +195,7 @@ make_cicero_cds <- function(cds,
lowerDetectionLimit=0))

cicero_cds <- monocle::detectGenes(cicero_cds, min_expr = .1)
cicero_cds <- BiocGenerics::estimateSizeFactors(cicero_cds)
cicero_cds <- estimateSizeFactorsSimp(cicero_cds)
#cicero_cds <- suppressWarnings(BiocGenerics::estimateDispersions(cicero_cds))

if (any(!c("chr", "bp1", "bp2") %in% names(fData(cicero_cds)))) {
Expand All @@ -192,6 +211,9 @@ make_cicero_cds <- function(cds,
t(t(Biobase::exprs(cicero_cds))/Biobase::pData(cicero_cds)$Size_Factor)
}

if (return_agg_info) {
return(list(cicero_cds, agg_map))
}
cicero_cds
}

Expand Down
Loading

0 comments on commit ca6772b

Please sign in to comment.