Skip to content

Commit 6bbf48a

Browse files
authored
Merge pull request #220 from samuel-marsh/release/3.0.1
Release 3.0.1
2 parents 6adcbed + 56e5fca commit 6bbf48a

16 files changed

+322
-113
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ Package: scCustomize
22
Type: Package
33
Title: Custom Visualizations & Functions for Streamlined Analyses of Single Cell Sequencing
44
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> RRID:SCR_024675.
5-
Version: 3.0.0
6-
Date: 2024-12-05
5+
Version: 3.0.1
6+
Date: 2024-12-18
77
Authors@R: c(
88
person(given = "Samuel", family = "Marsh", email = "samuel.marsh@childrens.harvard.edu", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-3012-6945")),
99
person(given = "Ming", family = "Tang", role = c("ctb"), email = "tangming2005@gmail.com"),

NEWS.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
# scCustomize 3.0.1 (2024-12-18)
2+
## Added
3+
- Added new parameters `output_width` and `output_height` to the `Iterate_*` family of plotting functions ([#217](https://github.com/samuel-marsh/scCustomize/issues/217)).
4+
5+
6+
## Changed
7+
8+
9+
## Fixes
10+
- Fixed bug in `Random_Cells_Downsample` that prevented setting identity using the `group.by` parameter.
11+
- Fixed bug in `Cell_Highlight_Plot` that didn't pass the reduction parameter properly ([#216](https://github.com/samuel-marsh/scCustomize/issues/216)).
12+
- Fixed bug when retrieving ensembl IDs for IEGs.
13+
- Fixed bug that prevented using `return_plots` in iterative plotting functions([#217](https://github.com/samuel-marsh/scCustomize/issues/217)).
14+
15+
16+
17+
118
# scCustomize 3.0.0 (2024-12-05)
219
## Added
320
**Major Updates to Functionality with rliger Package:**

R/Internal_Utilities.R

Lines changed: 94 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747

4848

4949
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50-
#################### Object Checks ####################
50+
#################### Object/Feature Checks ####################
5151
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5252

5353

@@ -188,8 +188,68 @@ Assay5_Check <- function(
188188
}
189189

190190

191+
#' Perform Feature and Meta Checks before plotting
192+
#'
193+
#' Wraps the `Feature_Present`, `Meta_Present`, `Reduction_Loading_Present`, and `Case_Check` into
194+
#' single function to perform feature checks before plotting.
195+
#'
196+
#' @param object Seurat object
197+
#' @param features vector of features and/or meta data variables to plot.
198+
#' @param assay Assay to use (default all assays present).
199+
#'
200+
#' @return vector of features and/or meta data that were found in object.
201+
#'
202+
#' @noRd
203+
#'
204+
#' @keywords internal
205+
#'
206+
207+
Feature_PreCheck <- function(
208+
object,
209+
features,
210+
assay = NULL
211+
) {
212+
# set assay (if null set to active assay)
213+
assay <- assay %||% Assays(object = object)
214+
215+
# Check features and meta to determine which features present
216+
features_list <- Feature_Present(data = object, features = features, omit_warn = FALSE, print_msg = FALSE, case_check_msg = FALSE, return_none = TRUE, seurat_assay = assay)
217+
218+
meta_list <- Meta_Present(object = object, meta_col_names = features_list[[2]], omit_warn = FALSE, print_msg = FALSE, return_none = TRUE)
219+
220+
reduction_list <- Reduction_Loading_Present(seurat_object = object, reduction_names = meta_list[[2]], omit_warn = FALSE, print_msg = FALSE, return_none = TRUE)
221+
222+
all_not_found_features <- reduction_list[[2]]
223+
224+
all_found_features <- c(features_list[[1]], meta_list[[1]], reduction_list[[1]])
225+
226+
# Stop if no features found
227+
if (length(x = all_found_features) < 1) {
228+
cli_abort(message = c("No features were found.",
229+
"*" = "The following are not present in object:",
230+
"i" = "{.field {glue_collapse_scCustom(input_string = all_not_found_features, and = TRUE)}}")
231+
)
232+
}
233+
234+
# Return message of features not found
235+
if (length(x = all_not_found_features) > 0) {
236+
op <- options(warn = 1)
237+
on.exit(options(op))
238+
cli_warn(message = c("The following features were omitted as they were not found:",
239+
"i" = "{.field {glue_collapse_scCustom(input_string = all_not_found_features, and = TRUE)}}")
240+
)
241+
}
242+
243+
# Check feature case and message if found
244+
Case_Check(seurat_object = object, gene_list = all_not_found_features, case_check_msg = TRUE, return_features = FALSE)
245+
246+
# return all found features
247+
return(all_found_features)
248+
}
249+
250+
191251
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
192-
#################### WARN/ERROR MESSAGING ####################
252+
#################### FUNCTION HELPERS ####################
193253
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
194254

195255

@@ -250,66 +310,6 @@ glue_collapse_scCustom <- function(
250310
}
251311

252312

253-
#' Perform Feature and Meta Checks before plotting
254-
#'
255-
#' Wraps the `Feature_Present`, `Meta_Present`, `Reduction_Loading_Present`, and `Case_Check` into
256-
#' single function to perform feature checks before plotting.
257-
#'
258-
#' @param object Seurat object
259-
#' @param features vector of features and/or meta data variables to plot.
260-
#' @param assay Assay to use (default all assays present).
261-
#'
262-
#' @return vector of features and/or meta data that were found in object.
263-
#'
264-
#' @noRd
265-
#'
266-
#' @keywords internal
267-
#'
268-
269-
Feature_PreCheck <- function(
270-
object,
271-
features,
272-
assay = NULL
273-
) {
274-
# set assay (if null set to active assay)
275-
assay <- assay %||% Assays(object = object)
276-
277-
# Check features and meta to determine which features present
278-
features_list <- Feature_Present(data = object, features = features, omit_warn = FALSE, print_msg = FALSE, case_check_msg = FALSE, return_none = TRUE, seurat_assay = assay)
279-
280-
meta_list <- Meta_Present(object = object, meta_col_names = features_list[[2]], omit_warn = FALSE, print_msg = FALSE, return_none = TRUE)
281-
282-
reduction_list <- Reduction_Loading_Present(seurat_object = object, reduction_names = meta_list[[2]], omit_warn = FALSE, print_msg = FALSE, return_none = TRUE)
283-
284-
all_not_found_features <- reduction_list[[2]]
285-
286-
all_found_features <- c(features_list[[1]], meta_list[[1]], reduction_list[[1]])
287-
288-
# Stop if no features found
289-
if (length(x = all_found_features) < 1) {
290-
cli_abort(message = c("No features were found.",
291-
"*" = "The following are not present in object:",
292-
"i" = "{.field {glue_collapse_scCustom(input_string = all_not_found_features, and = TRUE)}}")
293-
)
294-
}
295-
296-
# Return message of features not found
297-
if (length(x = all_not_found_features) > 0) {
298-
op <- options(warn = 1)
299-
on.exit(options(op))
300-
cli_warn(message = c("The following features were omitted as they were not found:",
301-
"i" = "{.field {glue_collapse_scCustom(input_string = all_not_found_features, and = TRUE)}}")
302-
)
303-
}
304-
305-
# Check feature case and message if found
306-
Case_Check(seurat_object = object, gene_list = all_not_found_features, case_check_msg = TRUE, return_features = FALSE)
307-
308-
# return all found features
309-
return(all_found_features)
310-
}
311-
312-
313313
#' Ask yes/no question to proceed
314314
#'
315315
#' Asks the user to answer yes/no question and returns logical value depending on
@@ -337,6 +337,37 @@ yesno <- function(msg, .envir = parent.frame()) {
337337
}
338338

339339

340+
#' Change function parameter value from NULL to NA
341+
#'
342+
#' Provides method to change parameter value dynamically within function to suit defaults of other functions.
343+
#' Used in iterative plotting functions.
344+
#'
345+
#' @param parameter the parameter to check for NULL
346+
#'
347+
#' @return if NULL returns NA otherwise returns input value.
348+
#'
349+
#'
350+
#' @import cli
351+
#'
352+
#' @noRd
353+
#'
354+
355+
replace_null <- function(
356+
parameter
357+
) {
358+
# check length
359+
if (length(x = parameter) > 1) {
360+
cli_abort(message = "{.code parameter} must be single value.")
361+
}
362+
363+
# check NULL and swap NA
364+
if (is.null(x = parameter)) {
365+
parameter <- NA
366+
}
367+
return(parameter)
368+
}
369+
370+
340371
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
341372
#################### QC HELPERS ####################
342373
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -827,7 +858,7 @@ Retrieve_IEG_Ensembl_Lists <- function(
827858

828859
# pull lists
829860
qc_gene_list <- list(
830-
ieg = ieg_gene_list[[ieg]]
861+
ieg = ensembl_ieg_list[[ieg]]
831862
)
832863

833864
return(qc_gene_list)

R/Object_Utilities.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ Fetch_Meta.Seurat <- function(
474474
#' @param num_cells number of cells per ident to use in down-sampling. This value must be less than or
475475
#' equal to the size of ident with fewest cells. Alternatively, can set to "min" which will
476476
#' use the maximum number of barcodes based on size of smallest group.
477-
#' @param group.by The ident to use to group cells. Default is "ident" which use current active.ident. .
477+
#' @param group.by The ident to use to group cells. Default is NULL which use current active.ident. .
478478
#' @param return_list logical, whether or not to return the results as list instead of vector, default is
479479
#' FALSE.
480480
#' @param allow_lower logical, if number of cells in identity is lower than `num_cells` keep the
@@ -513,7 +513,7 @@ Fetch_Meta.Seurat <- function(
513513
Random_Cells_Downsample <- function(
514514
seurat_object,
515515
num_cells,
516-
group.by = "ident",
516+
group.by = NULL,
517517
return_list = FALSE,
518518
allow_lower = FALSE,
519519
seed = 123
@@ -522,7 +522,7 @@ Random_Cells_Downsample <- function(
522522
Is_Seurat(seurat_object = seurat_object)
523523

524524
# set ident in case of NULL
525-
group.by <- "ident" %||% group.by
525+
group.by <- group.by %||% "ident"
526526

527527
# Check and set idents if not "ident"
528528
if (group.by != "ident") {
@@ -536,7 +536,7 @@ Random_Cells_Downsample <- function(
536536
rownames_to_column("barcodes")
537537

538538
# get unique ident vector
539-
idents_all <- as.character(levels(x = Idents(object = seurat_object)))
539+
idents_all <- as.character(x = levels(x = Idents(object = seurat_object)))
540540

541541
# Find minimum length ident and warn if num_cells not equal or lower
542542
min_cells <- CellsByIdentities(object = seurat_object)
@@ -574,7 +574,7 @@ Random_Cells_Downsample <- function(
574574
# set seed and select random cells per ident
575575
set.seed(seed = seed)
576576

577-
random_cells <- lapply(1:length(idents_all), function(x) {
577+
random_cells <- lapply(1:length(x = idents_all), function(x) {
578578
clus_barcodes <- cluster_barcodes %>%
579579
filter(.data[["ident"]] == idents_all[x]) %>%
580580
column_to_rownames("barcodes") %>%

R/Plotting_Seurat.R

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,6 +1688,7 @@ Cell_Highlight_Plot <- function(
16881688
split.by = split.by,
16891689
split_seurat = split_seurat,
16901690
label = label,
1691+
reduction = reduction,
16911692
...)
16921693

16931694
# Edit plot legend
@@ -1710,9 +1711,6 @@ Cell_Highlight_Plot <- function(
17101711
}
17111712

17121713

1713-
1714-
1715-
17161714
#' DimPlot with modified default settings
17171715
#'
17181716
#' Creates DimPlot with some of the settings modified from their Seurat defaults (colors_use, shuffle, label).

0 commit comments

Comments
 (0)