diff --git a/NAMESPACE b/NAMESPACE index 6012f97..26adeae 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) diff --git a/R/methods.R b/R/methods.R index 843424c..c4ffc04 100755 --- a/R/methods.R +++ b/R/methods.R @@ -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", ...) { @@ -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 %>% diff --git a/README.Rmd b/README.Rmd index 1150d08..eb9e075 100755 --- a/README.Rmd +++ b/README.Rmd @@ -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`. diff --git a/README.md b/README.md index 6151927..bbf6057 100755 --- a/README.md +++ b/README.md @@ -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 ## ## 1 ATGC… SeuratPro… 70 47 0 A g2 @@ -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 @@ -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 ## ## 1 ATGC… sampl… SeuratPro… 70 47 0 A @@ -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 ## ## 1 ATGC… SeuratPro… 70 47 0 A g2 @@ -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 ## ## 1 ATGCC… 2 SeuratPro… 70 47 0 A @@ -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 ## ## 1 ATGCCAGAACGA… CD4+ T-cells SeuratPro… 70 47 0 diff --git a/vignettes/introduction.Rmd b/vignettes/introduction.Rmd index 680b2cb..24e05ba 100755 --- a/vignettes/introduction.Rmd +++ b/vignettes/introduction.Rmd @@ -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,