Skip to content

Commit

Permalink
pull
Browse files Browse the repository at this point in the history
Merge branch 'master' of github.com:stemangiola/tidyseurat

Conflicts:
	tests/testthat/test-dplyr.R
  • Loading branch information
stemangiola committed Nov 23, 2023
2 parents c303d9b + 9f07977 commit 3460cff
Show file tree
Hide file tree
Showing 26 changed files with 241 additions and 240 deletions.
103 changes: 0 additions & 103 deletions .github/workflows/R-CMD-check.yaml

This file was deleted.

57 changes: 57 additions & 0 deletions .github/workflows/rworkflows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: rworkflows
'on':
push:
branches:
- master
- main
- devel
- RELEASE_**
pull_request:
branches:
- master
- main
- devel
- RELEASE_**
jobs:
rworkflows:
permissions: write-all
runs-on: ${{ matrix.config.os }}
name: ${{ matrix.config.os }} (${{ matrix.config.r }})
container: ${{ matrix.config.cont }}
strategy:
fail-fast: ${{ false }}
matrix:
config:
- os: ubuntu-latest
bioc: devel
r: auto
cont: ghcr.io/bioconductor/bioconductor_docker:devel
rspm: ~
- os: macOS-latest
bioc: release
r: auto
cont: ~
rspm: ~
- os: windows-latest
bioc: release
r: auto
cont: ~
rspm: ~
steps:
- uses: neurogenomics/rworkflows@master
with:
run_bioccheck: ${{ false }}
run_rcmdcheck: ${{ true }}
as_cran: ${{ true }}
run_vignettes: ${{ true }}
has_testthat: ${{ true }}
run_covr: ${{ true }}
run_pkgdown: ${{ true }}
has_runit: ${{ false }}
has_latex: ${{ false }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run_docker: ${{ false }}
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
runner_os: ${{ runner.os }}
cache_version: cache-v1
docker_registry: ghcr.io
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: tidyseurat
Title: Brings Seurat to the Tidyverse
Version: 0.7.2
Version: 0.7.8
Authors@R: c(person("Stefano", "Mangiola", email = "[email protected]",
role = c("aut", "cre")),
person("Maria", "Doyle", email = "[email protected]",
Expand All @@ -15,7 +15,7 @@ Depends:
ttservice (>= 0.3.8),
SeuratObject
Imports:
Seurat,
Seurat (>= 4.3.0),
tibble,
dplyr,
magrittr,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ exportMethods(aggregate_cells)
exportMethods(join_features)
importFrom(Matrix,rowSums)
importFrom(Seurat,Assays)
importFrom(Seurat,DietSeurat)
importFrom(Seurat,GetAssayData)
importFrom(Seurat,SplitObject)
importFrom(Seurat,VariableFeatures)
Expand Down
32 changes: 23 additions & 9 deletions R/dplyr_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,23 @@
#' @importFrom dplyr arrange
#' @export
arrange.Seurat <- function(.data, ..., .by_group=FALSE) {
.data@meta.data <-
.data %>%
as_tibble() %>%
dplyr::arrange( ..., .by_group=.by_group ) %>%
as_meta_data(.data)

.data

# DEPRECATE
deprecate_warn(
when="0.7.5",
what="arrange()",
details="tidyseurat says: arrange() is temporarly deprected as it is not clear that Seurat allows reordering of cells."
)

# .cell_ordered <-
# .data %>%
# as_tibble() %>%
# dplyr::arrange( ..., .by_group=.by_group ) %>%
# pull(!!c_(.data)$symbol)
#
# .data[,.cell_ordered]

.data
}

#' @name bind_rows
Expand Down Expand Up @@ -48,7 +58,7 @@ bind_rows.Seurat <- function(..., .id=NULL, add.cell.ids=NULL)
# slot(object=object[[assay]], name="SCTModel.list")
# So I have to delete any sample of size 1 if I have calculated SCT
# if()
# GetAssayData(object, slot='SCTModel.list', assay="SCT") %>%
# GetAssayData(object, layer='SCTModel.list', assay="SCT") %>%
# map(~ [email protected] %>% nrow)

# Check if cell with same name
Expand Down Expand Up @@ -269,6 +279,7 @@ mutate.Seurat <- function(.data, ...) {
#' data(pbmc_small)
#' pbmc_small |> rename(s_score=nFeature_RNA)
#'
#' @importFrom Seurat DietSeurat
#' @importFrom tidyselect eval_select
#' @importFrom dplyr rename
#' @export
Expand All @@ -281,7 +292,10 @@ rename.Seurat <- function(.data, ...)
get_special_columns(.data))

# Small df to be more efficient
df <- .data[1, 1] |> as_tibble()
df <-
DietSeurat(.data, features = rownames(.data)[1])[,1] |>
suppressWarnings() |>
as_tibble()

# What columns we are going to create
cols_from <- tidyselect::eval_select(expr(c(...)), df) |> names()
Expand Down
76 changes: 39 additions & 37 deletions R/methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,38 +73,39 @@ tidy.Seurat <- function(object){
setMethod("join_features", "Seurat", function(.data,
features=NULL, all=FALSE, exclude_zeros=FALSE, shape="long",
assay=NULL, slot="data", ...) {
.data %>%
when(
# Shape is long
shape == "long" ~ (.) %>%
left_join(
get_abundance_sc_long(
.data=.data,
features=features,
all=all,
exclude_zeros=exclude_zeros,
assay=assay,
slot=slot,
...
),
by=c_(.data)$name
) %>%
select(!!c_(.data)$symbol, .feature,
contains(".abundance"), everything()),
# Shape if wide
~ (.) %>%
left_join(
get_abundance_sc_wide(
.data=.data,
features=features,
all=all,
assay=assay,
slot=slot,
...
),
by=c_(.data)$name
)
)

.feature = NULL

if(shape == "long")
.data |>
left_join(
get_abundance_sc_long(
.data=.data,
features=features,
all=all,
exclude_zeros=exclude_zeros,
assay=assay,
slot=slot,
...
),
by=c_(.data)$name
) %>%
select(!!c_(.data)$symbol, .feature,
contains(".abundance"), everything())
else
.data |>
left_join(
get_abundance_sc_wide(
.data=.data,
features=features,
all=all,
assay=assay,
slot=slot,
...
),
by=c_(.data)$name
)

})


Expand All @@ -126,6 +127,7 @@ setMethod("join_features", "Seurat", function(.data,
#' @importFrom Matrix rowSums
#' @importFrom ttservice aggregate_cells
#' @importFrom SeuratObject DefaultAssay
#' @importFrom Seurat DietSeurat
#' @importFrom purrr map_int
#' @export
setMethod("aggregate_cells", "Seurat", function(.data,
Expand All @@ -140,7 +142,7 @@ setMethod("aggregate_cells", "Seurat", function(.data,
# Subset only wanted assays
if(!is.null(assays)){
DefaultAssay(.data) <- assays[1]
.data@assays <- .data@assays[assays]
.data = .data |> DietSeurat(assays = assays)
}

.data %>%
Expand All @@ -151,17 +153,17 @@ setMethod("aggregate_cells", "Seurat", function(.data,
# Loop over assays
map2(.x@assays, names(.x@assays),
# Get counts
~ GetAssayData(.x, slot=slot) %>%
~ GetAssayData(.x, layer=slot) %>%
aggregation_function(na.rm=T) %>%
tibble::enframe(
name=".feature",
value=sprintf("%s", .y)
) %>%
mutate(.feature=as.character(.feature))
) %>%
Reduce(function(...) full_join(..., by=c(".feature")), .)
)
) %>%
Reduce(function(...) full_join(..., by=c(".feature")), .),
.progress = TRUE
)) %>%
left_join(
.data %>%
as_tibble() %>%
Expand Down
3 changes: 2 additions & 1 deletion R/plotly_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
#' @return `plotly`
#'
#' @examples
#' # TODO
#' data(pbmc_small)
#' plot_ly(pbmc_small)
#'
#' @importFrom plotly plot_ly
#' @export
Expand Down
7 changes: 5 additions & 2 deletions R/tidyr_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ unnest_seurat <- function(data, cols, ...,
#' @importFrom magrittr equals
#' @importFrom rlang enquos
#' @importFrom Seurat SplitObject
#' @importFrom Seurat DietSeurat
#' @importFrom rlang :=
#' @export
nest.Seurat <- function (.data, ..., .names_sep=NULL)
Expand All @@ -106,11 +107,13 @@ nest.Seurat <- function (.data, ..., .names_sep=NULL)
.data <- ping_old_special_column_into_metadata(.data)
}

my_data__ <- .data
my_data__ <- .data

# This is for getting the column names
dummy_nested <-
my_data__[1,] |>
my_data__ |>
DietSeurat(features = rownames(my_data__)[1:2], assays = DefaultAssay(my_data__)) |>
suppressWarnings() |>
to_tib() %>%
tidyr::nest(...)

Expand Down
Loading

0 comments on commit 3460cff

Please sign in to comment.