So what happens to my data?…

you might rightfully ask yourself when loading a dataset into ShinyLipids. Luckily, we expose the internals of ShinyLipids in the form of clearly named functions for you to use even outside of the app. If you want to learn more about how exactly things work underneath the hood, you can click at the individual functions to read their documentation or have a look at the source code. But for now, let’s explore the example data together. We will follow the steps that ShinyLipids takes and inspect intermediate results.

First, we load ShinyLipids

library(ShinyLipids)

input <- defaultInput()

We can get the file path to our example data, given that ShinyLipids is installed, and open up a database connection to the database dump file

path <- system.file("extdata/exampleDatabase.db", package = "ShinyLipids")
databaseConnection <- DBI::dbConnect(RSQLite::SQLite(), path)

We see, that our example file contains two tables (their names are mandatory).

DBI::dbListTables(databaseConnection)
#> [1] "data2"   "id_info"

From this connection, we load in our meta data “id_info” – information about the dataset(s) in the “data2” table:

metaData <- collectMetaData(databaseConnection)
metaData
#> # A tibble: 1 x 14
#>      id title date_upload status sample_from date_sample extracted_by
#>   <dbl> <chr> <date>      <chr>  <chr>       <date>      <chr>       
#> 1     1 Exam… NA          in pr… Harry Pott… NA          Albus Dumbl…
#> # … with 7 more variables: date_extraction <date>, measured_by <chr>,
#> #   date_measured <date>, distinct_samples <int>, data_lines <int>, file <chr>,
#> #   instruments <chr>

We see, that our ownly dataset in the database has id 1, so we use that id to collect the raw data and inspect the first 6 rows:

rawData <- collectRawData(con = databaseConnection,
                          id = 1)
head(rawData)
#> # A tibble: 6 x 9
#>      id sample_identifi… lipid   value category func_cat sample sample_replicate
#>   <dbl> <chr>            <chr>   <dbl> <chr>    <chr>    <chr>  <chr>           
#> 1     1 1Aa              Cer … 0.00590 SP       SP       1 - 0… 1 - 0min Stim_A 
#> 2     1 1Aa              Cer … 0.276   SP       SP       1 - 0… 1 - 0min Stim_A 
#> 3     1 1Aa              Cer … 0.0497  SP       SP       1 - 0… 1 - 0min Stim_A 
#> 4     1 1Aa              Cer … 0.0690  SP       SP       1 - 0… 1 - 0min Stim_A 
#> 5     1 1Aa              Cer … 0.00325 SP       SP       1 - 0… 1 - 0min Stim_A 
#> 6     1 1Aa              Cer … 0.0219  SP       SP       1 - 0… 1 - 0min Stim_A 
#> # … with 1 more variable: sample_replicate_technical <chr>

Next, we run the data processing steps.

plotData <- rawData %>%
  imputeMissingIf(input) %>%
  addLipidProperties() %>%
  standardizeWithinTechnicalReplicatesIf(input) %>%
  filterRawDataFor(input) %>%
  standardizeWithin(input) %>%
  createPlotData(input)

head(plotData)
#> # A tibble: 6 x 4
#>   class sample         sample_replicate value
#>   <fct> <fct>          <fct>            <dbl>
#> 1 PC    1 - 0min Stim  1 - 0min Stim_A   9.08
#> 2 PC    1 - 0min Stim  1 - 0min Stim_B   6.71
#> 3 PC    1 - 0min Stim  1 - 0min Stim_C   4.66
#> 4 PC    1 - 0min Stim  1 - 0min Stim_D  19.5 
#> 5 PC    2 - 10min Stim 2 - 10min Stim_A  3.76
#> 6 PC    2 - 10min Stim 2 - 10min Stim_B  5.34
meanPlotData <- summarisePlotData(plotData, input)
head(meanPlotData)
#> # A tibble: 6 x 8
#>   class sample            SD   SEM     N value CI_lower CI_upper
#>   <fct> <fct>          <dbl> <dbl> <int> <dbl>    <dbl>    <dbl>
#> 1 PC    1 - 0min Stim   6.60 1.65      4  9.99     4.74    15.2 
#> 2 PC    2 - 10min Stim  3.10 0.775     4  6.80     4.33     9.26
#> 3 PC    3 - 6h Stim     2.07 0.518     4  9.32     7.67    11.0 
#> 4 PC    4 - 18h Stim    4.80 1.20      4 11.6      7.83    15.5 
#> 5 PC O- 1 - 0min Stim   2.32 0.580     4  5.33     3.48     7.17
#> 6 PC O- 2 - 10min Stim  4.97 1.24      4  6.86     2.90    10.8
plt <- createMainPlot(plotData            = plotData,
                      meanPlotData        = meanPlotData,
                      pairwiseComparisons = NULL,
                      input = input)

plt