Quantitative assay with Ext. calibration and QC
Source:vignettes/articles/R01_quantms.Rmd
R01_quantms.Rmd
This recipe demonstrates a simple workflow for a quantitative assay with external calibration and quality control samples, as used in e.g. in clinical chemistry or environmental analysis.
The datasets used in this example can be obtained from https://github.com/SLINGhub/midar/tree/main/data-raw.
library(midar)
# Create a new MidarExperiment data object
mexp <- MidarExperiment(title = "Corticosteroid Assay")
# Import analysis data (peak integration results) from a MassHunter CSV file
mexp <- import_data_masshunter(
data = mexp,
path = "QuantLCMS_Example_MassHunter.csv",
import_metadata = TRUE)
# Import metadata from an msorganiser template fie
mexp <- import_metadata_msorganiser(
mexp,
path = "QuantLCMS_Example_Metadata.xlsm",
excl_unmatched_analyses = T, ignore_warnings = T)
# Normalize data by internal standards (defined in feature metadata)
mexp <- normalize_by_istd(mexp)
# Calculate calibration results. The regression model and weighting
# can also be specified per feature in the feature metadata
mexp <- calc_calibration_results(
mexp,
overwrite_fit_param = TRUE, # Set to FALSE if defined in metadata
fit_model = "quadratic",
fit_weighting = "1/x")
# Get a table with calibration results
get_calibration_metrics(mexp)
# Plot calibration curves
p <- plot_calibrationcurves(
data = mexp,
fit_model = "quadratic",
fit_weighting = "1/x",
rows_page = 2,
cols_page = 4
)
# Calculate concentrations for all samples using external calibration
mexp <- quantify_by_calibration(
mexp,
overwrite_fit_param = FALSE,
include_qualifier = FALSE,
ignore_failed_calibration = TRUE,
fit_model = "quadratic",
fit_weighting = "1/x")
# get a table with QC results (bias and variability)
tbl <- get_qc_bias_variability(mexp, qc_types = c("HQC", "LQC"))
print(tbl)
# Save a table with final concentration data
save_dataset_csv( mexp,
path = "corticosteroid_conc.csv",
variable = "conc",
filter_data = FALSE)
#> indexed 0B in 0s, 0B/sindexed 1.00TB in 0s, 3.69PB/s --------------------------------------------------------------------------------------------
#> Type Table Column Issue Count
#> 1 W* Analyses sample_id Incomplete value(s) 8
#> --------------------------------------------------------------------------------------------
#> E = Error, W = Warning, W* = Supressed Warning, N = Note
#> --------------------------------------------------------------------------------------------
#> # A tibble: 8 × 14
#> feature_id is_quantifier fit_model fit_weighting reg_failed r2 lowest_cal
#> <chr> <lgl> <chr> <chr> <lgl> <dbl> <dbl>
#> 1 Aldosterone TRUE quadratic 1/x FALSE 0.980 0.277
#> 2 Aldosterone… FALSE quadratic 1/x FALSE 0.981 0.277
#> 3 Corticoster… TRUE quadratic 1/x FALSE 0.998 0.867
#> 4 Corticoster… FALSE quadratic 1/x FALSE 0.994 0.867
#> 5 Cortisol TRUE quadratic 1/x FALSE 0.988 5.52
#> 6 Cortisol [Q… FALSE quadratic 1/x FALSE 0.995 5.52
#> 7 Cortisone TRUE quadratic 1/x FALSE 0.997 1.39
#> 8 Cortisone [… FALSE quadratic 1/x FALSE 0.984 1.39
#> # ℹ 7 more variables: highest_cal <dbl>, coef_a <dbl>, coef_b <dbl>,
#> # coef_c <dbl>, lod <dbl>, loq <dbl>, sigma <dbl>
#> | | | 0% | |==============================| 100%
#> # A tibble: 32 × 11
#> feature_id sample_id qc_type conc_target conc_mean conc_sd bias bias_sd
#> <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 Aldosterone CAL-A CAL 0.277 0.280 NA 0.00310 NA
#> 2 Aldosterone CAL-B CAL 0.609 0.373 NA -0.236 NA
#> 3 Aldosterone CAL-C CAL 1.27 1.84 NA 0.567 NA
#> 4 Aldosterone CAL-D CAL 2.74 2.74 NA 0.00171 NA
#> 5 Aldosterone CAL-E CAL 5.93 5.41 NA -0.522 NA
#> 6 Aldosterone CAL-F CAL 12.7 12.9 NA 0.184 NA
#> 7 Aldosterone HQC HQC 9.74 8.65 1.14 -1.09 1.14
#> 8 Aldosterone LQC LQC 0.911 0.843 0.132 -0.0682 0.132
#> 9 Corticoster… CAL-A CAL 0.867 0.920 NA 0.0530 NA
#> 10 Corticoster… CAL-B CAL 2.28 1.93 NA -0.346 NA
#> # ℹ 22 more rows
#> # ℹ 3 more variables: bias_perc <dbl>, bias_perc_sd <dbl>, cv_intra <dbl>