Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seurat V5 compatability #406

Merged
merged 6 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: clustifyr
Title: Classifier for Single-cell RNA-seq Using Cell Clusters
Version: 1.15.1
Version: 1.15.2
Description: Package designed to aid in classifying cells from single-cell RNA sequencing data
using external reference data (e.g., bulk RNA-seq, scRNA-seq, microarray, gene lists). A
variety of correlation based methods and gene list enrichment methods are provided to assist cell
Expand Down Expand Up @@ -57,6 +57,7 @@ Imports:
methods,
SingleCellExperiment,
SummarizedExperiment,
SeuratObject,
matrixStats,
S4Vectors,
proxy,
Expand All @@ -73,7 +74,6 @@ Suggests:
BiocManager,
remotes,
shiny,
SeuratObject,
gprofiler2,
purrr,
data.table,
Expand All @@ -87,7 +87,7 @@ VignetteBuilder:
ByteCompile: true
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
LazyData: true
Config/Needs/website:
pkgdown,
Expand Down
13 changes: 12 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export(make_comb_ref)
export(marker_select)
export(matrixize_markers)
export(object_data)
export(object_loc_lookup)
export(object_ref)
export(overcluster)
export(overcluster_test)
Expand All @@ -68,8 +69,10 @@ export(ref_marker_select)
export(reverse_marker_matrix)
export(run_clustifyr_app)
export(run_gsea)
export(sce_pbmc)
export(seurat_meta)
export(seurat_ref)
export(so_pbmc)
export(write_meta)
import(Matrix)
import(dplyr)
Expand All @@ -78,9 +81,16 @@ import(ggplot2)
import(scales)
import(tibble)
importFrom(S4Vectors,DataFrame)
importFrom(SeuratObject,"DefaultAssay<-")
importFrom(SeuratObject,"Key<-")
importFrom(SeuratObject,CreateDimReducObject)
importFrom(SeuratObject,CreateSeuratObject)
importFrom(SeuratObject,DefaultAssay)
importFrom(SeuratObject,Key)
importFrom(SeuratObject,VariableFeatures)
importFrom(SingleCellExperiment,colData)
importFrom(SingleCellExperiment,logcounts)
importFrom(SummarizedExperiment,`colData<-`)
importFrom(SummarizedExperiment,"colData<-")
importFrom(cowplot,theme_cowplot)
importFrom(fgsea,fgsea)
importFrom(httr,build_url)
Expand All @@ -98,4 +108,5 @@ importFrom(stats,p.adjust)
importFrom(stats,prcomp)
importFrom(stats,quantile)
importFrom(tidyr,gather)
importFrom(utils,packageVersion)
importFrom(utils,read.csv)
5 changes: 4 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,7 @@ Changes in version 1.7.3 (2022-03-09)
+ Maintainer change

Changes in version 1.15.1 (2023-10-31)
+ Replace `Seurat` dependency with `SeuratObject`
+ Replace `Seurat` dependency with `SeuratObject`

Changes in version 1.15.2 (2024-04-03)
+ Add support for `Seurat` version 5 objects
1 change: 1 addition & 0 deletions R/clustifyR-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
#' @importFrom cowplot theme_cowplot
#' @importFrom fgsea fgsea
#' @importFrom methods is
#' @importFrom SeuratObject Key Key<- DefaultAssay DefaultAssay<-
## usethis namespace: end
NULL
24 changes: 0 additions & 24 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,6 @@
#' @source `[pbmc_matrix]` processed by Seurat
"pbmc_vargenes"

#' Small clustered Seurat2 object
#'
#' @family data
#' @source `[pbmc_small]` processed by seurat
"s_small"

#' Small clustered Seurat3 object
#'
#' @family data
#' @source `[pbmc_small]` processed by Seurat
"s_small3"

#' Small SingleCellExperiment object
#'
#' @family data
#' @source \url{https://github.com/hemberg-lab/scRNA.seq.datasets/blob/master/R/segerstolpe.R}
"sce_small"

#' reference matrix from seurat citeseq CBMC tutorial
#'
#' @family data
Expand All @@ -73,12 +55,6 @@
#' @source \url{https://satijalab.org/seurat/v3.0/multimodal_vignette.html#identify-differentially-expressed-proteins-between-clusters}
"cbmc_m"

#' lookup table for single cell object structures
#'
#' @family data
#' @source various packages
"object_loc_lookup"

