Skip to content

Commit

Permalink
Merge pull request #3 from FridleyLab/dev
Browse files Browse the repository at this point in the history
CRAN submission
  • Loading branch information
ACSoupir authored Oct 5, 2023
2 parents fdb5e3c + 2e13536 commit 4e623f0
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 19 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: scSpatialSIM
Title: A point pattern simulator for spatial cellular data
Version: 0.1.3.0
Version: 0.1.3.1
Authors@R:
c(
person(given = "Alex",
Expand Down
28 changes: 21 additions & 7 deletions R/create_cells.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
#' @param ymax A numeric value specifying the maximum y value for the kernel.
#' @param sdmin A numeric value specifying the minimum standard deviation for the kernel.
#' @param sdmax A numeric value specifying the maximum standard deviation for the kernel.
#' @param probs A numeric vector of length 2 specifying the minimum and maximum probability values for scaling the kernel values.
#' @param probs Either a vector of c(low probability, high probability) for all cell types or data frame where each row
#' is the low and high probabilities for the cell type. If data frame, number of rows must equal number of cells
#' @param Force A logical value indicating whether to force simulation parameters to be within the simulation window limits.
#' @param density_heatmap A logical value indicating whether to compute a density heatmap for each cell.
#' @param step_size A numeric value specifying the step size for the grid of points within the window.
Expand Down Expand Up @@ -40,6 +41,10 @@ GenerateCellPositivity = function(sim_object, k = NA,
if(any(is.null(c(k, xmin, xmax, ymin, ymax, sdmin, sdmax)))) stop("Cannot have `NULL` parameters")

if(!is.empty(sim_object@Cells[[1]], "Simulated Kernels") & overwrite == FALSE) stop("Already have cell kernels and `overwrite == FALSE`")

ncells = length(sim_object@Cells)
if(methods::is(probs, "data.frame"))
if(nrow(probs) != ncells) stop("`probs` should either be data.frame with nrow length of Cells or a vector of length 2")
if(!is.empty(sim_object@Cells[[1]], "Simulated Kernels") & overwrite == TRUE){
message("Overwriting existing cell kernels")
# #tissue
Expand Down Expand Up @@ -72,16 +77,25 @@ GenerateCellPositivity = function(sim_object, k = NA,
}

#create parameter vector
params = list(k = k,
xmin = xmin, xmax = xmax,
ymin = ymin, ymax = ymax,
sdmin = sdmin, sdmax = sdmax,
probs = probs)
ncells = length(sim_object@Cells)
if(methods::is(probs, "vector")){
probs2 = data.frame(matrix(rep(probs, ncells), nrow = ncells, byrow = TRUE)) %>% stats::setNames(c("Low", "High"))
} else {
probs2 = probs
}

params_overall = list(k = k,
xmin = xmin, xmax = xmax,
ymin = ymin, ymax = ymax,
sdmin = sdmin, sdmax = sdmax,
probs = probs2)

#make sure that the shift is in bounds
if((shift < 0 | shift > 1) & ncells > 1) stop("supply an appropriate shift")
#dummy variable to prevent console printing
dmb = lapply(seq(ncells), function(cell){
#subset the params to the specific cells parameters
params = params_overall
params$probs = params$probs[cell,] %>% as.numeric()
#if no parameters are input then use the initialized
params = mapply(replace_na, sim_object@Cells[[cell]]@Parameters, params, SIMPLIFY = FALSE)
#add updated parameters to the object cell
Expand Down
8 changes: 7 additions & 1 deletion R/utils-helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,13 @@ gaussian_kernel_shift = function(kern, shift, win_limits){
do.call(dplyr::bind_rows, .) %>%
dplyr::distinct()
#sample them to kern rows
dirichlet_intersect = dirichlet_intersect[sample(seq(nrow(dirichlet_intersect)), nrow(kern)),]
repl = ifelse(nrow(dirichlet_intersect) < nrow(kern), TRUE, FALSE)
if(repl){
warning("kernel has more rows than the Dirishlet Intersections")
print(kern)
}
dirichlet_intersect = dirichlet_intersect[sample(seq(nrow(dirichlet_intersect)), nrow(kern),
replace = ifelse(nrow(dirichlet_intersect) < nrow(kern), TRUE, FALSE)),]
#find nearest real points
distance_matrix = proxy::dist(x = kern[,1:2], y = dirichlet_intersect)
#get minimum distance
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ To install `scSpatialSIM`, it is required to have `devtools` or `remotes` instal
if (!require("devtools", quietly = TRUE))
install.packages("devtools")
devtools::install_github("FridleyLab/scSpatialSIM@v0.1.1.0")
devtools::install_github("FridleyLab/mIFsim@v0.1.3.1")
```

# Vignettes
Expand Down
2 changes: 1 addition & 1 deletion docs/404.html

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

2 changes: 1 addition & 1 deletion docs/LICENSE-text.html

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

2 changes: 1 addition & 1 deletion docs/LICENSE.html

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

6 changes: 3 additions & 3 deletions docs/authors.html

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

4 changes: 2 additions & 2 deletions docs/index.html

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

3 changes: 2 additions & 1 deletion man/GenerateCellPositivity.Rd

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

0 comments on commit 4e623f0

Please sign in to comment.