Skip to content

Commit

Permalink
account for lots of labels
Browse files Browse the repository at this point in the history
  • Loading branch information
jashapiro committed Nov 19, 2024
1 parent b9c46bb commit 5188bfe
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion modules/simulate-sce/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ This workflow is designed to simulate single cell data, primarily using the [spl

Scripts are derived from the the `simulate-sce` module of the [OpenScPCA-analysis](https://github.com/AlexsLemonade/OpenScPCA-analysis) repository.

Permalink to the version used: https://github.com/AlexsLemonade/OpenScPCA-analysis/tree/0c105e1a482dc045478e88339633999ba9982f1c/analyses/simulate-sce
Permalink to the version used: https://github.com/AlexsLemonade/OpenScPCA-analysis/tree/714282f90979400528a213b11ea71718bdd3527c/analyses/simulate-sce
8 changes: 3 additions & 5 deletions modules/simulate-sce/resources/usr/bin/simulate-sce.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ suppressPackageStartupMessages({
#' Randomize labels
#'
#' A function to randomly select labels from a set,
#' while ensuring each label is included at least once.
#' while ensuring each label is included at least once, if possible.
#'
#' @param label_set a vector a labels
#' @param n the number of labels to select
Expand All @@ -70,16 +70,14 @@ suppressPackageStartupMessages({
#'
#' @examples
random_label <- function(label_set, n) {
# randomly select n labels from the label set, ensuring each label is included at least once

# ensure labels are unique
label_set <- unique(label_set)
if (length(label_set) > n) {
stop("The number of labels must not be greater than the number requested.")
warning("The number of labels is greater than the number requested; not all labels will be used.")
}
r_labels <- sample(label_set, n, replace = TRUE)
# add each label at least once
idx <- sample.int(n, length(label_set))
idx <- sample.int(n, min(n, length(label_set)))
r_labels[idx] <- label_set
return(r_labels)
}
Expand Down

0 comments on commit 5188bfe

Please sign in to comment.