Skip to content

Commit

Permalink
Merge pull request #85 from stemangiola/hotfix-Seurat5-one-cell-bug
Browse files Browse the repository at this point in the history
Hotfix seurat5 one cell bug
  • Loading branch information
stemangiola authored Jul 18, 2024
2 parents 74a7cca + 5780b87 commit 82b6aec
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
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.8.1
Version: 0.8.2
Authors@R: c(person("Stefano", "Mangiola", email = "[email protected]",
role = c("aut", "cre")),
person("Maria", "Doyle", email = "[email protected]",
Expand Down Expand Up @@ -49,6 +49,6 @@ Biarch: true
biocViews: AssayDomain, Infrastructure, RNASeq, DifferentialExpression, GeneExpression, Normalization, Clustering, QualityControl, Sequencing, Transcription, Transcriptomics
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
URL: https://github.com/stemangiola/tidyseurat, https://stemangiola.github.io/tidyseurat/
BugReports: https://github.com/stemangiola/tidyseurat/issues
4 changes: 2 additions & 2 deletions R/methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ setMethod("join_features", "Seurat", function(.data,

})


#' @name aggregate_cells
#' @rdname aggregate_cells
#' @inherit ttservice::aggregate_cells
Expand All @@ -128,6 +127,7 @@ setMethod("join_features", "Seurat", function(.data,
#' @importFrom ttservice aggregate_cells
#' @importFrom SeuratObject DefaultAssay
#' @importFrom Seurat DietSeurat
#' @importFrom Seurat GetAssayData
#' @importFrom purrr map_int
#' @export
setMethod("aggregate_cells", "Seurat", function(.data,
Expand All @@ -153,7 +153,7 @@ setMethod("aggregate_cells", "Seurat", function(.data,
# Loop over assays
map2(.x@assays, names(.x@assays),
# Get counts
~ GetAssayData(.x, layer=slot) %>%
~ GetAssayData_robust(.x, layer=slot) %>%
aggregation_function(na.rm=T) %>%
tibble::enframe(
name=".feature",
Expand Down
18 changes: 18 additions & 0 deletions R/utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,26 @@ subset_tidyseurat <- function(.data, .column) {
stop("tidyseurat says: some of the .column specified",
" do not exist in the input data frame.")


.data %>%
# Selecting the right columns
select(!!.column, get_specific_annotation_columns(.data, !!.column)) %>%
distinct()
}

#' @importFrom Seurat GetAssayData
GetAssayData_robust = function(seurat_assay, layer = NULL){

if(
seurat_assay |> is("Assay5") &
seurat_assay |> ncol() == 1
){
m = seurat_assay@layers[[layer]] |> as.matrix()
rownames(m) = rownames(seurat_assay)
colnames(m) = colnames(seurat_assay)
m
}

else
GetAssayData(seurat_assay, layer=layer)
}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pbmc_small
```

## # A Seurat-tibble abstraction: 80 × 15
## # Features=230 | Cells=80 | Active assay=RNA | Assays=RNA
## # [90mFeatures=230 | Cells=80 | Active assay=RNA | Assays=RNA[0m
## .cell orig.ident nCount_RNA nFeature_RNA RNA_snn_res.0.8 letter.idents groups
## <chr> <fct> <dbl> <int> <fct> <fct> <chr>
## 1 ATGC… SeuratPro… 70 47 0 A g2
Expand Down Expand Up @@ -217,7 +217,7 @@ pbmc_small_pca
```

## # A Seurat-tibble abstraction: 80 × 17
## # Features=220 | Cells=80 | Active assay=SCT | Assays=RNA, SCT
## # [90mFeatures=220 | Cells=80 | Active assay=SCT | Assays=RNA, SCT[0m
## .cell orig.ident nCount_RNA nFeature_RNA RNA_snn_res.0.8 letter.idents groups
## <chr> <fct> <dbl> <int> <fct> <fct> <chr>
## 1 ATGC… SeuratPro… 70 47 0 A g2
Expand Down Expand Up @@ -262,7 +262,7 @@ pbmc_small_cluster
```

## # A Seurat-tibble abstraction: 80 × 19
## # Features=220 | Cells=80 | Active assay=SCT | Assays=RNA, SCT
## # [90mFeatures=220 | Cells=80 | Active assay=SCT | Assays=RNA, SCT[0m
## .cell orig.ident nCount_RNA nFeature_RNA RNA_snn_res.0.8 letter.idents groups
## <chr> <fct> <dbl> <int> <fct> <fct> <chr>
## 1 ATGC… SeuratPro… 70 47 0 A g2
Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/test-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ test_that("aggregate_cells() returns expected values", {
pull(.cell)] |>
LayerData() |>
sum())

# Aggregate with tidyselect
pbmc_small |>
aggregate_cells(c(any_of("groups"), letter.idents), assays = "RNA") |>
expect_no_error()
})

test_that("get_abundance_sc_wide", {
Expand Down

0 comments on commit 82b6aec

Please sign in to comment.