Skip to content

Commit

Permalink
replace Seurat dependency with SeuratObject (#402)
Browse files Browse the repository at this point in the history
* bump x.y.z version to even y prior to creation of RELEASE_3_18 branch

* bump x.y.z version to odd y following creation of RELEASE_3_18 branch

* Seurat -> SeuratObject

* bump version

* test on 3.18

---------

Co-authored-by: J Wokaty <[email protected]>
  • Loading branch information
kriemo and jwokaty authored Nov 7, 2023
1 parent df4193c commit e59930a
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 57 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/check-bioc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ jobs:
fail-fast: false
matrix:
config:
- { os: ubuntu-latest, r: '4.3', bioc: '3.17', cont: "bioconductor/bioconductor_docker:RELEASE_3_17", rspm: "https://packagemanager.posit.co/cran/__linux__/jammy/latest" }
- { os: windows-latest, r: '4.3', bioc: '3.17'}
- { os: ubuntu-latest, r: '4.3', bioc: '3.18', cont: "bioconductor/bioconductor_docker:RELEASE_3_18", rspm: "https://packagemanager.posit.co/cran/__linux__/jammy/latest" }
- { os: windows-latest, r: '4.3', bioc: '3.18'}
## Check https://github.com/r-lib/actions/tree/master/examples
## for examples using the http-user-agent
env:
Expand Down Expand Up @@ -106,16 +106,16 @@ jobs:
uses: actions/cache@v3
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ env.cache-version }}-${{ runner.os }}-biocversion-RELEASE_3_17-r-4.3-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ env.cache-version }}-${{ runner.os }}-biocversion-RELEASE_3_17-r-4.3-
key: ${{ env.cache-version }}-${{ runner.os }}-biocversion-RELEASE_3_18-r-4.3-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ env.cache-version }}-${{ runner.os }}-biocversion-RELEASE_3_18-r-4.3-

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

- name: Install Linux system dependencies
if: runner.os == 'Linux'
Expand Down Expand Up @@ -289,7 +289,7 @@ jobs:
if: failure()
uses: actions/upload-artifact@master
with:
name: ${{ runner.os }}-biocversion-RELEASE_3_17-r-4.3-results
name: ${{ runner.os }}-biocversion-RELEASE_3_18-r-4.3-results
path: check

## Note that DOCKER_PASSWORD is really a token for your dockerhub
Expand Down
4 changes: 2 additions & 2 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.13.1
Version: 1.15.1
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 @@ -73,7 +73,7 @@ Suggests:
BiocManager,
remotes,
shiny,
Seurat,
SeuratObject,
gprofiler2,
purrr,
data.table,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,4 @@ importFrom(stats,p.adjust)
importFrom(stats,prcomp)
importFrom(stats,quantile)
importFrom(tidyr,gather)
importFrom(utils,read.csv)
5 changes: 4 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,7 @@ Changes in version 1.5.2 (2021-10-04)

Changes in version 1.7.3 (2022-03-09)
+ `vec_out` option for directly getting classification results as a vector, to be inserted into other metadata/workflow
+ Maintainer change
+ Maintainer change

Changes in version 1.15.1 (2023-10-31)
+ Replace `Seurat` dependency with `SeuratObject`
4 changes: 2 additions & 2 deletions R/main.R
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ clustify.Seurat <- function(input,
}
}

