Skip to content
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
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,11 @@ importFrom(rlang,quo_name)
importFrom(rlang,quo_squash)
importFrom(stats,setNames)
importFrom(stringr,regex)
importFrom(stringr,str_c)
importFrom(stringr,str_detect)
importFrom(stringr,str_remove)
importFrom(stringr,str_replace_all)
importFrom(stringr,str_subset)
importFrom(tibble,as_tibble)
importFrom(tibble,enframe)
importFrom(tibble,glimpse)
Expand Down
46 changes: 36 additions & 10 deletions R/methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ setClass("tidySingleCellExperiment", contains="SingleCellExperiment")
#' @importFrom dplyr contains
#' @importFrom dplyr everything
#' @importFrom ttservice join_features
#' @importFrom stringr str_c
#' @importFrom stringr str_subset
#' @export
setMethod("join_features", "SingleCellExperiment", function(.data,
features=NULL, all=FALSE, exclude_zeros=FALSE, shape="long", ...) {
Expand All @@ -42,16 +44,40 @@ setMethod("join_features", "SingleCellExperiment", function(.data,

# Shape is long
if (shape == "long") {
.data %>%
left_join(
by=c_(.data)$name,
get_abundance_sc_long(
.data=.data,
features=features,
all=all,
exclude_zeros=exclude_zeros)) %>%
select(!!c_(.data)$symbol, .feature,
contains(".abundance"), everything())

# Suppress generic data frame creation message produced by left_join
suppressMessages({
.data <-
.data %>%
left_join(
by=c_(.data)$name,
get_abundance_sc_long(
.data=.data,
features=features,
all=all,
exclude_zeros=exclude_zeros)) %>%
select(!!c_(.data)$symbol, .feature,
contains(".abundance"), everything())
})

# Provide data frame creation and abundance column message
if (any(class(.data) == "tbl_df")) {

abundance_columns <-
.data %>%
colnames() %>%
stringr::str_subset('.abundance_')

message(stringr::str_c("tidySingleCellExperiment says: join_features produces",
" duplicate cell names to accomadate the long data format. For this reason, a data",
" frame is returned for independent data analysis. Assay feature abundance is",
" appended as ",
stringr::str_flatten_comma(abundance_columns, last = " and "), "."
))
}

.data

# Shape if wide
} else {
.data %>%
Expand Down
13 changes: 13 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,19 @@ pbmc_small_tidy
assay(pbmc_small_tidy, "counts")[1:5, 1:5]
```

The `SingleCellExperiment` object's tibble visualisation can be turned off, or back on at any time.

```{r}
# Turn off the tibble visualisation
options("restore_SingleCellExperiment_show" = TRUE)
pbmc_small_tidy
```

```{r}
# Turn on the tibble visualisation
options("restore_SingleCellExperiment_show" = FALSE)
```

# Annotation polishing

We may have a column that contains the directory each run was taken from, such as the "file" column in `pbmc_small_tidy`.
Expand Down
33 changes: 28 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pbmc_small_tidy
```

## # A SingleCellExperiment-tibble abstraction: 80 × 17
## # Features=230 | Cells=80 | Assays=counts, logcounts
## # [90mFeatures=230 | Cells=80 | Assays=counts, logcounts[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 @@ -135,6 +135,29 @@ assay(pbmc_small_tidy, "counts")[1:5, 1:5]
## CD79A .
## HLA-DRA 1
## TCL1A .

The `SingleCellExperiment` object's tibble visualisation can be turned off, or back on at any time.

```{r}
# Turn off the tibble visualisation
options("restore_SingleCellExperiment_show" = TRUE)
pbmc_small_tidy
```

## class: SingleCellExperiment
## dim: 230 80
## metadata(0):
## assays(2): counts logcounts
## rownames(230): MS4A1 CD79B ... SPON2 S100B
## rowData names(5): vst.mean vst.variance vst.variance.expected
## vst.variance.standardized vst.variable
## colnames(80): ATGCCAGAACGACT CATGGCCTGTGCAT ... GGAACACTTCAGAC CTTGATTGATCTTC
## colData names(9): orig.ident nCount_RNA ... file ident

```{r}
# Turn on the tibble visualisation
options("restore_SingleCellExperiment_show" = FALSE)
```

# Annotation polishing

Expand Down Expand Up @@ -167,7 +190,7 @@ pbmc_small_polished |>
```

## # A SingleCellExperiment-tibble abstraction: 80 × 18
## # Features=230 | Cells=80 | Assays=counts, logcounts
## # [90mFeatures=230 | Cells=80 | Assays=counts, logcounts[0m
## .cell sample orig.ident nCount_RNA nFeature_RNA RNA_snn_res.0.8 letter.idents
## <chr> <chr> <fct> <dbl> <int> <fct> <fct>
## 1 ATGC… sampl… SeuratPro… 70 47 0 A
Expand Down Expand Up @@ -294,7 +317,7 @@ pbmc_small_pca
```

## # A SingleCellExperiment-tibble abstraction: 80 × 18
## # Features=230 | Cells=80 | Assays=counts, logcounts
## # [90mFeatures=230 | Cells=80 | Assays=counts, logcounts[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 @@ -356,7 +379,7 @@ pbmc_small_cluster |> select(label, everything())
```

## # A SingleCellExperiment-tibble abstraction: 80 × 19
## # Features=230 | Cells=80 | Assays=counts, logcounts
## # [90mFeatures=230 | Cells=80 | Assays=counts, logcounts[0m
## .cell label orig.ident nCount_RNA nFeature_RNA RNA_snn_res.0.8 letter.idents
## <chr> <fct> <fct> <dbl> <int> <fct> <fct>
## 1 ATGCC… 2 SeuratPro… 70 47 0 A
Expand Down Expand Up @@ -509,7 +532,7 @@ pbmc_small_cell_type |>
## your workflow to reflect the new vocabulary (.cell)

## # A SingleCellExperiment-tibble abstraction: 80 × 23
## # Features=230 | Cells=80 | Assays=counts, logcounts
## # [90mFeatures=230 | Cells=80 | Assays=counts, logcounts[0m
## cell first.labels orig.ident nCount_RNA nFeature_RNA RNA_snn_res.0.8
## <chr> <chr> <fct> <dbl> <int> <fct>
## 1 ATGCCAGAACGA… CD4+ T-cells SeuratPro… 70 47 0
Expand Down
12 changes: 12 additions & 0 deletions vignettes/introduction.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ pbmc_small_tidy
counts(pbmc_small_tidy)[1:5, 1:4]
```

The `SingleCellExperiment` object's tibble visualisation can be turned off, or back on at any time.

```{r}
# Turn off the tibble visualisation
options("restore_SingleCellExperiment_show" = TRUE)
pbmc_small_tidy
```
```{r}
# Turn on the tibble visualisation
options("restore_SingleCellExperiment_show" = FALSE)
```

# Annotation polishing

We may have a column that contains the directory each run was taken from,
Expand Down