Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #250

Merged
merged 1 commit into from
Jul 23, 2022
Merged

fixes #250

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
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ importFrom(purrr,as_mapper)
importFrom(purrr,map)
importFrom(purrr,map2)
importFrom(purrr,map2_dfr)
importFrom(purrr,map_chr)
importFrom(purrr,map_dfr)
importFrom(purrr,map_lgl)
importFrom(purrr,reduce)
Expand Down
30 changes: 19 additions & 11 deletions R/methods_SE.R
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ setMethod("aggregate_duplicates",



#' @importFrom rlang quo_is_symbol
#' @importFrom rlang quo_is_symbolic
.deconvolve_cellularity_se = function(.data,
reference = X_cibersort,
method = "cibersort",
Expand All @@ -944,7 +944,7 @@ setMethod("aggregate_duplicates",
.[[get_assay_scaled_if_exists_SE(.data)]] %>%

# Change row names
when(quo_is_symbol(.transcript) ~ {
when(quo_is_symbolic(.transcript) ~ {
.x = (.)
rownames(.x) = .data %>% pivot_transcript() %>% pull(!!.transcript)
.x
Expand Down Expand Up @@ -1294,6 +1294,8 @@ setMethod("keep_variable",
#' keep_variable
#' @inheritParams keep_variable
#'
#' @importFrom purrr map_chr
#'
#' @docType methods
#' @rdname keep_variable-methods
#'
Expand All @@ -1319,10 +1321,10 @@ setMethod("keep_variable",
# Check factor_of_interest
if(
!is.null(factor_of_interest) &&
quo_is_symbol(factor_of_interest) &&
(quo_name(factor_of_interest) %in% colnames(colData(.data)) %>% not())
quo_is_symbolic(factor_of_interest) &&
(quo_names(factor_of_interest) %in% colnames(colData(.data)) |> all() %>% not())
)
stop(sprintf("tidybulk says: the column %s is not present in colData", quo_name(factor_of_interest)))
stop(sprintf("tidybulk says: the column %s is not present in colData", quo_names(factor_of_interest)))

if (minimum_counts < 0)
stop("The parameter minimum_counts must be > 0")
Expand All @@ -1343,16 +1345,22 @@ setMethod("keep_variable",

factor_of_interest %>%
when(
quo_is_symbol(factor_of_interest) &&
quo_is_symbolic(factor_of_interest) &&
(
colData(.data)[, quo_name(factor_of_interest)] %>%
class %in% c("numeric", "integer", "double")) ~
colData(.data)[, quo_names(factor_of_interest), drop=FALSE] |>
as_tibble() |>
map_chr(~class(.x)) %in% c("numeric", "integer", "double") |>
any()
) ~
{
message("tidybulk says: The factor of interest is continuous (e.g., integer,numeric, double). The data will be filtered without grouping.")
message("tidybulk says: The factor(s) of interest include continuous variable (e.g., integer,numeric, double). The data will be filtered without grouping.")
NULL
},
quo_is_symbol(factor_of_interest) ~
colData(.data)[, quo_name(factor_of_interest)],
quo_is_symbolic(factor_of_interest) ~
colData(.data)[, quo_names(factor_of_interest), drop=FALSE] |>
as_tibble() |>
unite("factor_of_interest") |>
pull(factor_of_interest),
~ NULL
)

Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-bulk_methods_SummarizedExperiment.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ data("se_mini")
data("breast_tcga_mini_SE")

input_df = setNames(se_mini %>% tidybulk() %>% as_tibble(), c( "b","a", "c", "Cell type", "time" , "condition", "days", "dead", "entrez"))

input_df_breast = setNames( breast_tcga_mini_SE %>% tidybulk() %>% as_tibble(), c( "b", "a","c", "c norm", "call" ))

test_that("tidybulk SummarizedExperiment conversion",{
Expand Down