Skip to content

Commit

Permalink
Merge pull request #37 from spriyansh/main
Browse files Browse the repository at this point in the history
Updating to version 0.0.3
  • Loading branch information
spriyansh authored Mar 3, 2024
2 parents df8c870 + cb97fea commit 37086c9
Show file tree
Hide file tree
Showing 21 changed files with 500 additions and 263 deletions.
9 changes: 6 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: scMaSigPro
Type: Package
Title: Application of MaSigPro Bioconductor Package for scRNA Trajectory data
Version: 0.0.2
Version: 0.0.3
Authors@R: c(
person("Ana", "Conesa", role = c("aut"), email = "ana.conesa@csic.es"),
person("Maria Jose", "Nueda", role = c("aut"), email = "mj.nueda@ua.es"),
Expand All @@ -17,7 +17,7 @@ Imports:
assertthat, e1071, dplyr, entropy, ggplot2, igraph, magrittr, maSigPro,
MASS, MatrixGenerics, methods, parallel, parallelly, plotly, RColorConesa,
rlang, S4Vectors, scales, shiny, SingleCellExperiment, stats, stringr,
utils, ComplexUpset, mclust, SummarizedExperiment
utils, mclust
Depends: R (>= 4.0)
Encoding: UTF-8
LazyData: true
Expand All @@ -27,7 +27,10 @@ Suggests:
roxygen2,
knitr,
rmarkdown,
BiocStyle
BiocStyle,
ComplexUpset,
UpSetR,
patchwork
Config/testthat/edition: 3
URL: https://github.com/BioBam/scMaSigPro/
biocViews: Clustering, Regression, TimeCourse, DifferentialExpression,
Expand Down
7 changes: 1 addition & 6 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ exportMethods(eSparse)
exportMethods(pathAssign)
exportMethods(predictors)
import(ggplot2)
importFrom(ComplexUpset,intersection_matrix)
importFrom(ComplexUpset,intersection_size)
importFrom(ComplexUpset,upset)
importFrom(ComplexUpset,upset_set_size)
importFrom(MASS,glm.nb)
importFrom(MASS,negative.binomial)
importFrom(MatrixGenerics,rowMeans)
Expand All @@ -66,8 +62,6 @@ importFrom(S4Vectors,isEmpty)
importFrom(SingleCellExperiment,SingleCellExperiment)
importFrom(SingleCellExperiment,colData)
importFrom(SingleCellExperiment,reducedDims)
importFrom(SummarizedExperiment,"assay<-")
importFrom(SummarizedExperiment,assay)
importFrom(assertthat,assert_that)
importFrom(dplyr,arrange)
importFrom(dplyr,bind_rows)
Expand Down Expand Up @@ -173,5 +167,6 @@ importFrom(stringr,str_split_i)
importFrom(utils,View)
importFrom(utils,combn)
importFrom(utils,data)
importFrom(utils,packageVersion)
importFrom(utils,setTxtProgressBar)
importFrom(utils,txtProgressBar)
179 changes: 107 additions & 72 deletions R/plotIntersect.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
#'
#' @description
#' Generate UpSet Plot on Intersection of Significant Genes from scMaSigPro
#' object. It is a wrapper around `ComplexUpset::upset`.
#' object. It is a wrapper around `ComplexUpset::upset` and `UpSetR::upset`.
#'
#' @importFrom S4Vectors isEmpty
#' @importFrom ComplexUpset upset intersection_matrix intersection_size upset_set_size
#' @importFrom RColorConesa colorConesa
#'
#' @importFrom utils packageVersion
#'
#' @param scmpObj An object of class \code{\link{ScMaSigPro}}.
#' @param min_intersection_size Minimal number of observations in an intersection
#' for it to be included.
Expand All @@ -16,16 +16,22 @@
#' @param keep_empty_groups Whether empty sets should be kept (including sets
#' which are only empty after filtering by size)
#' @param show_sets_size The overall set sizes plot, e.g. from upset_set_size()
#' (FALSE to hide)
#' @param package Which package to use for the UpsetPlot. Options are 'ComplexUpset'
#' or 'UpSetR' (Default).
#' @param verbose Print detailed output in the console. (Default is TRUE)
#'
#' @return ggplot2 plot object.
#' @return ggplot2 plot object for 'ComplexUpset' or upset object for 'UpSetR'.
#'
#' @author Priyansh Srivastava \email{spriyansh29@@gmail.com}
#'
#' @export
plotIntersect <- function(scmpObj, min_intersection_size = 2,
plotIntersect <- function(scmpObj,
package = "UpSetR",
min_intersection_size = 2,
keep_empty_groups = TRUE,
width_ratio = 0.1, show_sets_size = FALSE) {
width_ratio = 0.1,
show_sets_size = FALSE,
verbose = TRUE) {
# Check the data
assert_that(
is(scmpObj, "ScMaSigPro"),
Expand All @@ -37,80 +43,109 @@ plotIntersect <- function(scmpObj, min_intersection_size = 2,
msg = "'sig.genes@Summary' slot is empty, please run 'sc.get.siggenes'"
)

# Check for possible options
assert_that(package %in% c("ComplexUpset", "UpSetR"),
msg = "Please provide a valid package name for UpSet plot. Options are 'ComplexUpset' or 'UpSetR'"
)

# Check if package is installed
if (!requireNamespace(package, quietly = TRUE)) {
stop(paste0("Package '", package, "' is not installed. Please install it first."))
} else {
if (verbose) {
message(paste0("Using '", package, "' for UpSet plot."))
}
}

gene_list <- scmpObj@Significant@genes
# Create a unique list of all genes
all_genes <- unique(unlist(gene_list))

# Initialize the data frame
gene_df <- data.frame(gene = all_genes)
if (package == "UpSetR") {
# Create list object
upset_r_gene_list <- UpSetR::fromList(gene_list)

# Add columns for each pathway
for (pathway in names(gene_list)) {
gene_df[[pathway]] <- gene_df$gene %in% gene_list[[pathway]]
}
# Create Plot
p <- UpSetR::upset(
upset_r_gene_list,
main.bar.color = "#F58A53",
matrix.color = "#15918A",
line.size = 1.5,
cutoff = min_intersection_size,
empty.intersections = keep_empty_groups,
point.size = 3,
shade.color = "purple",
text.scale = 1.5,
sets.x.label = "Number of Features",
sets.bar.color = "#EE446F"
)
return(p)
} else {
# Check version of the ggplot2
if (packageVersion("ggplot2") >= "3.5.0") {
warning("Please downgrade the ggplot2 to '>= 3.5.0' to use 'ComplesUpset'. We will support the latest version in future.
Visit:'https://github.com/krassowski/complex-upset/issues/195' for more details.")
} else {
# # Create a unique list of all genes
all_genes <- unique(unlist(gene_list))

# Binarize Variables and set factors
gene_df[, -1] <- lapply(gene_df[, -1], function(x) as.integer(x))
# Initialize the data frame
gene_df <- data.frame(gene = all_genes)

# Get conesa colours
col_pal <- colorConesa(3)
# Add columns for each pathway
for (pathway in names(gene_list)) {
gene_df[[pathway]] <- gene_df$gene %in% gene_list[[pathway]]
}

if (show_sets_size) {
show_sets_size <- upset_set_size()
}
# Binarize Variables and set factors
gene_df[, -1] <- lapply(gene_df[, -1], function(x) as.integer(x))

# Get conesa colours
col_pal <- colorConesa(3)

# Create Upset
p <- upset(
data = gene_df,
intersect = colnames(gene_df)[-1],
width_ratio = width_ratio,
min_size = min_intersection_size,
keep_empty_groups = keep_empty_groups,
name = "Vars",
# wrap=FALSE,
set_sizes = show_sets_size,
# stripes=c('deepskyblue1'),
matrix = (
if (show_sets_size) {
show_sets_size <- ComplexUpset::upset_set_size()
}

intersection_matrix(
geom = geom_point(
shape = "square",
size = 3.5
# Create Upset
p <- ComplexUpset::upset(
data = gene_df,
intersect = colnames(gene_df)[-1],
width_ratio = width_ratio,
min_size = min_intersection_size,
keep_empty_groups = keep_empty_groups,
name = "Vars",
# wrap=FALSE,
set_sizes = show_sets_size,
# stripes=c('deepskyblue1'),
matrix = (

ComplexUpset::intersection_matrix(
geom = geom_point(
shape = "square",
size = 3.5
),
segment = geom_segment(
linetype = "dotted",
color = col_pal[1]
)
)
+ scale_color_manual(
values = c("TRUE" = col_pal[1], "FALSE" = col_pal[3]),
# labels=c('TRUE'='yes', 'FALSE'='no'),
breaks = c("TRUE", "FALSE")
)
),
segment = geom_segment(
linetype = "dotted",
color = col_pal[1]
)
)
+ scale_color_manual(
values = c("TRUE" = col_pal[1], "FALSE" = col_pal[3]),
# labels=c('TRUE'='yes', 'FALSE'='no'),
breaks = c("TRUE", "FALSE")
base_annotations = list(
"Intersection size" = ComplexUpset::intersection_size(
counts = TRUE,
mapping = aes(fill = "bars_color")
)
+ scale_fill_manual(values = c("bars_color" = col_pal[2]), guide = "none")
)
),
base_annotations = list(
"Intersection size" = intersection_size(
counts = TRUE,
mapping = aes(fill = "bars_color")
)
+ scale_fill_manual(values = c("bars_color" = col_pal[2]), guide = "none")
)
) + ggtitle("Intersection of features among paths") +
theme(legend.position = "none")

# return plot
return(p)
) + ggtitle("Intersection of features among paths") +
theme(legend.position = "none", legend.title = element_text(hjust = 0.5))

# Perform UpSet plot
# upset(
# fromList(gene.list),
# main.bar.color = "#F58A53",
# matrix.color = "#15918A",
# line.size = 1.5,
# point.size = 3,
# shade.color = "purple",
# text.scale = 1.5,
# sets.x.label = "Number of Features",
# sets.bar.color = "#EE446F"
# )
# return plot
return(p)
}
}
}
2 changes: 1 addition & 1 deletion R/plotTrendCluster.R
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ plotTrendCluster <- function(scmpObj,
theme(
strip.background = element_blank(),
strip.text.x = element_text(size = 10, angle = 0),
legend.position = "bottom",
legend.position = "bottom", legend.title.align = 0.5,
panel.grid.major = element_line(color = "grey90", linewidth = 0.3, linetype = "dashed"),
panel.grid.minor = element_blank(),
axis.text.x = element_text(angle = 45, hjust = 1) # Rotate x-axis text if necessary
Expand Down
Loading

0 comments on commit 37086c9

Please sign in to comment.