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

Update confounders and filtering #318

Merged
merged 2 commits into from
Dec 13, 2024
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
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,15 @@ importFrom(rlang,enquo)
importFrom(rlang,enquos)
importFrom(rlang,flatten_if)
importFrom(rlang,inform)
importFrom(rlang,is_quosure)
importFrom(rlang,is_spliced)
importFrom(rlang,quo)
importFrom(rlang,quo_is_missing)
importFrom(rlang,quo_is_null)
importFrom(rlang,quo_is_symbol)
importFrom(rlang,quo_is_symbolic)
importFrom(rlang,quo_name)
importFrom(rlang,quo_set_env)
importFrom(rlang,quo_squash)
importFrom(rlang,set_names)
importFrom(scales,extended_breaks)
Expand Down
22 changes: 14 additions & 8 deletions R/methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -477,10 +477,10 @@ setGeneric("scale_abundance", function(.data,

# Attach column internals
add_tt_columns(
!!.sample,
!!.transcript,
!!.abundance,
!!(function(x, v) enquo(v))(x,!!value_scaled)
!!(.sample |> drop_enquo_env()),
!!(.transcript |> drop_enquo_env()),
!!(.abundance |> drop_enquo_env()),
!!(((function(x, v) enquo(v))(x,!!value_scaled)) |> drop_enquo_env())
)


Expand Down Expand Up @@ -698,10 +698,10 @@ setGeneric("quantile_normalise_abundance", function(.data,

# Attach column internals
add_tt_columns(
!!.sample,
!!.transcript,
!!.abundance,
!!(function(x, v) enquo(v))(x,!!value_scaled)
!!(.sample |> drop_enquo_env()),
!!(.transcript |> drop_enquo_env()),
!!(.abundance |> drop_enquo_env()),
!!(((function(x, v) enquo(v))(x,!!value_scaled)) |> drop_enquo_env())
)


Expand Down Expand Up @@ -3132,6 +3132,7 @@ setGeneric("identify_abundant", function(.data,
.transcript = NULL,
.abundance = NULL,
factor_of_interest = NULL,
design = NULL,
minimum_counts = 10,
minimum_proportion = 0.7)
standardGeneric("identify_abundant"))
Expand All @@ -3142,6 +3143,7 @@ setGeneric("identify_abundant", function(.data,
.transcript = NULL,
.abundance = NULL,
factor_of_interest = NULL,
design = NULL,
minimum_counts = 10,
minimum_proportion = 0.7)
{
Expand Down Expand Up @@ -3250,6 +3252,7 @@ setGeneric("identify_abundant", function(.data,
edgeR::filterByExpr(
min.count = minimum_counts,
group = string_factor_of_interest,
design = design,
min.prop = minimum_proportion
) %>%
not() |>
Expand Down Expand Up @@ -3345,6 +3348,7 @@ setGeneric("keep_abundant", function(.data,
.transcript = NULL,
.abundance = NULL,
factor_of_interest = NULL,
design = NULL,
minimum_counts = 10,
minimum_proportion = 0.7)
standardGeneric("keep_abundant"))
Expand All @@ -3355,6 +3359,7 @@ setGeneric("keep_abundant", function(.data,
.transcript = NULL,
.abundance = NULL,
factor_of_interest = NULL,
design = NULL,
minimum_counts = 10,
minimum_proportion = 0.7)
{
Expand Down Expand Up @@ -3387,6 +3392,7 @@ setGeneric("keep_abundant", function(.data,
.transcript = !!.transcript,
.abundance = !!.abundance,
factor_of_interest = !!factor_of_interest,
design = design,
minimum_counts = minimum_counts,
minimum_proportion = minimum_proportion
) |>
Expand Down
25 changes: 14 additions & 11 deletions R/methods_SE.R
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ setMethod("tidybulk", "RangedSummarizedExperiment", .tidybulk_se)
memorise_methods_used(c("edger", "tmm")) %>%

# Attach column internals
add_tt_columns(.abundance_scaled = !!(function(x, v) enquo(v))(x,!!as.symbol(value_scaled)))
add_tt_columns(.abundance_scaled = !!(((function(x, v) enquo(v))(x,!!as.symbol(value_scaled))) |> drop_enquo_env()) )

}

Expand Down Expand Up @@ -321,7 +321,7 @@ setMethod("scale_abundance",
memorise_methods_used(c("quantile")) %>%

# Attach column internals
add_tt_columns(.abundance_scaled = !!(function(x, v) enquo(v))(x,!!as.symbol(value_scaled)))
add_tt_columns(.abundance_scaled = !!(((function(x, v) enquo(v))(x,!!as.symbol(value_scaled))) |> drop_enquo_env()) )

}

Expand Down Expand Up @@ -953,8 +953,7 @@ setMethod("remove_redundancy",
memorise_methods_used("sva") %>%

# Attach column internals
add_tt_columns(.abundance_adjusted = !!(function(x, v)
enquo(v))(x, !!as.symbol(value_adjusted)))
add_tt_columns(.abundance_adjusted = !!(((function(x, v) enquo(v))(x,!!as.symbol(value_adjusted))) |> drop_enquo_env()) )

}

Expand Down Expand Up @@ -1573,6 +1572,7 @@ setMethod("keep_variable",
.transcript = NULL,
.abundance = NULL,
factor_of_interest = NULL,
design = NULL,
minimum_counts = 10,
minimum_proportion = 0.7)
{
Expand Down Expand Up @@ -1680,6 +1680,7 @@ setMethod("keep_variable",
edgeR::filterByExpr(
min.count = minimum_counts,
group = string_factor_of_interest,
design = design,
min.prop = minimum_proportion,
lib.size = Matrix::colSums(., na.rm=TRUE)
) %>%
Expand Down Expand Up @@ -1727,6 +1728,7 @@ setMethod("identify_abundant",
.transcript = NULL,
.abundance = NULL,
factor_of_interest = NULL,
design = NULL,
minimum_counts = 10,
minimum_proportion = 0.7)
{
Expand All @@ -1746,7 +1748,8 @@ setMethod("identify_abundant",
factor_of_interest = !!factor_of_interest,
minimum_counts = minimum_counts,
minimum_proportion = minimum_proportion,
.abundance = !!.abundance
.abundance = !!.abundance,
design = design
)

.data[rowData(.data)$.abundant,]
Expand Down Expand Up @@ -2819,14 +2822,14 @@ setMethod("describe_transcript", "RangedSummarizedExperiment", .describe_transcr
#' @importFrom SummarizedExperiment as.data.frame
.resolve_complete_confounders_of_non_interest <- function(se, ...){

colData(se) =
colData(se) |>
as.data.frame() |>
.resolve_complete_confounders_of_non_interest_df(...) |>
colData(se) =
colData(se) |>
as.data.frame() |>
.resolve_complete_confounders_of_non_interest_df(...) |>
DataFrame()

se

}

#' resolve_complete_confounders_of_non_interest
Expand Down
28 changes: 28 additions & 0 deletions R/utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -1514,3 +1514,31 @@ check_and_install_packages <- function(packages) {
)
}
}

#' Drop Environment from a Quosure
#'
#' Takes a quosure and resets its environment to `emptyenv()` without altering
#' its expression.
#'
#' @param q A quosure object to have its environment stripped.
#' @return A quosure with the same expression but environment set to `emptyenv()`.
#'
#' @importFrom rlang is_quosure
#' @importFrom rlang quo_set_env
#'
#' @examples
#' library(rlang)
#'
#' q <- quo(x + y)
#' environment(q)
#'
#' q_stripped <- drop_enquo_env(q)
#' identical(quo_get_env(q_stripped), emptyenv()) # TRUE
#'
#' @noRd
drop_enquo_env <- function(q) {
if (!rlang::is_quosure(q)) {
stop("`q` must be a quosure.")
}
rlang::quo_set_env(q, emptyenv())
}
6 changes: 6 additions & 0 deletions man/identify_abundant-methods.Rd

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

6 changes: 6 additions & 0 deletions man/keep_abundant-methods.Rd

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

14 changes: 7 additions & 7 deletions man/resolve_complete_confounders_of_non_interest.Rd

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

Loading