Skip to content

Commit

Permalink
Merge pull request #299 from stemangiola/fix-bug-reduce_dimension
Browse files Browse the repository at this point in the history
Fix bug reduce dimension
  • Loading branch information
stemangiola committed Oct 29, 2023
2 parents dd13dd6 + 078bef9 commit ffbb974
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion R/functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -2259,7 +2259,7 @@ get_reduced_dimensions_UMAP_bulk <-
of_samples = TRUE,
transform = log1p,
scale = TRUE,
calculate_for_pca_dimensions = 20,
calculate_for_pca_dimensions = min(20, top),
...) {

if(!is.null(calculate_for_pca_dimensions) & (
Expand Down
2 changes: 1 addition & 1 deletion R/functions_SE.R
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ get_reduced_dimensions_UMAP_bulk_SE <-
of_samples = TRUE,
transform = log1p,
scale = NULL, # This is only a dummy argument for making it compatibble with PCA
calculate_for_pca_dimensions = 20,
calculate_for_pca_dimensions = min(20, top),
...) {
# Comply with CRAN NOTES
. = NULL
Expand Down
11 changes: 11 additions & 0 deletions R/methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,17 @@ setGeneric("reduce_dimensions", function(.data,
col_names = get_abundance_norm_if_exists(.data, .abundance)
.abundance = col_names$.abundance

# adjust top for the max number of features I have
if(top > .data |> distinct(!!.feature) |> nrow()){
warning(sprintf(
"tidybulk says: the \"top\" argument %s is higher than the number of features %s",
top,
.data |> distinct(!!.feature) |> nrow()
))

top = min(top, .data |> distinct(!!.feature) |> nrow())
}

# Validate data frame
if(do_validate()) {
validation(.data, !!.element, !!.feature, !!.abundance)
Expand Down
11 changes: 11 additions & 0 deletions R/methods_SE.R
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,17 @@ setMethod("cluster_elements",
if(.abundance |> quo_is_symbolic()) my_assay = quo_name(.abundance)
else my_assay = get_assay_scaled_if_exists_SE(.data)

# adjust top for the max number of features I have
if(top > nrow(.data)){
warning(sprintf(
"tidybulk says: the \"top\" argument %s is higher than the number of features %s",
top,
nrow(.data)
))

top = min(top, nrow(.data))
}

my_assay =
.data %>%

Expand Down
2 changes: 1 addition & 1 deletion man/get_reduced_dimensions_UMAP_bulk.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/get_reduced_dimensions_UMAP_bulk_SE.Rd

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

0 comments on commit ffbb974

Please sign in to comment.