-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Hefin Rhys
committed
Apr 3, 2024
1 parent
7b38b3f
commit ee6ff94
Showing
23 changed files
with
314 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
lapply(names(fits), function(x) { | ||
|
||
lloq <- dplyr::filter( | ||
u5plex@summary_data, | ||
Analyte == x, | ||
Type == "Standard", | ||
Result_CV <= 0.2, | ||
Result_Avg / Expected > 0.8, | ||
Result_Avg / Expected < 1.2 | ||
) |> | ||
dplyr::pull(Expected) |> | ||
min() | ||
|
||
blank <- dplyr::filter( | ||
u5plex@well_data, | ||
Analyte == x, | ||
Type == "Standard", | ||
Expected == 0 | ||
) |> | ||
dplyr::pull(MFI) | ||
|
||
blank_targets <- | ||
(mean(blank) + 2.5*sd(blank)) / | ||
max(dplyr::filter(u5plex@well_data, Analyte == x)$MFI) | ||
|
||
suppressWarnings({ | ||
suppressMessages({ | ||
mdd <- nplr::getEstimates( | ||
fits[[x]], | ||
targets = blank_targets | ||
)$x | ||
}) | ||
}) | ||
|
||
df_low <- data.frame( | ||
x = 10^(fits[[x]]@x), | ||
y = fits[[x]]@y | ||
)[10^(fits[[x]]@x) %in% unique(10^(fits[[x]]@x))[1:3],] | ||
|
||
fit_low <- nplr::nplr( | ||
x = df_low$x, | ||
y = df_low$y#, | ||
# npars = npars, | ||
# method = weight_method, | ||
# LPweight = LPweight, | ||
# silent = silent | ||
) | ||
|
||
suppressWarnings({ | ||
suppressMessages({ | ||
lod <- nplr::getEstimates( | ||
fit_low, | ||
targets = blank_targets | ||
)$x | ||
}) | ||
}) | ||
|
||
tibble::tibble( | ||
Analyte = x, | ||
Fit = paste0("nplr ", fits[[x]]@npars, "PL"), | ||
LLoQ = lloq, | ||
MDD = mdd, | ||
LoD = lod, | ||
`R Squared` = fits[[x]]@goodness$gof, | ||
Slope = fits[[x]]@pars$s | ||
) | ||
}) |> dplyr::bind_rows() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#' update_recovery | ||
#' | ||
#' Update the recovery property from an intelliframe object using up-to-date | ||
#' well_data. Not meant to be called by the user. | ||
#' | ||
#' @param .well_data A tibble containing the well_data property. | ||
#' | ||
#' @return An intelliframe | ||
#' @export | ||
#' | ||
#' @noRd | ||
update_recovery <- function(.well_data){ | ||
dplyr::filter(.well_data, .data[["Type"]] %in% c("Standard", "Control")) |> | ||
|
||
dplyr::mutate( | ||
Recovery = dplyr::case_when( | ||
.data[["Expected"]] == 0 ~ NA_real_, | ||
.default = .data[["Result"]] / .data[["Expected"]] | ||
) | ||
) |> | ||
|
||
dplyr::select(-c("MFI", "Result", "Messages", "Exclude Reason", "Excluded", "Expected")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#' update_recovery_avg | ||
#' | ||
#' Update the recovery_avg property from an intelliframe object using up-to-date | ||
#' recovery. Not meant to be called by the user. | ||
#' | ||
#' @param .recovery A tibble containing the recovery property. | ||
#' @param .recovery A tibble containing the original recovery_avg property. | ||
#' @param .use_excluded Logical flag indicating whether wells with a value of | ||
#' \code{TRUE} in the \code{Excluded} column are used to calculate summary | ||
#' statistics. | ||
#' @param .excluded_wells Logical vector indicating whether each well is | ||
#' excluded. | ||
#' | ||
#' @return An intelliframe | ||
#' @export | ||
#' | ||
#' @noRd | ||
update_recovery_avg <- function(.recovery, .recovery_avg, .use_excluded, .excluded_wells) { | ||
correct_location <- dplyr::select(.recovery, -Location) |> | ||
dplyr::left_join( | ||
dplyr::select(.recovery_avg, -Recovery), | ||
by = c("Plate", "Group", "Well ID", "Sample ID", "Standard", "Type", "Analyte") | ||
) |> | ||
dplyr::select( | ||
"Plate", "Group", "Location", "Well ID", "Sample ID", "Standard", "Type", | ||
"Analyte", "Recovery" | ||
) | ||
|
||
if(!.use_excluded) { | ||
correct_location <- correct_location[-.excluded_wells, ] | ||
} | ||
|
||
dplyr::summarise( | ||
correct_location, | ||
.by = c("Plate", "Group", "Location", "Well ID", "Sample ID", "Standard", | ||
"Type", "Analyte"), | ||
Recovery = mean(Recovery, na.rm = TRUE) | ||
) | ||
} |
Oops, something went wrong.