Skip to content

Commit

Permalink
Merge pull request #73 from samuel-marsh/develop
Browse files Browse the repository at this point in the history
Merge for 1.0.1 Release
  • Loading branch information
samuel-marsh authored Nov 10, 2022
2 parents b6a0837 + 6370335 commit 67f8fa4
Show file tree
Hide file tree
Showing 13 changed files with 542 additions and 37 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: scCustomize
Type: Package
Title: An R package for custom visualization & analyses of single cell sequencing.
Version: 1.0.0
Date: 2022-10-25
Version: 1.0.1
Date: 2022-11-10
Authors@R: c(
person(given = "Samuel", family = "Marsh", email = "[email protected]", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-3012-6945")),
person(given = "Ming", family = "Tang", role = c("ctb"), email = "[email protected]"),
Expand All @@ -13,7 +13,7 @@ Description: Collection of functions created and/or curated to aid in the visual
URL: https://github.com/samuel-marsh/scCustomize, https://samuel-marsh.github.io/scCustomize, https://doi.org/10.5281/zenodo.5706431
BugReports: https://github.com/samuel-marsh/scCustomize/issues
Depends: R (>= 4.0.0),
Seurat (>= 4.2.0)
Seurat (>= 4.2.1)
Imports:
circlize,
cli (>= 3.2.0),
Expand Down
8 changes: 7 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated by roxygen2: do not edit by hand

export(Add_Cell_Bender_Diff)
export(Add_CellBender_Diff)
export(Add_Cell_Complexity_LIGER)
export(Add_Cell_Complexity_Seurat)
export(Add_Mito_Ribo_LIGER)
Expand All @@ -9,6 +9,8 @@ export(Add_Pct_Diff)
export(Add_Sample_Meta)
export(Blank_Theme)
export(Case_Check)
export(CellBender_Diff_Plot)
export(CellBender_Feature_Diff)
export(Change_Delim_All)
export(Change_Delim_Prefix)
export(Change_Delim_Suffix)
Expand Down Expand Up @@ -131,6 +133,7 @@ import(patchwork)
import(pbapply)
import(viridis)
importFrom(Matrix,readMM)
importFrom(Matrix,rowSums)
importFrom(Seurat,AddMetaData)
importFrom(Seurat,DimPlot)
importFrom(Seurat,DotPlot)
Expand All @@ -150,6 +153,7 @@ importFrom(cowplot,theme_cowplot)
importFrom(data.table,fread)
importFrom(dplyr,arrange)
importFrom(dplyr,bind_rows)
importFrom(dplyr,desc)
importFrom(dplyr,filter)
importFrom(dplyr,group_by)
importFrom(dplyr,intersect)
Expand Down Expand Up @@ -188,6 +192,7 @@ importFrom(purrr,keep)
importFrom(purrr,map)
importFrom(purrr,map2)
importFrom(purrr,map_dbl)
importFrom(purrr,pluck)
importFrom(purrr,reduce)
importFrom(scales,alpha)
importFrom(scales,hue_pal)
Expand All @@ -203,6 +208,7 @@ importFrom(stringr,str_wrap)
importFrom(tibble,column_to_rownames)
importFrom(tibble,rownames_to_column)
importFrom(tibble,tribble)
importFrom(tidyr,drop_na)
importFrom(tidyr,pivot_wider)
importFrom(tidyselect,all_of)
importFrom(utils,combn)
Expand Down
13 changes: 13 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# scCustomize 1.0.1 (2022-11-10)
## Added
- Added `CellBender_Feature_Diff` to return data.frame with count sums and differences between raw and CellBender assays.
- Added `CellBender_Diff_Plot` to plot differences between raw and CellBender assays using data from `CellBender_Feature_Diff`.

## Changed
- **BREAKING CHANGE** Function name changed, `Add_CellBender_Diff` is new name for `Add_Cell_Bender_Diff` in order to unify function names for CellBender related functions.
- Updated CellBender vignette with new functions.

## Fixes
- Fixed for automatic color palette selection when only plotting one group.


# scCustomize 1.0.0 (2022-10-25)
## Added
- Added `mito_name` parameter to `QC_Plots_Mito` to allow for custom specification of meta data column name that contains mitochondrial information.
Expand Down
3 changes: 3 additions & 0 deletions R/Color_Palettes.R
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,9 @@ scCustomize_Palette <- function(
if (ggplot_default_colors) {
colors_use <- Hue_Pal(num_colors = num_groups)
} else {
if (num_groups == 1) {
colors_use <- "dodgerblue"
}
if (num_groups == 2) {
colors_use <- NavyAndOrange()
}
Expand Down
25 changes: 25 additions & 0 deletions R/Internal_Utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -453,3 +453,28 @@ No_Right <- function() {
)
return(no.right)
}


#' Symetrical setdiff
#'
#' tests for differences between two vectors symmetrically.
#'
#' @param x first vector to test
#' @param y second vector to test
#'
#' @return vector differences x vs. y and y vs. x
#'
#' @references Function name and code from R-bloggers post:
#' (https://www.r-bloggers.com/2013/06/symmetric-set-differences-in-r/)
#'
#' @keywords internal
#'
#' @noRd
#'

symdiff <- function(
x,
y
) {
setdiff(x = union(x = x, y = y), intersect(x = x, y = y))
}
4 changes: 2 additions & 2 deletions R/Object_Utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -517,11 +517,11 @@ Add_Sample_Meta <- function(
#'
#' @examples
#' \dontrun{
#' object <- Add_Cell_Bender_Diff(seurat_object = obj, raw_assay_name = "RAW", cell_bender_assay_name = "RNA")
#' object <- Add_CellBender_Diff(seurat_object = obj, raw_assay_name = "RAW", cell_bender_assay_name = "RNA")
#' }
#'

Add_Cell_Bender_Diff <- function(
Add_CellBender_Diff <- function(
seurat_object,
raw_assay_name,
cell_bender_assay_name
Expand Down
8 changes: 4 additions & 4 deletions R/Seurat_Plotting.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ FeaturePlot_scCustom <- function(
if (length(x = all_found_features) < 1) {
cli_abort(message = c("No features were found.",
"*" = "The following are not present in object:",
"i" = "{scCustomize:::glue_collapse_scCustom(input_string = all_not_found_features, and = TRUE)}")
"i" = "{glue_collapse_scCustom(input_string = all_not_found_features, and = TRUE)}")
)
}

Expand Down Expand Up @@ -1011,7 +1011,7 @@ Stacked_VlnPlot <- function(
if (length(x = all_found_features) < 1) {
cli_abort(message = c("No features were found.",
"*" = "The following are not present in object:",
"i" = "{scCustomize:::glue_collapse_scCustom(input_string = all_not_found_features, and = TRUE)}")
"i" = "{glue_collapse_scCustom(input_string = all_not_found_features, and = TRUE)}")
)
}

Expand Down Expand Up @@ -1152,7 +1152,7 @@ DotPlot_scCustom <- function(
if (length(x = all_found_features) < 1) {
cli_abort(message = c("No features were found.",
"*" = "The following are not present in object:",
"i" = "{scCustomize:::glue_collapse_scCustom(input_string = all_not_found_features, and = TRUE)}")
"i" = "{glue_collapse_scCustom(input_string = all_not_found_features, and = TRUE)}")
)
}

Expand All @@ -1161,7 +1161,7 @@ DotPlot_scCustom <- function(
op <- options(warn = 1)
on.exit(options(op))
cli_warn(message = c("The following features were omitted as they were not found:",
"i" = "{scCustomize:::glue_collapse_scCustom(input_string = all_not_found_features, and = TRUE)}")
"i" = "{glue_collapse_scCustom(input_string = all_not_found_features, and = TRUE)}")
)
}

Expand Down
84 changes: 84 additions & 0 deletions R/Statistics.R
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,87 @@ Median_Stats <- function(
}


#' CellBender Feature Differences
#'
#' Get quick values for raw counts, CellBender counts, count differences, and percent count differences
#' per feature.
#'
#' @param seurat_object Seurat object name.
#' @param raw_assay Name of the assay containing the raw count data.
#' @param cell_bender_assay Name of the assay containing the CellBender count data.
#'
#' @return A data frame containing summed raw counts, CellBender counts, count difference, and
#' percent difference in counts.
#'
#' @import cli
#' @importFrom dplyr arrange desc left_join mutate
#' @importFrom magrittr "%>%"
#' @importFrom Matrix rowSums
#' @importFrom purrr pluck
#' @importFrom tibble rownames_to_column column_to_rownames
#'
#' @export
#'
#' @concept stats
#'
#' @examples
#' \dontrun{
#' cb_stats <- CellBender_Feature_Diff(seurat_object - obj, raw_assay = "RAW",
#' cell_bender_assay = "RNA")
#' }
#'

CellBender_Feature_Diff <- function(
seurat_object,
raw_assay,
cell_bender_assay
) {
# Is Seurat
Is_Seurat(seurat_object = seurat_object)

# Check assays present
assays_not_found <- Assay_Present(seurat_object = seurat_object, assay_list = c(raw_assay, cell_bender_assay), print_msg = FALSE, omit_warn = TRUE)[[2]]

if (!is.null(x = assays_not_found)) {
stop_quietly()
}

# Pull raw counts
raw_counts <- pluck(seurat_object, "assays", raw_assay, "counts") %>%
rowSums() %>%
data.frame() %>%
rownames_to_column("Feature_Names")

colnames(raw_counts)[2] <- "Raw_Counts"

# Pull Cell Bender Counts
cb_counts <- pluck(seurat_object, "assays", cell_bender_assay, "counts") %>%
rowSums() %>%
data.frame() %>%
rownames_to_column("Feature_Names")

colnames(cb_counts)[2] <- "CellBender_Counts"

# Check features identical
diff_features <- symdiff(x = raw_counts$Feature_Names, y = cb_counts$Feature_Names)

if (length(x = diff_features > 0)) {
cli_warn(message = c("The following features are not present in both assays:",
"*" = "{diff_features}",
"i" = "Check matrices used to create object.")
)
}

# merge
merged_counts <- suppressMessages(left_join(x = raw_counts, y = cb_counts))

# Add diff and % diff
merged_counts <- merged_counts %>%
mutate(Count_Diff = Raw_Counts - CellBender_Counts,
Pct_Diff = 100 - ((CellBender_Counts / Raw_Counts) * 100)) %>%
arrange(desc(Pct_Diff)) %>%
column_to_rownames("Feature_Names")

# return data
return(merged_counts)
}
Loading

0 comments on commit 67f8fa4

Please sign in to comment.