Skip to content

Commit

Permalink
Use latest tidyselect interface
Browse files Browse the repository at this point in the history
  • Loading branch information
igordot committed Jan 4, 2024
1 parent 6f1d0cf commit 1678b98
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 19 deletions.
7 changes: 3 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: clustermole
Title: Unbiased Single-Cell Transcriptomic Data Cell Type Identification
Version: 1.1.0.9000
Version: 1.1.0.9001
Authors@R:
person(given = "Igor",
family = "Dolgalev",
Expand All @@ -19,18 +19,17 @@ Imports:
GSVA (>= 1.26.0),
magrittr,
methods,
rlang (>= 0.1.2),
rlang,
singscore,
tibble,
tidyr,
utils
Suggests:
covr,
knitr,
prettydoc,
rmarkdown,
roxygen2,
testthat (>= 2.1.0)
testthat
biocViews:
Encoding: UTF-8
RoxygenNote: 7.2.3
Expand Down
13 changes: 6 additions & 7 deletions R/enrichment.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#' @examples
#' # my_enrichment <- clustermole_enrichment(expr_mat = my_expr_mat, species = "hs")
clustermole_enrichment <- function(expr_mat, species, method = "gsva") {

# check that the expression matrix seems reasonable
if (!is(expr_mat, "matrix")) {
stop("expression matrix is not a matrix")
Expand Down Expand Up @@ -53,7 +52,7 @@ clustermole_enrichment <- function(expr_mat, species, method = "gsva") {
# create a table of cell types (without genes)
celltypes_tbl <-
markers_tbl %>%
dplyr::select(-dplyr::starts_with("gene")) %>%
dplyr::select(!dplyr::starts_with("gene")) %>%
dplyr::distinct()

# run the actual enrichment analysis
Expand All @@ -80,7 +79,7 @@ get_scores <- function(expr_mat, markers_list, method = c("gsva", "ssgsea", "sin
method = "gsva", kcdf = "Gaussian", parallel.sz = 1, verbose = FALSE
)
scores_tbl <- lengthen_scores(scores_mat)
scores_gsva_tbl <- dplyr::select(scores_tbl, .data$cluster, .data$celltype_full, score_rank_gsva = .data$score_rank)
scores_gsva_tbl <- dplyr::select(scores_tbl, "cluster", "celltype_full", score_rank_gsva = "score_rank")
}

if (method == "ssgsea" || method == "all") {
Expand All @@ -89,7 +88,7 @@ get_scores <- function(expr_mat, markers_list, method = c("gsva", "ssgsea", "sin
method = "ssgsea", kcdf = "Gaussian", parallel.sz = 1, verbose = FALSE
)
scores_tbl <- lengthen_scores(scores_mat)
scores_ssgsea_tbl <- dplyr::select(scores_tbl, .data$cluster, .data$celltype_full, score_rank_ssgsea = .data$score_rank)
scores_ssgsea_tbl <- dplyr::select(scores_tbl, "cluster", "celltype_full", score_rank_ssgsea = "score_rank")
}

if (method == "singscore" || method == "all") {
Expand All @@ -98,7 +97,7 @@ get_scores <- function(expr_mat, markers_list, method = c("gsva", "ssgsea", "sin
scores_mat <- singscore::multiScore(rankData = rankGenes(expr_mat), upSetColc = markers_gsc)
scores_mat <- scores_mat$Scores
scores_tbl <- lengthen_scores(scores_mat)
scores_singscore_tbl <- dplyr::select(scores_tbl, .data$cluster, .data$celltype_full, score_rank_singscore = .data$score_rank)
scores_singscore_tbl <- dplyr::select(scores_tbl, "cluster", "celltype_full", score_rank_singscore = "score_rank")
}

if (method == "all") {
Expand Down Expand Up @@ -128,8 +127,8 @@ lengthen_scores <- function(scores_mat) {
scores_mat %>%
round(10) %>%
tibble::as_tibble(rownames = "celltype_full") %>%
tidyr::gather(key = "cluster", value = "score", -.data$celltype_full) %>%
dplyr::select(.data$cluster, .data$celltype_full, .data$score) %>%
tidyr::gather(key = "cluster", value = "score", -"celltype_full") %>%
dplyr::select("cluster", "celltype_full", "score") %>%
dplyr::group_by(.data$cluster) %>%
dplyr::mutate(score_rank = rank(desc(.data$score), ties.method = "first")) %>%
dplyr::ungroup()
Expand Down
11 changes: 4 additions & 7 deletions R/markers.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#'
#' @return A data frame of cell type markers (one gene per row).
#'
#' @import dplyr
#' @export
#'
#' @examples
Expand All @@ -16,12 +15,10 @@ clustermole_markers <- function(species = c("hs", "mm")) {
species <- match.arg(species)
m_tbl <- clustermole_markers_tbl
if (species == "hs") {
m_tbl %>%
dplyr::select(-.data$gene_mm) %>%
dplyr::rename(gene = .data$gene_hs)
names(m_tbl)[names(m_tbl) == "gene_hs"] <- "gene"
m_tbl[, !(names(m_tbl) %in% "gene_mm")]
} else if (species == "mm") {
m_tbl %>%
dplyr::select(-.data$gene_hs) %>%
dplyr::rename(gene = .data$gene_mm)
names(m_tbl)[names(m_tbl) == "gene_mm"] <- "gene"
m_tbl[, !(names(m_tbl) %in% "gene_hs")]
}
}
2 changes: 1 addition & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ read_gmt <- function(file, geneset_label = "celltype", gene_label = "gene") {
gmt_list <- lapply(gmt_split, tail, -2)
names(gmt_list) <- sapply(gmt_split, head, 1)
gmt_df <- tibble::enframe(gmt_list, name = geneset_label, value = gene_label)
gmt_df <- tidyr::unnest(gmt_df, gene_label)
gmt_df <- tidyr::unnest(gmt_df, all_of(gene_label))
gmt_df
}

0 comments on commit 1678b98

Please sign in to comment.