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

Hotfix seurat5 one cell bug #85

Merged
merged 3 commits into from
Jul 18, 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
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
Loading