Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion R/CalculatePercentage.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#' Calculate the percentage of cells in activation status
#' CalculatePercentage
#'
#' This function calculates the percentage of cells in ON (scale > 0) and OFF (scale < 0)
#' activation states within each group defined by `group_var`. If exactly two groups
#' are provided, it also computes Cohen's d effect size between their activation values.
#'
#' @name CalculatePercentage
#' @importFrom dplyr bind_rows
#' @importFrom effsize cohen.d
#' @importFrom stats na.omit
#' @param to.plot A data frame containing at least a `scale` column and a grouping column.
#' @param group_var A string specifying the grouping variable (e.g., "genotype", "treatment").
#'
#' @return A data frame with the percentage of ON/OFF cells and Cohen's d (if applicable).
#' @examples
#' data(fake_to_plot)
Expand Down
17 changes: 16 additions & 1 deletion R/ComputeCellData.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#' ComputeCellData
#'
#' A function computes cell status for a given pathway in single-cell RNA-seq data,
#' based on the distance between genes in a specified pathway. The distance is computed
#' for each batch of cells, and classical multidimensional scaling (MDS) is used to
Expand All @@ -14,7 +16,7 @@
#'
#' @param x A `Seurat` object containing single-cell RNA sequencing data.
#' @param pathway A `character` string specifying the pathway name. This should match a pathway used by `LoadPathway()`.
#' @param distance.method A `character` string specifying the distance metric to use.
#' @param distance.method A `character` string specifying the distance metric to use.Default is "manhattan".
#' Options include: `"manhattan"`, `"euclidean"`, `"canberra"`, `"binary"`, `"minkowski"`
#' @param batch.size An `integer` specifying the number of cells to process per batch. Default is 1000.
#' @param scale.data A `logical` indicating whether to use scaled data (`scale.data = TRUE`) or normalized data. Default is `TRUE`.
Expand Down Expand Up @@ -53,8 +55,15 @@ ComputeCellData <- function(x, pathway, distance.method, batch.size = batch.size
shuffled_cell_id <- sample(cell_id)

# Split shuffled indices into batches
# Check if batch.size is provided; if not, set default and message
if (missing(batch.size) || is.null(batch.size)) {
message("Parameter 'batch.size' is missing or NULL. Setting default batch size to 1000.")
batch.size <- 1000
}

# Define batch size
batch_size <- batch.size

batches <- split(shuffled_cell_id, ceiling(seq_along(shuffled_cell_id) / batch.size))

# Subset expression data into chunks based on sampled indices
Expand Down Expand Up @@ -82,6 +91,12 @@ ComputeCellData <- function(x, pathway, distance.method, batch.size = batch.size
next
}

# Check if distance.method is provided; if not, set default and message
if (missing(distance.method) || is.null(distance.method)) {
message("Parameter 'distance.method' is missing or NULL. Setting default distance.method to 'manhattan'.")
distance.method <- "manhattan"
}

# Distance calculation
message("Computing distance...")
d <- dist(t(pathwaytempdata), method = distance.method)
Expand Down
3 changes: 2 additions & 1 deletion R/LoadPathway.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Pathway Data Extraction from Exceldataset
#' LoadPathway
#'
#' This function reads pathway data from the package's built-in Excel file.
#'
#' @name LoadPathway
#' @param pathway A `character` string specifying the pathway name.
#' @return A data frame with pathway data.
Expand Down
3 changes: 3 additions & 0 deletions R/PathwayMaxMin.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#' PathwayMaxMin
#'
#' A function to obtain the hypothetical max and min activation status of selected pathway for a given scRNA seq data set
#'
#' @name PathwayMaxMin
#' @import Seurat
#' @import tidyverse
Expand Down
2 changes: 2 additions & 0 deletions R/PlotPathway.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#' PlotPathway
#'
#' A function to plot the Pathway activation status
#'
#' @name PlotPathway
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ library(PathwayEmbed)
data(fake_test_object)

# Compute pathway data
mds_results <- ComputeCellData(fake_test_object, pathway = "Wnt", distance.method = "manhattan")
mds_results <- ComputeCellData(fake_test_object, pathway = "Wnt", distance.method = "manhattan", batch.size = 100) need to add a default batch size and a end message

# Prepare data for plotting
plot_data <- PreparePlotData(fake_test_object, mds_results, group = "genotype")
Expand Down
Binary file modified inst/extdata/Pathway_Embedding.xlsx
Binary file not shown.
2 changes: 1 addition & 1 deletion man/CalculatePercentage.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions man/ComputeCellData.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/LoadPathway.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/PathwayMaxMin.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/PlotPathway.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.