diff --git a/CRAN-SUBMISSION b/CRAN-SUBMISSION index f5ee35d7b9..10bc73b83a 100644 --- a/CRAN-SUBMISSION +++ b/CRAN-SUBMISSION @@ -1,3 +1,3 @@ -Version: 2.0.0 -Date: 2023-11-14 01:30:08 UTC -SHA: 8987da5397b33ac79a5a3a08da9f7eccfac71a03 +Version: 2.0.1 +Date: 2023-11-17 15:28:31 UTC +SHA: 2bf5f1166ee097878adef4e10d1a3923db44557b diff --git a/DESCRIPTION b/DESCRIPTION index df33b92ab5..a9f6ac5c5c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,9 +1,9 @@ Package: scCustomize Type: Package Title: Custom Visualizations & Functions for Streamlined Analyses of Single Cell Sequencing -Description: Collection of functions created and/or curated to aid in the visualization and analysis of single-cell data using 'R'. 'scCustomize' aims to provide 1) Customized visualizations for aid in ease of use and to create more aesthetic and functional visuals. 2) Improve speed/reproducibility of common tasks/pieces of code in scRNA-seq analysis with a single or group of functions. For citation please use: Marsh SE (2021) "Custom Visualizations & Functions for Streamlined Analyses of Single Cell Sequencing" . -Version: 2.0.0 -Date: 2023-11-13 +Description: Collection of functions created and/or curated to aid in the visualization and analysis of single-cell data using 'R'. 'scCustomize' aims to provide 1) Customized visualizations for aid in ease of use and to create more aesthetic and functional visuals. 2) Improve speed/reproducibility of common tasks/pieces of code in scRNA-seq analysis with a single or group of functions. For citation please use: Marsh SE (2021) "Custom Visualizations & Functions for Streamlined Analyses of Single Cell Sequencing" RRID:SCR_024675. +Version: 2.0.1 +Date: 2023-11-17 Authors@R: c( person(given = "Samuel", family = "Marsh", email = "samuel.marsh@childrens.harvard.edu", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-3012-6945")), person(given = "Ming", family = "Tang", role = c("ctb"), email = "tangming2005@gmail.com"), diff --git a/NEWS.md b/NEWS.md index 1fc16fa988..b3e522a89b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,20 @@ +# scCustomize 2.0.1 (2023-11-17) +## Added +- None. + + +## Changed +- Removed warning in `VariableFeaturePlot_scCustom` now fixed in Seurat release. + + +## Fixes +- Fixed error in `Add_Mito_Ribo_Seurat` causing failure due to error message when `overwrite = TRUE`. +- Fixed error in `Add_Top_Gene_Pct_Seurat` to avoid issue that accidentally could call function on normalized data. +- Fixed error in `Add_Top_Gene_Pct_Seurat` that caused error if more than one counts layer was present. +- Fixed error in `QC_Histogram` that prevented plotting or titling of plots. + + + # scCustomize 2.0.0 (2023-11-13) ## Added - Added support for metrics produced by Cell Ranger `multi` pipeline to `Read10X_Metrics` via new parameter `cellranger_multi`. diff --git a/R/Internal_Utilities.R b/R/Internal_Utilities.R index 7cf55f7877..e50e756d41 100644 --- a/R/Internal_Utilities.R +++ b/R/Internal_Utilities.R @@ -654,7 +654,7 @@ Retrieve_Ensembl_Ribo <- function( ) } cli_inform(message = c("Columns with {.val {oxphos_name}} and/or {.val {apop_name}} already present in meta.data slot.", - "i" = "Overwriting those columns as .code {overwrite = TRUE.}") + "i" = "Overwriting those columns as {.code overwrite = TRUE.}") ) } @@ -739,7 +739,7 @@ Retrieve_Ensembl_Ribo <- function( ) } cli_inform(message = c("Column with {.val {ieg_name}} already present in meta.data slot.", - "i" = "Overwriting those column as .code {overwrite = TRUE.}") + "i" = "Overwriting those column as {.code overwrite = TRUE.}") ) } diff --git a/R/Object_Utilities.R b/R/Object_Utilities.R index e5acba764a..a12e60e08a 100644 --- a/R/Object_Utilities.R +++ b/R/Object_Utilities.R @@ -183,7 +183,7 @@ Add_Mito_Ribo_Seurat <- function( ) } cli_inform(message = c("Columns with {.val {mito_name}} and/or {.val {ribo_name}} already present in meta.data slot.", - "i" = "Overwriting those columns as .code {overwrite = TRUE.}") + "i" = "Overwriting those columns as {.code overwrite = TRUE.}") ) } @@ -391,9 +391,10 @@ Add_Cell_Complexity_Seurat <- function( #' storing corrected and uncorrected assays in same object (e.g. outputs of both Cell Ranger and Cell Bender). #' @param overwrite Logical. Whether to overwrite existing an meta.data column. Default is FALSE meaning that #' function will abort if column with name provided to `meta_col_name` is present in meta.data slot. +#' @param verbose logical, whether to print messages with status updates, default is TRUE. #' #' @import cli -#' @importFrom dplyr select all_of +#' @importFrom dplyr select all_of bind_rows #' @importFrom magrittr "%>%" #' @importFrom rlang is_installed #' @importFrom SeuratObject LayerData @@ -425,7 +426,8 @@ Add_Top_Gene_Pct_Seurat <- function( num_top_genes = 50, meta_col_name = NULL, assay = "RNA", - overwrite = FALSE + overwrite = FALSE, + verbose = TRUE ){ # Check for scuttle first scuttle_check <- is_installed(pkg = "scuttle") @@ -468,15 +470,47 @@ Add_Top_Gene_Pct_Seurat <- function( ) } + count_layers_present <- Layers(object = seurat_object, search = "counts") + # Extract matrix - count_mat <- LayerData(object = seurat_object, assay = assay) + if (length(x = count_layers_present) == 1) { + if (isTRUE(x = verbose)) { + cli_inform(message = "Calculating percent expressing top {num_top_genes} for layer: {.field {count_layers_present}}") + } + + count_mat <- LayerData(object = seurat_object, assay = assay, layer = "counts") + + # calculate + res <- as.data.frame(scuttle::perCellQCMetrics(x = count_mat, percent.top = num_top_genes)) + + # select percent column + res <- res %>% + select(all_of(scuttle_colname)) + } + + + if (length(x = count_layers_present) > 1) { + res_list <- lapply(1:length(x = count_layers_present), function(x) { + if (isTRUE(x = verbose)) { + cli_inform(message = "Calculating percent expressing top {num_top_genes} for layer: {.field {count_layers_present[x]}}") + } - # calculate - res <- as.data.frame(scuttle::perCellQCMetrics(x = count_mat, percent.top = num_top_genes)) + # Get layer data + layer_count <- LayerData(object = seurat_object, assay = assay, layer = count_layers_present[x]) - # select percent column - res <- res %>% - select(all_of(scuttle_colname)) + # run scuttle + layer_res <- as.data.frame(scuttle::perCellQCMetrics(x = layer_count, percent.top = num_top_genes)) + # select results column + layer_res <- layer_res %>% + select(all_of(scuttle_colname)) + }) + + # combine results + if (isTRUE(x = verbose)) { + cli_inform(message = "Combining data from: {.field {count_layers_present}}") + } + res <- bind_rows(res_list) + } # Add to object and return seurat_object <- AddMetaData(object = seurat_object, metadata = res, col.name = meta_col_name) diff --git a/R/QC_Plotting_Seurat.R b/R/QC_Plotting_Seurat.R index 10ecad7ba9..4eebbbdaf0 100644 --- a/R/QC_Plotting_Seurat.R +++ b/R/QC_Plotting_Seurat.R @@ -632,12 +632,14 @@ QC_Histogram <- function( } # Check and set titles - if (is.null(x = plot_title) && is.null(x = split.by)) { - plot_titles <- all_found_features + if (!is.null(x = plot_title) && length(x = plot_title) != length(x = features)) { + cli_abort(message = "The number of {.code plot_title} (.field {length(x = plot_title)}}) does not equal number of features ({.field {length(x = all_found_features)}})") + } else { + plot_titles <- plot_title } - if (!is.null(x = plot_title) && length(x = plot_title) != features) { - cli_abort(message = "The number of {.code plot_title} (.field {length(x = plot_title)}}) does not equal number of features ({.field {length(x = all_found_features)}})") + if (is.null(x = plot_title) && is.null(x = split.by)) { + plot_titles <- all_found_features } # Plot diff --git a/R/Seurat_Plotting.R b/R/Seurat_Plotting.R index b27c284a13..0453f07305 100644 --- a/R/Seurat_Plotting.R +++ b/R/Seurat_Plotting.R @@ -2582,12 +2582,6 @@ VariableFeaturePlot_scCustom <- function( # set assay (if null set to active assay) assay <- assay %||% DefaultAssay(object = seurat_object) - if (isTRUE(x = Assay5_Check(seurat_object = seurat_object, assay = assay))) { - cli_inform(message = c("!" = "Currently labeling top variable genes from Assay5 object will not correctly label top variable features due to changes in Seurat5.", - "i" = "This feature will be updated when more information comes from Seurat Dev team.", - "i" = "For now the top variable features can be manually extracted and provided to {.code custom_features} parameter.")) - } - # Extract num of desired features top_features <- head(x = VariableFeatures(object = seurat_object, assay = assay, selection.method = selection.method), num_features) diff --git a/cran-comments.md b/cran-comments.md index a49afa0b7f..0114bff69f 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,9 +1,7 @@ ## Minor Version Update -This is a major version update to v2.0.0. In this version I have: +This is a hotfix update with bug fixes now v2.0.1; apologies for not catching these in v2.0.0 submission last week. In this version I have: -- Added a number of new functions, added new function parameters, and fixed bugs (see News.md). -- Ensured compatibility with major version of Seurat package. -- Fixed in example code causing current CRAN check errors with current package version (v1.1.3). +- Fixed 5 minor bugs presented in v2.0.0 release. ## R CMD check results @@ -29,5 +27,5 @@ This is a major version update to v2.0.0. In this version I have: - The errors are from failures running package examples. This includes functions that have been part of prior CRAN releases. NO errors are found when checking locally on macos platform using R 4.3.2 and none are found in GitHub Actions check on linux or windows platforms. I believe to be error in GitHub Actions workflow and I have therefore refrained from adding `dontrun` - to examples that run fine on other platforms. If error occurs during CRAN check during submission I will re-evaluate changes - required. + to examples that run fine on other platforms. This was also the case with v2.0.0 which passed macos checks on CRAN, + furthering it is likely a GitHub Actions issue. diff --git a/man/Add_Top_Gene_Pct_Seurat.Rd b/man/Add_Top_Gene_Pct_Seurat.Rd index 635377a8aa..8b688c37b7 100644 --- a/man/Add_Top_Gene_Pct_Seurat.Rd +++ b/man/Add_Top_Gene_Pct_Seurat.Rd @@ -9,7 +9,8 @@ Add_Top_Gene_Pct_Seurat( num_top_genes = 50, meta_col_name = NULL, assay = "RNA", - overwrite = FALSE + overwrite = FALSE, + verbose = TRUE ) } \arguments{ @@ -26,6 +27,8 @@ storing corrected and uncorrected assays in same object (e.g. outputs of both Ce \item{overwrite}{Logical. Whether to overwrite existing an meta.data column. Default is FALSE meaning that function will abort if column with name provided to \code{meta_col_name} is present in meta.data slot.} + +\item{verbose}{logical, whether to print messages with status updates, default is TRUE.} } \value{ A Seurat Object diff --git a/man/scCustomize-package.Rd b/man/scCustomize-package.Rd index 4f49c3581c..b6fa127778 100644 --- a/man/scCustomize-package.Rd +++ b/man/scCustomize-package.Rd @@ -6,7 +6,7 @@ \alias{scCustomize-package} \title{scCustomize: Custom Visualizations & Functions for Streamlined Analyses of Single Cell Sequencing} \description{ -Collection of functions created and/or curated to aid in the visualization and analysis of single-cell data using 'R'. 'scCustomize' aims to provide 1) Customized visualizations for aid in ease of use and to create more aesthetic and functional visuals. 2) Improve speed/reproducibility of common tasks/pieces of code in scRNA-seq analysis with a single or group of functions. For citation please use: Marsh SE (2021) "Custom Visualizations & Functions for Streamlined Analyses of Single Cell Sequencing" \doi{10.5281/zenodo.5706430}. +Collection of functions created and/or curated to aid in the visualization and analysis of single-cell data using 'R'. 'scCustomize' aims to provide 1) Customized visualizations for aid in ease of use and to create more aesthetic and functional visuals. 2) Improve speed/reproducibility of common tasks/pieces of code in scRNA-seq analysis with a single or group of functions. For citation please use: Marsh SE (2021) "Custom Visualizations & Functions for Streamlined Analyses of Single Cell Sequencing" \doi{10.5281/zenodo.5706430} RRID:SCR_024675. } \section{Package options}{