if ("Seurat" %in% loadedNamespaces()) {
if ("SeuratObject" %in% loadedNamespaces()) {
s_object <- write_meta(s_object, df_temp_full)
return(s_object)
} else {
Expand Down Expand Up @@ -917,7 +917,7 @@ clustify_lists.Seurat <- function(input,
}
}

if ("Seurat" %in% loadedNamespaces()) {
if ("SeuratObject" %in% loadedNamespaces()) {
s_object <- write_meta(s_object, df_temp_full)
return(s_object)
} else {
Expand Down
26 changes: 10 additions & 16 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,11 @@ plot_dims <- function(data,
do_legend = TRUE,
do_repel = TRUE) {
# add backticks to allow special characters in column names
x_col <- paste0("`", x, "`")
y_col <- paste0("`", y, "`")

# If feature is not provided return unlabeled plot
if (is.null(feature)) {
p <- ggplot2::ggplot(data, ggplot2::aes_string(x_col, y_col)) +
ggplot2::geom_point(size = pt_size) +
p <- ggplot(data, aes(.data[[x]], .data[[y]])) +
geom_point(size = pt_size) +
cowplot::theme_cowplot()

if (!is.null(d_cols)) {
Expand Down Expand Up @@ -79,21 +77,17 @@ plot_dims <- function(data,
data <- dplyr::arrange(data, !!dplyr::sym(feature))

if (!is.null(alpha_col)) {
p <- ggplot2::ggplot(data, ggplot2::aes_string(x_col, y_col)) +
geom_point(ggplot2::aes_string(
color = paste0("`", feature, "`"),
alpha = paste0("`", alpha_col, "`")
p <- ggplot(data, aes(.data[[x]], .data[[y]])) +
geom_point(aes(
color = .data[[feature]],
alpha = .data[[alpha_col]]
), # backticks protect special character gene names
size = pt_size
) +
scale_alpha_continuous(range = c(0, 1))
} else {
p <- ggplot2::ggplot(data, ggplot2::aes_string(x_col, y_col)) +
ggplot2::geom_point(ggplot2::aes_string(color = paste0(
"`",
feature,
"`"
)),
p <- ggplot(data, aes(.data[[x]], .data[[y]])) +
geom_point(aes(color = .data[[feature]]),
size = pt_size
)
}
Expand Down Expand Up @@ -177,7 +171,7 @@ plot_dims <- function(data,
colnames(alldata) <- colnames(centers)
alldata <- rbind(alldata, centers)
p <- p +
ggplot2::geom_point(
geom_point(
data = alldata,
mapping = aes(
x = !!dplyr::sym("t1"),
Expand All @@ -200,7 +194,7 @@ plot_dims <- function(data,
)
} else {
p <- p +
ggplot2::geom_text(
geom_text(
data = centers,
mapping = aes(
x = !!dplyr::sym("t1"),
Expand Down
4 changes: 2 additions & 2 deletions R/seurat_wrapper.R
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ write_meta <- function(object, ...) {
write_meta.Seurat <- function(object,
meta,
...) {
if ("Seurat" %in% loadedNamespaces()) {
if ("SeuratObject" %in% loadedNamespaces()) {
object_new <- object
object_new@meta.data <- meta
return(object_new)
} else {
message("Seurat not loaded")
message("SeuratObject not loaded")
}
}

Expand Down
3 changes: 2 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@ clustify_nudge.Seurat <- function(input,
rename_prefix = rename_prefix
)

if ("Seurat" %in% loadedNamespaces()) {
if ("SeuratObject" %in% loadedNamespaces()) {
input <- write_meta(input, df_temp_full)
return(input)
} else {
Expand Down Expand Up @@ -1359,6 +1359,7 @@ feature_select_PCA <- function(mat = NULL,
#'
#' gene.lists <- gmt_to_list(path = gmt_file)
#' length(gene.lists)
#' @importFrom utils read.csv
#' @export
gmt_to_list <- function(path,
cutoff = 0,
Expand Down
3 changes: 1 addition & 2 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ BiocManager::install("clustifyr")
Install the development version with:

``` r
# install.packages("remotes")
remotes::install_github("rnabioco/clustifyr")
BiocManager::install("rnabioco/clustifyr")
```

## Example usage
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
coverage](https://codecov.io/gh/rnabioco/clustifyr/branch/devel/graph/badge.svg)](https://app.codecov.io/gh/rnabioco/clustifyr?branch=devel)
[![platforms](https://bioconductor.org/shields/availability/release/clustifyr.svg)](https://bioconductor.org/packages/release/bioc/html/clustifyr.html)
[![bioc](https://bioconductor.org/shields/years-in-bioc/clustifyr.svg)](https://bioconductor.org/packages/release/bioc/html/clustifyr.html)
[![\#downloads](https://img.shields.io/badge/%23%20downloads-7329-brightgreen)](https://bioconductor.org/packages/stats/bioc/clustifyr/clustifyr_stats.tab)
[![\#downloads](https://img.shields.io/badge/%23%20downloads-8045-brightgreen)](https://bioconductor.org/packages/stats/bioc/clustifyr/clustifyr_stats.tab)
<!-- badges: end -->

clustifyr classifies cells and clusters in single-cell RNA sequencing
Expand All @@ -29,8 +29,7 @@ BiocManager::install("clustifyr")
Install the development version with:

``` r
# install.packages("remotes")
remotes::install_github("rnabioco/clustifyr")
BiocManager::install("rnabioco/clustifyr")
```

## Example usage
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test_cor.R
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ test_that("clustify reinserts seurat3 metadata correctly", {
seurat_out = TRUE,
dr = "tsne"
)
if ("Seurat" %in% loadedNamespaces()) {
if ("SeuratObject" %in% loadedNamespaces()) {
expect_true(class(res) %in% c("Seurat"))
} else {
expect_true(is.matrix(res))
Expand Down Expand Up @@ -392,7 +392,7 @@ test_that("correct error message is displayed for nonexistent cluster_col", {
})

test_that("input Seurat metadata columns are not changed (type, r, rn, etc). #259", {
skip_if_not_installed("Seurat")
skip_if_not_installed("SeuratObject")
tmp <- s_small3
tmp@meta.data$type <- 0L
tmp@meta.data$rn <- 0L
Expand Down
28 changes: 19 additions & 9 deletions tests/testthat/test_gsea.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
context("run_gsea")

# use capture.output to quiet progress bar from fgsea
shush <- function(...) {
capture.output(..., file = nullfile())
}
test_that("output is correctly formatted", {
data("pbmc_vargenes")
res <- run_gsea(

shush(res <- run_gsea(
pbmc_matrix_small,
query_genes = pbmc_vargenes[1:100],
n_perm = 10,
cluster_ids = pbmc_meta$classified,
no_warnings = TRUE
)
))

expect_equal(nrow(res), length(unique(pbmc_meta$classified)))
expect_true(all(res$pval >= 0 & res$pval <= 1))
Expand All @@ -30,26 +35,30 @@ test_that("run_gsea checks for matching number of clusters", {
test_that("run_gsea warns slow runs", {
data("pbmc_vargenes")

expect_warning(res <- run_gsea(pbmc_matrix_small[, 1:3],
expect_warning(
shush(res <- run_gsea(pbmc_matrix_small[, 1:3],
query_genes = pbmc_vargenes[1:2],
n_perm = 10001,
per_cell = TRUE,
cluster_ids = pbmc_meta$classified,
no_warnings = TRUE
))
)
)
)
})

test_that("run_gsea warning suppression", {
data("pbmc_vargenes")
expect_warning(
res <- run_gsea(
shush(res <- run_gsea(
pbmc_matrix_small[, 1:3],
query_genes = pbmc_vargenes[1:2],
n_perm = 1,
per_cell = TRUE,
cluster_ids = pbmc_meta$classified,
no_warnings = FALSE
)
)
)
})

Expand All @@ -62,7 +71,7 @@ test_that("calculate_pathway_gsea gives appropriate output", {
pbmc_meta,
cluster_col = "classified"
)
res <- calculate_pathway_gsea(pbmc_avg, gl, scale = TRUE)
shush(res <- calculate_pathway_gsea(pbmc_avg, gl, scale = TRUE))

expect_equal(nrow(res), length(unique(pbmc_meta$classified)))
})
Expand All @@ -76,7 +85,7 @@ test_that("plot_pathway_gsea gives appropriate output", {
pbmc_meta,
cluster_col = "classified"
)
g <- plot_pathway_gsea(pbmc_avg, gl, 5)
shush(g <- plot_pathway_gsea(pbmc_avg, gl, 5))
expect_equal(length(g), 2)
})

Expand All @@ -89,7 +98,8 @@ test_that("plot_pathway_gsea gives output depending on returning option", {
pbmc_meta,
cluster_col = "classified"
)
g <- plot_pathway_gsea(pbmc_avg, gl, 5, returning = "plot")
g2 <- plot_pathway_gsea(pbmc_avg, gl, 5, returning = "res")
shush(g <- plot_pathway_gsea(pbmc_avg, gl, 5, returning = "plot"))
shush(g2 <- plot_pathway_gsea(pbmc_avg, gl, 5, returning = "res"))

expect_true(is(g, "Heatmap") & is.data.frame(g2))
})
Loading

0 comments on commit e59930a

Please sign in to comment.