Skip to content

Commit

Permalink
Fix: layout indeed can be longer the samples (#109)
Browse files Browse the repository at this point in the history
* Fix: layout indeed can be longer the samples

* Update docs
  • Loading branch information
ZetrextJG authored Aug 30, 2024
1 parent 08c223c commit 0d075fb
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 deletions.
1 change: 1 addition & 0 deletions R/classes-model.R
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ create_standard_curve_model_analyte <- function(plate, analyte_name, data_type =

mfi_source <- ifelse(source_mfi_range_from_all_analytes, "ALL", analyte_name)


mfi_min <- min(plate$get_data(mfi_source, "STANDARD CURVE", data_type = data_type), na.rm = TRUE)
mfi_max <- max(plate$get_data(mfi_source, "STANDARD CURVE", data_type = data_type), na.rm = TRUE)

Expand Down
16 changes: 10 additions & 6 deletions R/classes-plate_builder.R
Original file line number Diff line number Diff line change
Expand Up @@ -433,13 +433,14 @@ convert_dilutions_to_numeric <- function(dilutions) {
#'
#' Otherwise, the returned SampleType is `TEST`
#'
#' @param sample_names (`character`)\cr
#' @param sample_names (`character()`)\cr
#' Vector of sample names from Luminex file
#'
#' @param sample_names_from_layout (`character`)\cr
#' @param sample_names_from_layout (`character()`)\cr
#' Vector of sample names from Layout file
#' values in this vector may be different than `sample_names` and may
#' contain additional information about the sample type like dilution
#' contain additional information about the sample type like dilution.
#' This vector when set has to have at least the length of `sample_names`.
#'
#' @return A vector of valid sample_type strings of length equal to the length of `sample_names`
#'
Expand All @@ -448,12 +449,15 @@ convert_dilutions_to_numeric <- function(dilutions) {
#' translate_sample_names_to_sample_types(c("S", "CP3"))
#'
#' @export
translate_sample_names_to_sample_types <- function(sample_names, sample_names_from_layout = "") {
translate_sample_names_to_sample_types <- function(sample_names, sample_names_from_layout = NULL) {
stopifnot(is.character(sample_names))
# Handle case when sample name from layout is not provided
# Ensure sample_names_from_layout is a character vector of the same length as sample_names
if (length(sample_names_from_layout) != length(sample_names)) {
if (is.null(sample_names_from_layout)) {
sample_names_from_layout <- rep("", length(sample_names))
}
# Ensure sample_names_from_layout is a character vector at least as long as sample_names
stopifnot(length(sample_names) <= length(sample_names_from_layout))

# Initialize the result vector
sample_types <- vector("character", length(sample_names))
# Iterate over each sample
Expand Down
1 change: 0 additions & 1 deletion R/parser.R
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ read_luminex_data <- function(plate_filepath,
plate_builder$set_dilutions(use_layout_dilutions, dilutions)



plate <- plate_builder$build(validate = TRUE)

verbose_cat(color_codes$green_start, "\nNew plate object has been created with name: ",
Expand Down
9 changes: 5 additions & 4 deletions man/translate_sample_names_to_sample_types.Rd

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

18 changes: 10 additions & 8 deletions tests/testthat/test-plate_builder.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ test_that("Sample type is correctly identified as POSITIVE CONTROL", {
)
})

test_that("Test translating samples with only proportions", {
expect_equal(
translate_sample_names_to_sample_types(
c("BLANK", "1/50", "1/100", "1/1000"),
c("BLANK", "1/50", "1/100", "1/1000")
),
c("BLANK", "STANDARD CURVE", "STANDARD CURVE", "STANDARD CURVE")
)
})

test_that("Sample type defaults to TEST when no special conditions are met", {
expect_equal(
translate_sample_names_to_sample_types(
Expand All @@ -88,14 +98,6 @@ test_that("Handling of missing layout names", {
),
c("BLANK", "STANDARD CURVE", "POSITIVE CONTROL", "NEGATIVE CONTROL")
)

expect_equal(
translate_sample_names_to_sample_types(
c("BLANK", "S", "POS 1/10", "NEGATIVE CONTROL"),
NA
),
c("BLANK", "STANDARD CURVE", "POSITIVE CONTROL", "NEGATIVE CONTROL")
)
})

test_that("Handling of empty layout names", {
Expand Down

0 comments on commit 0d075fb

Please sign in to comment.