Skip to content
Open
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
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: tidySingleCellExperiment
Title: Brings SingleCellExperiment to the Tidyverse
Version: 1.19.1
Version: 1.19.2
Authors@R: c(person("Stefano", "Mangiola",
comment=c(ORCID="0000-0001-7474-836X"),
email="mangiolastefano@gmail.com",
Expand Down Expand Up @@ -60,7 +60,8 @@ Suggests:
celldex,
dittoSeq,
plotly,
rbibutils
rbibutils,
prettydoc
VignetteBuilder:
knitr
RdMacros:
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

S3method(add_count,SingleCellExperiment)
S3method(anti_join,SingleCellExperiment)
S3method(append_samples,SingleCellExperiment)
S3method(arrange,SingleCellExperiment)
S3method(as_tibble,SingleCellExperiment)
S3method(bind_cols,SingleCellExperiment)
Expand Down Expand Up @@ -158,6 +159,7 @@ importFrom(tidyr,unnest)
importFrom(tidyselect,all_of)
importFrom(tidyselect,eval_select)
importFrom(ttservice,aggregate_cells)
importFrom(ttservice,append_samples)
importFrom(ttservice,bind_cols)
importFrom(ttservice,bind_rows)
importFrom(ttservice,join_features)
Expand Down
55 changes: 47 additions & 8 deletions R/dplyr_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,7 @@ arrange.SingleCellExperiment <- function(.data, ..., .by_group=FALSE) {
#' @name bind_rows
#' @rdname bind_rows
#' @inherit ttservice::bind_rows
#'
#' @examples
#' data(pbmc_small)
#' tt <- pbmc_small
#' bind_rows(tt, tt)
#'
#' tt_bind <- tt |> select(nCount_RNA, nFeature_RNA)
#' tt |> bind_cols(tt_bind)
#' @noRd
#'
#' @references
#' Hutchison, W.J., Keyes, T.J., The tidyomics Consortium. et al. The tidyomics ecosystem: enhancing omic data analyses. Nat Methods 21, 1166–1170 (2024). https://doi.org/10.1038/s41592-024-02299-2
Expand All @@ -48,6 +41,13 @@ arrange.SingleCellExperiment <- function(.data, ..., .by_group=FALSE) {
#' @importFrom SingleCellExperiment cbind
#' @export
bind_rows.SingleCellExperiment <- function(..., .id=NULL, add.cell.ids=NULL) {
lifecycle::deprecate_warn(
when = "1.19.2",
what = "bind_rows()",
with = "append_samples()",
details = "bind_rows is not a generic method in dplyr and may cause conflicts. Use append_samples."
)

tts <- flatten_if(dots_values(...), is_spliced)

new_obj <- SingleCellExperiment::cbind(tts[[1]], tts[[2]])
Expand All @@ -62,6 +62,45 @@ bind_rows.SingleCellExperiment <- function(..., .id=NULL, add.cell.ids=NULL) {
new_obj
}

#' @name append_samples
#' @rdname append_samples
#' @title Append samples from multiple SingleCellExperiment objects
#'
#' @description
#' Append samples from multiple SingleCellExperiment objects by column-binding them.
#' This function is equivalent to `cbind` but provides a tidyverse-like interface.
#'
#' @param x First SingleCellExperiment object to combine
#' @param ... Additional SingleCellExperiment objects to combine by samples
#' @param .id Object identifier (currently not used)
#'
#' @return A combined SingleCellExperiment object
#'
#' @examples
#' data(pbmc_small)
#' append_samples(pbmc_small, pbmc_small)
#'
#' @importFrom ttservice append_samples
#' @importFrom rlang flatten_if
#' @importFrom rlang is_spliced
#' @importFrom SingleCellExperiment cbind
#' @export
append_samples.SingleCellExperiment <- function(x, ..., .id = NULL) {
# Combine all arguments into a list
tts <- flatten_if(list(x, ...), is_spliced)
new_obj <- do.call(cbind, tts)

# If duplicated cell names
if (any(duplicated(colnames(new_obj)))) {
warning("tidySingleCellExperiment says:",
" you have duplicated cell names, they will be made unique.")
unique_colnames <- make.unique(colnames(new_obj), sep = "_")
colnames(new_obj) <- unique_colnames
}

new_obj
}

#' @importFrom rlang flatten_if
#' @importFrom rlang is_spliced
#' @importFrom rlang dots_values
Expand Down
2 changes: 1 addition & 1 deletion R/methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ setClass("tidySingleCellExperiment", contains="SingleCellExperiment")
#' @importFrom stringr str_subset
#' @export
setMethod("join_features", "SingleCellExperiment", function(.data,
features=NULL, all=FALSE, exclude_zeros=FALSE, shape="long", ...) {
features=NULL, all=FALSE, exclude_zeros=FALSE, shape="wide", ...) {
# CRAN Note
.cell <- NULL
.feature <- NULL
Expand Down
6 changes: 3 additions & 3 deletions R/methods_DEPRECATED.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ join_transcripts <-
transcripts=NULL,
all=FALSE,
exclude_zeros=FALSE,
shape="long", ...)
shape="wide", ...)
{
UseMethod("join_transcripts", .data)
}
Expand All @@ -45,7 +45,7 @@ join_transcripts.default <-
transcripts=NULL,
all=FALSE,
exclude_zeros=FALSE,
shape="long", ...)
shape="wide", ...)
{
print("tidySingleCellExperiment says:",
" This function cannot be applied to this object")
Expand All @@ -56,7 +56,7 @@ join_transcripts.Seurat <-
transcripts=NULL,
all=FALSE,
exclude_zeros=FALSE,
shape="long", ...)
shape="wide", ...)
{
deprecate_warn(
"1.1.2", "join_transcripts()",
Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ pbmc_small_nested_interactions <-
cell_signaling(genes=rownames(data), cluster=cluster) |>
inter_network(data=data, signal=_, genes=rownames(data), cluster=cluster) %$%
`individual-networks` |>
map_dfr(~ bind_rows(as_tibble(.x)))
map_dfr(~ append_samples(as_tibble(.x)))
}))

pbmc_small_nested_interactions |>
Expand Down
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,6 @@ pbmc_small_pca <-
## TRUE, : You're computing too large a percentage of total singular values, use a
## standard svd instead.

## Warning in (function (A, nv = 5, nu = nv, maxit = 1000, work = nv + 7, reorth =
## TRUE, : did not converge--results might be invalid!; try increasing work or
## maxit

``` r
pbmc_small_pca
```
Expand Down Expand Up @@ -742,7 +738,7 @@ pbmc_small_nested_interactions <-
cell_signaling(genes=rownames(data), cluster=cluster) |>
inter_network(data=data, signal=_, genes=rownames(data), cluster=cluster) %$%
`individual-networks` |>
map_dfr(~ bind_rows(as_tibble(.x)))
map_dfr(~ append_samples(as_tibble(.x)))
}))