#' table of references stored in clustifyrdata
#'
#' @family data
Expand Down
72 changes: 42 additions & 30 deletions R/main.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ clustify <- function(input, ...) {
#' metadata = pbmc_meta,
#' ref_mat = cbmc_ref,
#' query_genes = pbmc_vargenes,
#' cluster_col = "classified",
#' cluster_col = "RNA_snn_res.0.5",
#' verbose = TRUE
#' )
#'
Expand All @@ -69,28 +69,40 @@ clustify <- function(input, ...) {
#' metadata = pbmc_meta,
#' ref_mat = cbmc_ref,
#' query_genes = pbmc_vargenes,
#' cluster_col = "classified",
#' cluster_col = "RNA_snn_res.0.5",
#' compute_method = "cosine"
#' )
#'
#'
#' # Annotate a SingleCellExperiment object
#' sce <- sce_pbmc()
#' clustify(
#' sce,
#' cbmc_ref,
#' cluster_col = "clusters",
#' obj_out = TRUE,
#' per_cell = FALSE,
#' dr = "umap"
#' )
#'
#' # Annotate a Seurat object
#' so <- so_pbmc()
#' clustify(
#' s_small3,
#' so,
#' cbmc_ref,
#' cluster_col = "RNA_snn_res.1",
#' cluster_col = "seurat_clusters",
#' obj_out = TRUE,
#' per_cell = FALSE,
#' dr = "tsne"
#' dr = "umap"
#' )
#'
#' # Annotate (and return) a Seurat object per-cell
#' clustify(
#' input = s_small3,
#' input = so,
#' ref_mat = cbmc_ref,
#' cluster_col = "RNA_snn_res.1",
#' cluster_col = "seurat_clusters",
#' obj_out = TRUE,
#' per_cell = TRUE,
#' dr = "tsne"
#' dr = "umap"
#' )
#' @export
clustify.default <- function(input,
Expand All @@ -107,7 +119,7 @@ clustify.default <- function(input,
lookuptable = NULL,
rm0 = FALSE,
obj_out = TRUE,
seurat_out = TRUE,
seurat_out = obj_out,
vec_out = FALSE,
rename_prefix = NULL,
threshold = "auto",
Expand Down Expand Up @@ -161,8 +173,9 @@ clustify.default <- function(input,
stop("given `cluster_col` is not a column in `metadata`", call. = FALSE)
}

if (length(query_genes) == 0) {
message("var.features not found, using all genes instead")
if (is.null(query_genes) || length(query_genes) == 0) {
message("Variable features not available, using all genes instead\n",
"consider supplying variable features to `query_genes` argument.")
query_genes <- NULL
}

Expand Down Expand Up @@ -248,8 +261,8 @@ clustify.default <- function(input,
message("similarity computation completed, matrix of ", dim(res)[1], " x ", dim(res)[2], ", preparing output")
}

if ((obj_out &&
seurat_out) &&
obj_out <- seurat_out
if (obj_out &&
!inherits(input_original, c(
"matrix",
"Matrix",
Expand Down Expand Up @@ -324,8 +337,8 @@ clustify.Seurat <- function(input,
pseudobulk_method = "mean",
use_var_genes = TRUE,
dr = "umap",
seurat_out = TRUE,
obj_out = TRUE,
seurat_out = obj_out,
vec_out = FALSE,
threshold = "auto",
verbose = TRUE,
Expand Down Expand Up @@ -380,8 +393,8 @@ clustify.Seurat <- function(input,
if (n_perm != 0) {
res <- -log(res$p_val + .01, 10)
}

if (!(seurat_out && obj_out) && !vec_out || vec) {
obj_out <- seurat_out
if (!obj_out && !vec_out || vec) {
res
} else {
df_temp <- cor_to_call(
Expand Down Expand Up @@ -449,8 +462,8 @@ clustify.SingleCellExperiment <- function(input,
pseudobulk_method = "mean",
use_var_genes = TRUE,
dr = "umap",
seurat_out = TRUE,
obj_out = TRUE,
seurat_out = obj_out,
vec_out = FALSE,
threshold = "auto",
verbose = TRUE,
Expand Down Expand Up @@ -501,8 +514,8 @@ clustify.SingleCellExperiment <- function(input,
if (n_perm != 0) {
res <- -log(res$p_val + .01, 10)
}

if (!(seurat_out && obj_out) && !vec_out) {
obj_out <- seurat_out
if (!obj_out && !vec_out) {
res
} else {
df_temp <- cor_to_call(
Expand Down Expand Up @@ -588,7 +601,7 @@ clustify_lists <- function(input, ...) {
}

#' @rdname clustify_lists
#' @param input single-cell expression matrix or Seurat object
#' @param input single-cell expression matrix, Seurat object, or SingleCellExperiment
#' @param marker matrix or dataframe of candidate genes for each cluster
#' @param marker_inmatrix whether markers genes are already in preprocessed
#' matrix form
Expand Down Expand Up @@ -658,7 +671,7 @@ clustify_lists.default <- function(input,
output_high = TRUE,
lookuptable = NULL,
obj_out = TRUE,
seurat_out = TRUE,
seurat_out = obj_out,
vec_out = FALSE,
rename_prefix = NULL,
threshold = 0,
Expand Down Expand Up @@ -778,10 +791,9 @@ clustify_lists.default <- function(input,
if (verbose) {
message("similarity computation completed, matrix of ", dim(res)[1], " x ", dim(res)[2], ", preparing output")
}

obj_out <- seurat_out
if ((!inherits(input_original, c("matrix", "Matrix", "data.frame")) &&
obj_out &&
seurat_out) || (vec_out &&
obj_out ) || (vec_out &&
inherits(input_original, c(
"matrix",
"Matrix",
Expand Down Expand Up @@ -840,8 +852,8 @@ clustify_lists.Seurat <- function(input,
metric = "hyper",
output_high = TRUE,
dr = "umap",
seurat_out = TRUE,
obj_out = TRUE,
seurat_out = obj_out,
vec_out = FALSE,
threshold = 0,
rename_prefix = NULL,
Expand Down Expand Up @@ -885,8 +897,8 @@ clustify_lists.Seurat <- function(input,
details_out = details_out,
...
)

if (!(seurat_out && obj_out) && !vec_out || vec) {
obj_out <- seurat_out
if (!obj_out && !vec_out || vec) {
res
} else {
if (metric != "consensus") {
Expand Down Expand Up @@ -943,8 +955,8 @@ clustify_lists.SingleCellExperiment <- function(input,
metric = "hyper",
output_high = TRUE,
dr = "umap",
seurat_out = TRUE,
obj_out = TRUE,
seurat_out = obj_out,
vec_out = FALSE,
threshold = 0,
rename_prefix = NULL,
Expand Down Expand Up @@ -986,7 +998,7 @@ clustify_lists.SingleCellExperiment <- function(input,
...
)

if (!(seurat_out && obj_out) && !vec_out || vec) {
if (!obj_out && !vec_out || vec) {
res
} else {
df_temp <- cor_to_call(
Expand Down
Loading
Loading