Skip to content
Open
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ vignettes/*.pdf
# support for build via github.com with access_token defined
.github_access_token.txt
docs
.serena/
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: gDRutils
Type: Package
Title: A package with helper functions for processing drug response data
Version: 1.11.2
Version: 1.11.3
Date: 2026-05-05
Authors@R: c(person("Bartosz", "Czech", role=c("aut"),
comment = c(ORCID = "0000-0002-9908-3007")),
Expand Down
5 changes: 4 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## gDRutils 1.11.3 - 2026-05-18
* apply updated gDRstyle rules

## gDRutils 1.11.2 - 2026-05-05
* update author email address

Expand Down Expand Up @@ -727,4 +730,4 @@
* import pipes from magrittr

## gDRutils 0.0.0.4 - 2020-06-10
* including the masked field to be able to remove the masked data from averages
* including the masked field to be able to remove the masked data from averages
24 changes: 12 additions & 12 deletions R/assay_names.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ ASSAY_INFO_TBL <- data.table::data.table(
#' will return single string instead of named vector with single element
#' useful when function is expected to return single element/assay only
#' @keywords assay_names
#'
#'
#' @return charvec
#'
#' @examples
#'
#' @examples
#' get_env_assay_names()
#'
#' @author Arkadiusz Gładki \email{arkadiusz.gladki@@contractors.roche.com}
Expand Down Expand Up @@ -66,7 +66,7 @@ get_env_assay_names <-
df <- df[df[[eval(filter)]] %in% v_filters[[filter]], ]
}

if ((nrow(df)) == 0) {
if ((NROW(df)) == 0) {
v_filters_str <-
paste(names(v_filters),
v_filters,
Expand All @@ -93,9 +93,9 @@ get_env_assay_names <-
#'
#' @return charvec
#'
#' @examples
#' @examples
#' get_assay_names()
#'
#'
#' @export
get_assay_names <- function(se = NULL, ...) {
if (!is.null(se) &&
Expand All @@ -116,9 +116,9 @@ get_assay_names <- function(se = NULL, ...) {
#' @keywords assay_names
#' @return charvec of combo assay names.
#' @export
#' @examples
#' @examples
#' get_combo_assay_names()
#'
#'
#' @author Arkadiusz Gładki \email{arkadiusz.gladki@@contractors.roche.com}
#'
get_combo_assay_names <- function(se = NULL, ...) {
Expand All @@ -134,7 +134,7 @@ get_combo_assay_names <- function(se = NULL, ...) {
#' @return charvec
#' @export
#'
#' @examples
#' @examples
#' get_combo_base_assay_names()
#' @author Arkadiusz Gładki \email{arkadiusz.gladki@@contractors.roche.com}
#'
Expand All @@ -151,10 +151,10 @@ get_combo_base_assay_names <- function(se = NULL, ...) {
#' @return charvec
#'
#' @export
#'
#' @examples
#'
#' @examples
#' get_combo_score_assay_names()
#'
#'
#' @author Arkadiusz Gładki \email{arkadiusz.gladki@@contractors.roche.com}
#'
get_combo_score_assay_names <- function(se = NULL, ...) {
Expand Down
52 changes: 26 additions & 26 deletions R/combo.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
#' @param se \code{SummarizedExperiment} object with dose-response data
#' @param c_assays charvec of combo assays to be used
#' @param normalization_type charvec of normalization_types expected in the data
#' @param prettify boolean flag indicating whether or not to prettify the colnames of the returned data
#' @param prettify boolean flag indicating whether or not to prettify the colnames of the returned data
#' @keywords combination_data
#'
#'
#' @author Arkadiusz Gładki \email{arkadiusz.gladki@@contractors.roche.com}
#'
#' @return list of data.table(s) with combo data
#'
#' @examples
#' @examples
#' mae <- get_synthetic_data("finalMAE_combo_matrix_small.qs2")
#' convert_combo_data_to_dt(mae[[1]])
#'
Expand Down Expand Up @@ -38,7 +38,7 @@ convert_combo_data_to_dt <-
}
dt
})

# TODO: discuss what should be returned: assay_name or maybe assay_type?
names(my_l) <- as.character(c_assays)
my_l
Expand All @@ -60,10 +60,10 @@ DATA_COMBO_INFO_TBL <- data.table::data.table(
#' @return charvec
#'
#' @export
#'
#' @examples
#'
#' @examples
#' get_combo_score_assay_names()
#'
#'
get_combo_score_field_names <- function() {
dt <- DATA_COMBO_INFO_TBL[type == "scores", c("name", "pname"), with = FALSE]
stats::setNames(dt$pname, dt$name)
Expand All @@ -75,10 +75,10 @@ get_combo_score_field_names <- function() {
#' @return charvec
#'
#' @export
#'
#' @examples
#'
#' @examples
#' get_combo_excess_field_names()
#'
#'
get_combo_excess_field_names <- function() {
dt <- DATA_COMBO_INFO_TBL[type == "excess", c("name", "pname"), with = FALSE]
stats::setNames(dt$pname, dt$name)
Expand All @@ -93,10 +93,10 @@ get_combo_excess_field_names <- function() {
#' @return charvec
#'
#' @export
#'
#' @examples
#'
#' @examples
#' convert_combo_field_to_assay("hsa_score")
#'
#'
convert_combo_field_to_assay <- function(field) {
checkmate::assert_string(field)
DATA_COMBO_INFO_TBL[name == field, ][["type"]]
Expand All @@ -111,26 +111,26 @@ convert_combo_field_to_assay <- function(field) {
#' @details
#' \code{drug_1} is diluted along the rows as the y-axis and
#' \code{drug_2} is diluted along the columns and will be the x-axis.
#'
#'
#' @keywords combination_data
#' @return list with axis grid positions
#'
#'
#' @examples
#' cl_name <- "cellline_BC"
#' drug1_name <- "drug_001"
#' drug2_name <- "drug_026"
#'
#'
#' se <- get_synthetic_data("combo_matrix_small")[["combination"]]
#' dt_average <- convert_se_assay_to_dt(se, "Averaged")[normalization_type == "GR"]
#'
#'
#' ls_axes <- define_matrix_grid_positions(
#' dt_average[["Concentration"]], dt_average[["Concentration_2"]])
#'
#'
#' @export
define_matrix_grid_positions <- function(conc1, conc2) {
checkmate::assert_numeric(conc1)
checkmate::assert_numeric(conc2)

.generate_gap_for_single_agent <- function(x) {
if (NROW(x) == 1) {
x
Expand All @@ -139,8 +139,8 @@ define_matrix_grid_positions <- function(conc1, conc2) {
} else {
x[2] - 0.5 # diff(log10(c(0, 10^(seq(-3, 1, 0.5))))) # nolint
}
}
}

conc_1 <- sort(unique(round_concentration(conc1)))
pos_y <- log10conc_1 <- log10(conc_1)
pos_y[1] <- .generate_gap_for_single_agent(log10conc_1)
Expand All @@ -149,7 +149,7 @@ define_matrix_grid_positions <- function(conc1, conc2) {
pos_y = pos_y,
marks_y = sprintf("%.2g", conc_1)
)

conc_2 <- sort(unique(round_concentration(conc2)))
pos_x <- log10conc_2 <- log10(conc_2)
pos_x[1] <- .generate_gap_for_single_agent(log10conc_2)
Expand All @@ -158,16 +158,16 @@ define_matrix_grid_positions <- function(conc1, conc2) {
pos_x = pos_x,
marks_x = sprintf("%.2g", conc_2)
)

list(axis_1 = axis_1, axis_2 = axis_2)
}

#' Round concentration to ndigit significant digits
#'
#' @param x value to be rounded.
#' @param ndigit number of significant digits (default = 4).
#'
#' @examples
#'
#' @examples
#' round_concentration(x = c(0.00175,0.00324,0.0091), ndigit = 1)
#'
#' @return rounded x
Expand All @@ -176,6 +176,6 @@ define_matrix_grid_positions <- function(conc1, conc2) {
round_concentration <- function(x, ndigit = 3) {
checkmate::assert_numeric(x)
checkmate::assert_integerish(ndigit)

round(10 ^ (round(log10(x), ndigit)), ndigit - 1 - floor(log10(x)))
}
32 changes: 16 additions & 16 deletions R/concatentate_SEs.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ has_nested_field <- function(asy, nested_field) {
#'
#' @seealso promote_fields
#' @details Revert this operation using \code{promote_fields}.
#'
#' @examples
#'
#' @examples
#' mae <- get_synthetic_data("finalMAE_small.qs2")
#' se <- mae[[1]]
#' se <- promote_fields(se, "ReadoutValue", 2)
#' demote_fields(se, "ReadoutValue")
#'
#'
#' @export
demote_fields <- function(se, fields) {
checkmate::assertClass(se, "SummarizedExperiment")
Expand All @@ -48,7 +48,7 @@ demote_fields <- function(se, fields) {

if (any(are_nested_fields <- !fields %in% c(rowmd, colmd))) {
stop(sprintf("field(s) '%s' are already demoted fields, perhapy you intended to call 'promote_fields'?",
paste0(fields[are_nested_fields], collapse = ", ")))
toString(fields[are_nested_fields])))
}

rowmd <- setdiff(rowmd, fields)
Expand Down Expand Up @@ -94,26 +94,26 @@ demote_fields <- function(se, fields) {
#' @return A \code{SummarizedExperiment} object with new dimensions resulting from promoting given \code{fields}.
#' @details Revert this operation using \code{demote_fields}.
#' @seealso demote_fields
#'
#' @examples
#'
#' @examples
#' mae <- get_synthetic_data("finalMAE_small.qs2")
#' se <- mae[[1]]
#' se <- promote_fields(se, "ReadoutValue", 2)
#'
#'
#' @export
promote_fields <- function(se, fields, MARGIN = c(1, 2)) {
checkmate::assertClass(se, "SummarizedExperiment")
checkmate::assertCharacter(fields)
if (length(MARGIN) != 1L || !MARGIN %in% c(1, 2)) {
stop("invalid 'MARGIN' argument, must be either '1' or '2'")
}
rowmd <- colnames(rowData(se))
rowmd <- colnames(rowData(se))
colmd <- colnames(colData(se))
rowmd <- colnames(rowData(se))
colmd <- colnames(colData(se))
if (any(rfields <- fields %in% rowmd) || any(cfields <- fields %in% colmd)) {
stop(sprintf("fields '%s' are already promoted fields",
paste0(fields[rfields || cfields], collapse = ", ")))
toString(fields[rfields || cfields])))
}
if (MARGIN == 1) {
rowmd <- c(rowmd, fields)
Expand All @@ -139,7 +139,7 @@ promote_fields <- function(se, fields, MARGIN = c(1, 2)) {
}
if (length(final_assays) == 0L) {
stop(sprintf("unable to find nested fields: '%s' in any assays, perhaps you intended to call 'demote_fields'?",
paste0(fields, collapse = ", ")))
toString(fields)))
}
.validate_final_assays(final_assays)
assay_list <- lapply(final_assays, function(x) {
Expand Down Expand Up @@ -184,7 +184,7 @@ promote_fields <- function(se, fields, MARGIN = c(1, 2)) {
missing <- setdiff(colnames(df), c(row_fields, column_fields, nested_fields))
if (length(missing) != 0L) {
stop(sprintf("found columns in 'df' not specified as row, column, or nested fields",
paste0(missing, collapse = ", ")))
toString(missing)))
}
if (any(is_duplicated <- duplicated(c(row_fields, column_fields, nested_fields)))) {
stop(sprintf("fields: '%s' are duplicated across arguments 'row_fields', 'column_fields', 'nested_fields'",
Expand Down Expand Up @@ -216,13 +216,13 @@ promote_fields <- function(se, fields, MARGIN = c(1, 2)) {
#' @keywords SE_operators
#'
#' @return A \code{BumpyMatrix} object aggregated by \code{FUN}.
#'
#' @examples
#' mae <- get_synthetic_data("finalMAE_small.qs2")
#'
#' @examples
#' mae <- get_synthetic_data("finalMAE_small.qs2")
#' se <- mae[[1]]
#' assay <- SummarizedExperiment::assay(se)
#' aggregate_assay(assay, FUN = mean, by = c("Barcode"))
#'
#'
#' @export
aggregate_assay <- function(asy, by, FUN) {
checkmate::assert_class(asy, "BumpyMatrix")
Expand All @@ -238,7 +238,7 @@ aggregate_assay <- function(asy, by, FUN) {
row.field = row.field,
column.field = column.field)
if (!all(present <- by %in% setdiff(colnames(df), c(row.field, column.field)))) {
stop(sprintf("specified 'by' columns: '%s' are not present in 'asy'", paste0(by[!present], collapse = ", ")))
stop(sprintf("specified 'by' columns: '%s' are not present in 'asy'", toString(by[!present])))
}

by <- c(row.field, column.field, by)
Expand Down
Loading
Loading