Overview
MidarExperiment` object is the main data container used in the MiDAR workflow. It holds all the experimental and processed data and metadata, as well as details of the applied processing steps and the current status of the data.
Most MiDAR
functions take an
MidarExperiment
object as input. Functions that process or
update the data return a modified MidarExperiment
object as
output, allowing it to be used in subsequent functions. You can create
and process multiple MidarExperiment
objects independently
within the same script.
Creating a MidarExperiment object
First the {midar} package is loaded and then we create a new
MidarExperiment
object.
library(midar)
myexp <- MidarExperiment()
Using MidarExperiment objects
Most MiDAR
functions take an MidarExperiment object as
input. Functions that process or update the data return a modified
MidarExperiment
object as output, allowing it to be used in
subsequent functions.
myexp <- MidarExperiment()
myexp <- data_load_example(myexp, 1)
myexp <- normalize_by_istd(myexp)
#> ✔ 24 features normalized with 9 ISTDs in 499 analyses.
save_dataset_csv(myexp, "mydata.csv", "norm_intensity", FALSE)
#> ✔ Norm_intensity values of 499 analyses and 24 features have been exported.
You can also use MidarExperiment
objects in an R pipe
chain. This allows you to chain multiple functions together, making your
code more streamlined and easier to read while clearly indicating the
flow of your processing workflow.
myexp <- myexp |>
MidarExperiment() |>
data_load_example(1) |>
normalize_by_istd() |>
save_dataset_csv("mydata.csv", "norm_intensity", FALSE)
#> ✔ 24 features normalized with 9 ISTDs in 499 analyses.
#> ✔ Norm_intensity values of 499 analyses and 24 features have been exported.
Status of an MidarExperiment
A detailed summary of the dataset and processing status can be printed any time
print(myexp)
#> [1] "cli-85346-7"
Multiple MidarExperiment
objects
Multiple MidarExperiment
objects can be created and
processed independently within the same script.
myexp_1 <- MidarExperiment(title = "Polar metabolites")
myexp_2 <- MidarExperiment(title = "Non-polar metabolites")
#myexp <- midar::combine_experiments(myexp_1, myexp_2)
Accessing data and metadata
Functions starting with data_get_
allow to retrieve data
and metadat from MidarExperiment
object.
myexp <- data_load_example(myexp, 1)
dataset <- get_analyticaldata(myexp)
print(dataset)
#> # A tibble: 16,467 × 18
#> run_seq_num analysis_id acquisition_time_stamp qc_type batch_id sample_id
#> <int> <chr> <dttm> <chr> <chr> <chr>
#> 1 1 Longit_BLANK-0… 2017-10-20 14:15:36 SBLK 1 NA
#> 2 1 Longit_BLANK-0… 2017-10-20 14:15:36 SBLK 1 NA
#> 3 1 Longit_BLANK-0… 2017-10-20 14:15:36 SBLK 1 NA
#> 4 1 Longit_BLANK-0… 2017-10-20 14:15:36 SBLK 1 NA
#> 5 1 Longit_BLANK-0… 2017-10-20 14:15:36 SBLK 1 NA
#> 6 1 Longit_BLANK-0… 2017-10-20 14:15:36 SBLK 1 NA
#> 7 1 Longit_BLANK-0… 2017-10-20 14:15:36 SBLK 1 NA
#> 8 1 Longit_BLANK-0… 2017-10-20 14:15:36 SBLK 1 NA
#> 9 1 Longit_BLANK-0… 2017-10-20 14:15:36 SBLK 1 NA
#> 10 1 Longit_BLANK-0… 2017-10-20 14:15:36 SBLK 1 NA
#> # ℹ 16,457 more rows
#> # ℹ 12 more variables: replicate_no <int>, specimen <chr>, feature_id <chr>,
#> # feature_class <chr>, feature_label <chr>, is_istd <lgl>,
#> # is_quantifier <lgl>, feature_rt <dbl>, feature_area <dbl>,
#> # feature_height <dbl>, feature_fwhm <dbl>, feature_intensity <dbl>
Alternatively, the $
syntax can be used access data and
metadata tables in MidarExperiment
objects.
analyses <- myexp$annot_analyses
features <- myexp$annot_features
dataset <- myexp$dataset
print(features)
#> # A tibble: 33 × 15
#> feature_id feature_class is_istd istd_feature_id quant_istd_feature_id
#> <chr> <chr> <lgl> <chr> <chr>
#> 1 CE 18:1 NA FALSE CE 18:1 d7 (IS… CE 18:1 d7 (ISTD)
#> 2 CE 18:1 d7 (ISTD) NA TRUE CE 18:1 d7 (IS… CE 18:1 d7 (ISTD)
#> 3 Cer d18:1/12:0 (… NA FALSE Cer d18:1/25:0… Cer d18:1/25:0 (ISTD)
#> 4 Cer d18:1/16:0 NA FALSE Cer d18:1/25:0… Cer d18:1/25:0 (ISTD)
#> 5 Cer d18:1/24:0 NA FALSE Cer d18:1/25:0… Cer d18:1/25:0 (ISTD)
#> 6 Cer d18:1/25:0 (… NA TRUE Cer d18:1/25:0… Cer d18:1/25:0 (ISTD)
#> 7 LPC 18:1 (a) NA FALSE LPC 18:1 (ab )… LPC 18:1 (ab ) d7 (I…
#> 8 LPC 18:1 (b) NA FALSE LPC 18:1 (ab )… LPC 18:1 (ab ) d7 (I…
#> 9 LPC 18:1 (ab ) d… NA TRUE LPC 18:1 (ab )… LPC 18:1 (ab ) d7 (I…
#> 10 LPC 18:1 (a ) d7… NA FALSE LPC 18:1 (ab )… LPC 18:1 (ab ) d7 (I…
#> # ℹ 23 more rows
#> # ℹ 10 more variables: is_quantifier <lgl>, valid_feature <lgl>,
#> # response_factor <dbl>, interference_feature_id <chr>,
#> # interference_proportion <dbl>, curve_fit_method <chr>, fit_weighting <chr>,
#> # remarks <chr>, feature_label <chr>, curve_fit_weighting <chr>
Saving and Reading MidarExperiment objects
myexp <- MidarExperiment()
myexp <- data_load_example(myexp, 1)
saveRDS(myexp, file = "myexp-midar.rds", compress = TRUE)
my_saved_exp <- readRDS(file = "myexp-midar.rds")
print(my_saved_exp)