Skip to content

Commit

Permalink
Merge pull request #723 from cole-trapnell-lab/bge.develop.add_diagno…
Browse files Browse the repository at this point in the history
…stics.20240429

Bge.develop.add diagnostics.20240429
  • Loading branch information
brgew authored May 24, 2024
2 parents 1619e50 + 70585f0 commit 7dfc3b2
Show file tree
Hide file tree
Showing 31 changed files with 1,468 additions and 762 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/check_on_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ jobs:
# which is found at the Github Packages tab.
# image: ghcr.io/cole-trapnell-lab/monocle3_depend.v1.3.0_20221103:v1 # old and replaced
image: ghcr.io/cole-trapnell-lab/monocle3_depend:v1.4.5_1
# image: ghcr.io/cole-trapnell-lab/monocle3_depend:v1.4.18_1

#
#
Expand Down Expand Up @@ -121,6 +122,7 @@ jobs:
# Rscript -e 'install.packages(c("ggdist", "ggforce"))'
- name: Run R CMD build and R CMD check
run: |
Rscript -e 'remotes::install_github("bnprks/BPCells")'
R CMD build .
R CMD check monocle3*tar.gz
shell: bash
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: monocle3
Title: Clustering, Differential Expression, and Trajectory Analysis for
Single-Cell RNA-Seq
Version: 1.4.17
Version: 1.4.18
Authors@R: c(
person(given = "Hannah",
family = "Pliner",
Expand Down
15 changes: 9 additions & 6 deletions R/alignment.R
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,16 @@ align_cds <- function(cds,
nn_index <- make_nn_index(subject_matrix=SingleCellExperiment::reducedDims(cds)[['Aligned']],
nn_control=nn_control,
verbose=verbose)
cds <- set_cds_nn_index(cds=cds,
reduction_method='Aligned',
nn_index,
verbose=verbose)
cds <- tryCatch(set_cds_nn_index(cds=cds,
reduction_method='Aligned',
nn_index,
verbose=verbose),
error = function(c) { stop(paste0(trimws(c), '\n* error in align_cds')) })
}
else {
cds <- tryCatch(clear_cds_nn_index(cds=cds, reduction_method='Aligned', 'all'),
error = function(c) { stop(paste0(trimws(c), '\n* error in align_cds')) })
}
else
cds <- clear_cds_nn_index(cds=cds, reduction_method='Aligned', 'all')

cds
}
Expand Down
96 changes: 0 additions & 96 deletions R/apply_transforms.R

This file was deleted.

81 changes: 43 additions & 38 deletions R/cluster_cells.R
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,16 @@ cluster_cells <- function(cds,
message("Running ", cluster_method, " clustering algorithm ...")

if(cluster_method=='louvain') {
cluster_result <- louvain_clustering(data=reduced_dim_res,
pd=colData(cds),
weight=weight,
nn_index=nn_index,
k=k,
nn_control=nn_control,
louvain_iter=num_iter,
random_seed=random_seed,
verbose=verbose)
cluster_result <- tryCatch(louvain_clustering(data=reduced_dim_res,
pd=colData(cds),
weight=weight,
nn_index=nn_index,
k=k,
nn_control=nn_control,
louvain_iter=num_iter,
random_seed=random_seed,
verbose=verbose),
error = function(c) { stop(paste0(trimws(c), '\n* error in cluster_cells')) })

if (length(unique(cluster_result$optim_res$membership)) > 1) {
cluster_graph_res <- compute_partitions(cluster_result$g,
Expand All @@ -219,16 +220,17 @@ cluster_cells <- function(cds,
}
else if(cluster_method=='leiden'){
cds <- add_citation(cds, "leiden")
cluster_result <- leiden_clustering(data=reduced_dim_res,
pd=colData(cds),
weight=weight,
nn_index=nn_index,
k=k,
nn_control=nn_control,
num_iter=num_iter,
resolution_parameter=resolution,
random_seed=random_seed,
verbose=verbose, ...)
cluster_result <- tryCatch(leiden_clustering(data=reduced_dim_res,
pd=colData(cds),
weight=weight,
nn_index=nn_index,
k=k,
nn_control=nn_control,
num_iter=num_iter,
resolution_parameter=resolution,
random_seed=random_seed,
verbose=verbose, ...),
error = function(c) { stop(paste0(trimws(c), '\n* error in cluster_cells')) })

if(length(unique(cluster_result$optim_res$membership)) > 1) {
cluster_graph_res <- compute_partitions(cluster_result$g,
Expand Down Expand Up @@ -290,11 +292,12 @@ cluster_cells_make_graph <- function(data,
if(is.null(nn_index)) {
nn_index <- make_nn_index(subject_matrix=data, nn_control=nn_control, verbose=verbose)
}
tmp <- search_nn_index(query_matrix=data,
nn_index=nn_index,
k=k+1,
nn_control=nn_control,
verbose=verbose)
tmp <- tryCatch(search_nn_index(query_matrix=data,
nn_index=nn_index,
k=k+1,
nn_control=nn_control,
verbose=verbose),
error = function(c) { stop(paste0(trimws(c), '\n* error in cluster_cells_make_graph')) })
if(nn_method == 'annoy' || nn_method == 'hnsw') {
tmp <- swap_nn_row_index_point(nn_res=tmp, verbose=verbose)
}
Expand Down Expand Up @@ -350,13 +353,14 @@ louvain_clustering <- function(data,
if(!identical(cell_names, row.names(pd)))
stop("Phenotype and row name from the data doesn't match")

graph_result <- cluster_cells_make_graph(data=data,
weight=weight,
cell_names=cell_names,
nn_index,
k=k,
nn_control=nn_control,
verbose=verbose)
graph_result <- tryCatch(cluster_cells_make_graph(data=data,
weight=weight,
cell_names=cell_names,
nn_index,
k=k,
nn_control=nn_control,
verbose=verbose),
error = function(c) { stop(paste0(trimws(c), '\n* error in louvain_clustering')) })

if(verbose)
message(" Run louvain clustering ...")
Expand Down Expand Up @@ -470,13 +474,14 @@ leiden_clustering <- function(data,
if(!identical(cell_names, row.names(pd)))
stop("Phenotype and row name from the data don't match")

graph_result <- cluster_cells_make_graph(data=data,
weight=weight,
cell_names=cell_names,
nn_index,
k=k,
nn_control=nn_control,
verbose=verbose)
graph_result <- tryCatch(cluster_cells_make_graph(data=data,
weight=weight,
cell_names=cell_names,
nn_index,
k=k,
nn_control=nn_control,
verbose=verbose),
error = function(c) { stop(paste0(trimws(c), '\n* error in leiden_clustering')) })

if(verbose)
message(" Run leiden clustering ...")
Expand Down
27 changes: 14 additions & 13 deletions R/cluster_genes.R
Original file line number Diff line number Diff line change
Expand Up @@ -191,20 +191,20 @@ find_gene_modules <- function(cds,
reduced_dim_res <- umap_res

if(verbose)

message("Running leiden clustering algorithm ...")

cluster_result <- leiden_clustering(data=reduced_dim_res,
pd=rowData(cds)[row.names(reduced_dim_res),,drop=FALSE],
weight=weight,
nn_index=NULL,
k=k,
nn_control=nn_control,
num_iter=leiden_iter,
resolution_parameter=resolution,
random_seed=random_seed,
verbose=verbose,
...)
cluster_result <- tryCatch(leiden_clustering(data=reduced_dim_res,
pd=rowData(cds)[row.names(reduced_dim_res),,drop=FALSE],
weight=weight,
nn_index=NULL,
k=k,
nn_control=nn_control,
num_iter=leiden_iter,
resolution_parameter=resolution,
random_seed=random_seed,
verbose=verbose,
...),
error = function(c) { stop(paste0(trimws(c), '\n* error in find_gene_modules')) })

cluster_graph_res <- compute_partitions(cluster_result$g,
cluster_result$optim_res,
Expand Down Expand Up @@ -463,7 +463,8 @@ aggregate_gene_expression <- function(cds,
cell_agg_fun="mean"){
if (is.null(gene_group_df) && is.null(cell_group_df))
stop("one of either gene_group_df or cell_group_df must not be NULL.")
agg_mat <- normalized_counts(cds, norm_method=norm_method, pseudocount=pseudocount)
agg_mat <- tryCatch(normalized_counts(cds, norm_method=norm_method, pseudocount=pseudocount),
error = function(c) { stop(paste0(trimws(c), '\n* error in aggregate_gene_expression')) })
if (is.null(gene_group_df) == FALSE){
gene_group_df <- as.data.frame(gene_group_df)
gene_group_df <- gene_group_df[gene_group_df[,1] %in%
Expand Down
4 changes: 3 additions & 1 deletion R/expr_models.R
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,9 @@ fit_model_helper <- function(x,
))
FM_summary = summary(FM_fit)
if (clean_model){
FM_fit = clean_model_object(FM_fit)
FM_fit <- tryCatch(clean_model_object(FM_fit),
error = function(c) { stop(paste0(trimws(c), '\n* error in fit_model_helper')) })

if (class(FM_fit)[1] == "glmerMod"){
FM_summary = clean_glmerMod_summary_object(FM_summary)
}
Expand Down
23 changes: 14 additions & 9 deletions R/find_markers.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,20 @@ top_markers <- function(cds,
# For each gene compute the fraction of cells expressing it within each group
# in a matrix thats genes x cell groups

cluster_binary_exprs = as.matrix(aggregate_gene_expression(cds,
cell_group_df=cell_group_df,
norm_method="binary",
scale_agg_values=FALSE))

cluster_mean_exprs = as.matrix(aggregate_gene_expression(cds,
cell_group_df=cell_group_df,
norm_method="size_only",
scale_agg_values=FALSE))
tmp_matrix <- tryCatch(aggregate_gene_expression(cds,
cell_group_df=cell_group_df,
norm_method="binary",
scale_agg_values=FALSE),
error = function(c) { stop(paste0(trimws(c), '\n* error in top_markers')) })

cluster_binary_exprs = as.matrix(tmp_matrix)

tmp_matrix <- tryCatch(aggregate_gene_expression(cds,
cell_group_df=cell_group_df,
norm_method="size_only",
scale_agg_values=FALSE),
error = function(c) { stop(paste0(trimws(c), '\n* error in top_markers')) })
cluster_mean_exprs = as.matrix(tmp_matrix)

# bge the cluster_binary_exprs and cluster_mean_exprs pairs appear to be the same when run with dgCMatrix vs BPCells matrix

Expand Down
Loading

0 comments on commit 7dfc3b2

Please sign in to comment.