pbmc_small_nested_interactions |>
Expand Down
15 changes: 15 additions & 0 deletions inst/NEWS.rd
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
\name{NEWS}
\title{News for Package \pkg{tidySingleCellExperiment}}

\section{Changes in version 1.19.2, Bioconductor 3.22 Release}{
\itemize{
\item Soft deprecated \code{bind_rows()} in favor of \code{append_samples()} from ttservice.
\item Added \code{append_samples()} method for SingleCellExperiment objects.
\item \code{bind_rows()} is not a generic method in dplyr and may cause conflicts.
\item Users are encouraged to use \code{append_samples()} instead.
}}

\section{Changes in version 1.4.0, Bioconductor 3.14 Release}{
\itemize{
\item Improved sample_n, and sample_frac functions.
Expand All @@ -15,3 +23,10 @@
\item Use .cell for cell column name to avoid errors when cell column is defined by the user
}}

\section{Changes in version 1.19.2, Bioconductor 3.22 Release}{
\itemize{
\item \strong{BREAKING CHANGE}: Changed default shape parameter in \code{join_features()} from "long" to "wide".
This means that \code{join_features()} now returns a SingleCellExperiment object by default instead of a tibble.
To get the old behavior, explicitly specify \code{shape="long"}.
}}

28 changes: 28 additions & 0 deletions man/append_samples.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 0 additions & 72 deletions man/bind_rows.Rd

This file was deleted.

2 changes: 1 addition & 1 deletion man/join_features.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/join_transcripts.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/testthat/test-dplyr_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ df$factor <- sample(
# expect_identical(fd, df)
# })

test_that("bind_rows()", {
test_that("append_samples()", {
# warn about duplicated cells names
expect_warning(fd <- bind_rows(df, df))
expect_warning(fd <- append_samples(df, df))
# cell names should be unique after binding
expect_true(!any(duplicated(pull(fd, .cell))))
})
Expand Down
14 changes: 7 additions & 7 deletions tests/testthat/test-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ test_that("show()", {

test_that("join_features()", {
gs <- sample(rownames(df), 3)
# wide (default)
fd <- join_features(df, gs, assay="counts")
expect_s4_class(fd, "SingleCellExperiment")
expect_null(fd$.feature)
expect_identical(
unname(t(as.matrix(as_tibble(fd)[, make.names(gs)]))),
as.matrix(unname(counts(df)[gs, ])))
# long
fd <- join_features(df, gs, shape="long")
expect_s3_class(fd, "tbl_df")
Expand All @@ -20,13 +27,6 @@ test_that("join_features()", {
expect_identical(
matrix(fd$.abundance_counts, nrow=length(gs)),
as.matrix(unname(counts(df)[fd$.feature[seq_along(gs)], ])))
# wide
fd <- join_features(df, gs, shape="wide", assay="counts")
expect_s4_class(fd, "SingleCellExperiment")
expect_null(fd$.feature)
expect_identical(
unname(t(as.matrix(as_tibble(fd)[, make.names(gs)]))),
as.matrix(unname(counts(df)[gs, ])))
})

test_that("as_tibble()", {
Expand Down
Loading
Loading