Skip to contents

Metabolon data is…

Import Metabolon data

library(metaboprep)

# example file
filepath <- system.file("extdata", "metabolon_v1.2_example.xlsx", package = "metaboprep")

# import
dat <- read_metabolon(filepath, sheet = 'OrigScale')

# view structure
str(dat)
#> List of 3
#>  $ data    : num [1:100, 1:104] 98551 43695 44899 37811 36825 ...
#>   ..- attr(*, "dimnames")=List of 2
#>   .. ..$ : chr [1:100] "ind1" "ind2" "ind3" "ind4" ...
#>   .. ..$ : chr [1:104] "123" "124" "125" "126" ...
#>  $ samples :'data.frame':    100 obs. of  5 variables:
#>   ..$ sample_id        : chr [1:100] "ind1" "ind2" "ind3" "ind4" ...
#>   ..$ parent_sample_id : chr [1:100] "ps_id" "ps_id" "ps_id" "ps_id" ...
#>   ..$ client_identifier: chr [1:100] "FR01234" "FR01235" "FR01236" "FR01237" ...
#>   ..$ pair             : chr [1:100] "99999" "99999" "99999" "99999" ...
#>   ..$ volume_extracted : chr [1:100] "100" "100" "100" "100" ...
#>  $ features:'data.frame':    104 obs. of  13 variables:
#>   ..$ feature_id       : chr [1:104] "123" "124" "125" "126" ...
#>   ..$ pathway_sortorder: chr [1:104] "1" "2" "3" "4" ...
#>   ..$ biochemical      : chr [1:104] "(N(1) + N(8))-acetylspermidine" "1,2,3-benzenetriol sulfate (2)" "1,2-dilinoleoyl-GPC (18:2/18:2)" "1,2-dilinoleoyl-GPE (18:2/18:2)*" ...
#>   ..$ super_pathway    : chr [1:104] "Amino Acid" "Xenobiotics" "Lipid" "Lipid" ...
#>   ..$ sub_pathway      : chr [1:104] "Polyamine Metabolism" "Chemical" "Phosphatidylcholine (PC)" "Phosphatidylethanolamine (PE)" ...
#>   ..$ platform         : chr [1:104] "LC/MS Pos Early" "LC/MS Neg" "LC/MS Pos Late" "LC/MS Pos Late" ...
#>   ..$ chemical_id      : chr [1:104] "1111" "1112" "1113" "1114" ...
#>   ..$ ri               : chr [1:104] "2221" "2222" "2223" "2224" ...
#>   ..$ mass             : chr [1:104] "111.111" "111.11199999999999" "111.113" "111.114" ...
#>   ..$ cas              : chr [1:104] NA NA "111-11-1" NA ...
#>   ..$ pubchem          : chr [1:104] NA NA "11111" "11112" ...
#>   ..$ kegg             : chr [1:104] NA NA NA NA ...
#>   ..$ group_hmdb       : chr [1:104] NA NA "HMDB123" "HMDB124" ...

Create Metaboprep object

Once imported, we pass the data to the Metaboprep class object.

m <- Metaboprep(data     = dat$data, 
                features = dat$features, 
                samples  = dat$samples)

# view 
m
#> <metaboprep::Metaboprep>
#>  @ data           : num [1:100, 1:104, 1] 98551 43695 44899 37811 36825 ...
#>  .. - attr(*, "dimnames")=List of 3
#>  ..  ..$ : chr [1:100] "ind1" "ind2" "ind3" "ind4" ...
#>  ..  ..$ : chr [1:104] "123" "124" "125" "126" ...
#>  ..  ..$ : chr "input"
#>  @ samples        :'data.frame': 100 obs. of  5 variables:
#>  .. $ sample_id        : chr  "ind1" "ind2" "ind3" "ind4" ...
#>  .. $ parent_sample_id : chr  "ps_id" "ps_id" "ps_id" "ps_id" ...
#>  .. $ client_identifier: chr  "FR01234" "FR01235" "FR01236" "FR01237" ...
#>  .. $ pair             : chr  "99999" "99999" "99999" "99999" ...
#>  .. $ volume_extracted : chr  "100" "100" "100" "100" ...
#>  @ features       :'data.frame': 104 obs. of  13 variables:
#>  .. $ feature_id       : chr  "123" "124" "125" "126" ...
#>  .. $ pathway_sortorder: chr  "1" "2" "3" "4" ...
#>  .. $ biochemical      : chr  "(N(1) + N(8))-acetylspermidine" "1,2,3-benzenetriol sulfate (2)" "1,2-dilinoleoyl-GPC (18:2/18:2)" "1,2-dilinoleoyl-GPE (18:2/18:2)*" ...
#>  .. $ super_pathway    : chr  "Amino Acid" "Xenobiotics" "Lipid" "Lipid" ...
#>  .. $ sub_pathway      : chr  "Polyamine Metabolism" "Chemical" "Phosphatidylcholine (PC)" "Phosphatidylethanolamine (PE)" ...
#>  .. $ platform         : chr  "LC/MS Pos Early" "LC/MS Neg" "LC/MS Pos Late" "LC/MS Pos Late" ...
#>  .. $ chemical_id      : chr  "1111" "1112" "1113" "1114" ...
#>  .. $ ri               : chr  "2221" "2222" "2223" "2224" ...
#>  .. $ mass             : chr  "111.111" "111.11199999999999" "111.113" "111.114" ...
#>  .. $ cas              : chr  NA NA "111-11-1" NA ...
#>  .. $ pubchem          : chr  NA NA "11111" "11112" ...
#>  .. $ kegg             : chr  NA NA NA NA ...
#>  .. $ group_hmdb       : chr  NA NA "HMDB123" "HMDB124" ...
#>  @ exclusions     :List of 2
#>  .. $ samples :List of 5
#>  ..  ..$ user_excluded                    : chr(0) 
#>  ..  ..$ extreme_sample_missingness       : chr(0) 
#>  ..  ..$ user_defined_sample_missingness  : chr(0) 
#>  ..  ..$ user_defined_sample_totalpeakarea: chr(0) 
#>  ..  ..$ user_defined_sample_pca_outlier  : chr(0) 
#>  .. $ features:List of 3
#>  ..  ..$ user_excluded                   : chr(0) 
#>  ..  ..$ extreme_feature_missingness     : chr(0) 
#>  ..  ..$ user_defined_feature_missingness: chr(0) 
#>  @ feature_summary: num[0 , 0 , 0 ] 
#>  @ sample_summary : num[0 , 0 , 0 ]

QC Metabolon

m <- m |>
  quality_control(source_layer        = "input", 
                  sample_missingness  = 0.5, 
                  feature_missingness = 0.3, 
                  total_peak_area_sd  = 5, 
                  outlier_udist       = 5, 
                  outlier_treatment   = "leave_be", 
                  winsorize_quantile  = 1.0, 
                  tree_cut_height     = 0.5, 
                  pc_outlier_sd       = 5)
#> 
#> ── Starting Metabolite QC Process ──────────────────────────────────────────────
#>  Validating input parameters
#>  Validating input parameters [7ms]
#> 
#>  Sample & Feature Summary Statistics for raw data
#>  Sample & Feature Summary Statistics for raw data [1.1s]
#> 
#>  Copying input data to new 'qc' data layer
#>  Copying input data to new 'qc' data layer [24ms]
#> 
#>  Assessing for extreme sample missingness >=80% - excluding 0 sample(s)
#>  Assessing for extreme sample missingness >=80% - excluding 1 sample(s) [16ms]
#> 
#>  Assessing for extreme feature missingness >=80% - excluding 0 feature(s)
#>  Assessing for extreme feature missingness >=80% - excluding 0 feature(s) [21m
#> 
#>  Assessing for sample missingness at specified level of >=50% - excluding 0 sa…
#>  Assessing for sample missingness at specified level of >=50% - excluding 0 sa…
#> 
#>  Assessing for feature missingness at specified level of >=30% - excluding 0 f…
#>  Assessing for feature missingness at specified level of >=30% - excluding 1 f…
#> 
#>  Calculating total peak abundance outliers at +/- 5 Sdev - excluding 0 sample(…
#>  Calculating total peak abundance outliers at +/- 5 Sdev - excluding 0 sample(…
#> 
#>  Running sample data PCA outlier analysis at +/- 5 Sdev
#>  Running sample data PCA outlier analysis at +/- 5 Sdev [17ms]
#> 
#>  Sample PCA outlier analysis - re-identify feature independence and PC outlier…
#> [1] 2
#> [1] 99 10
#>  Sample PCA outlier analysis - re-identify feature independence and PC outlier…
#> 
#>  Creating final QC dataset...
#>  Creating final QC dataset... [1s]
#> 
#>  Metabolite QC Process Completed
#>  Metabolite QC Process Completed [20ms]
#> 

# view 
m
#> <metaboprep::Metaboprep>
#>  @ data           : num [1:100, 1:104, 1:2] 98551 43695 44899 37811 36825 ...
#>  .. - attr(*, "dimnames")=List of 3
#>  ..  ..$ : chr [1:100] "ind1" "ind2" "ind3" "ind4" ...
#>  ..  ..$ : chr [1:104] "123" "124" "125" "126" ...
#>  ..  ..$ : chr [1:2] "input" "qc"
#>  .. - attr(*, "qc_sample_missingness")= num 0.5
#>  .. - attr(*, "qc_feature_missingness")= num 0.3
#>  .. - attr(*, "qc_total_peak_area_sd")= num 5
#>  .. - attr(*, "qc_outlier_udist")= num 5
#>  .. - attr(*, "qc_outlier_treatment")= chr "leave_be"
#>  .. - attr(*, "qc_winsorize_quantile")= num 1
#>  .. - attr(*, "qc_tree_cut_height")= num 0.5
#>  .. - attr(*, "qc_pc_outlier_sd")= num 5
#>  .. - attr(*, "qc_features_exclude_but_keep")= chr(0) 
#>  @ samples        :'data.frame': 100 obs. of  7 variables:
#>  .. $ sample_id        : chr  "ind1" "ind2" "ind3" "ind4" ...
#>  .. $ parent_sample_id : chr  "ps_id" "ps_id" "ps_id" "ps_id" ...
#>  .. $ client_identifier: chr  "FR01234" "FR01235" "FR01236" "FR01237" ...
#>  .. $ pair             : chr  "99999" "99999" "99999" "99999" ...
#>  .. $ volume_extracted : chr  "100" "100" "100" "100" ...
#>  .. $ reason_excluded  : chr  NA NA NA NA ...
#>  .. $ excluded         : logi  FALSE FALSE FALSE FALSE FALSE FALSE ...
#>  @ features       :'data.frame': 104 obs. of  15 variables:
#>  .. $ feature_id       : chr  "123" "124" "125" "126" ...
#>  .. $ pathway_sortorder: chr  "1" "2" "3" "4" ...
#>  .. $ biochemical      : chr  "(N(1) + N(8))-acetylspermidine" "1,2,3-benzenetriol sulfate (2)" "1,2-dilinoleoyl-GPC (18:2/18:2)" "1,2-dilinoleoyl-GPE (18:2/18:2)*" ...
#>  .. $ super_pathway    : chr  "Amino Acid" "Xenobiotics" "Lipid" "Lipid" ...
#>  .. $ sub_pathway      : chr  "Polyamine Metabolism" "Chemical" "Phosphatidylcholine (PC)" "Phosphatidylethanolamine (PE)" ...
#>  .. $ platform         : chr  "LC/MS Pos Early" "LC/MS Neg" "LC/MS Pos Late" "LC/MS Pos Late" ...
#>  .. $ chemical_id      : chr  "1111" "1112" "1113" "1114" ...
#>  .. $ ri               : chr  "2221" "2222" "2223" "2224" ...
#>  .. $ mass             : chr  "111.111" "111.11199999999999" "111.113" "111.114" ...
#>  .. $ cas              : chr  NA NA "111-11-1" NA ...
#>  .. $ pubchem          : chr  NA NA "11111" "11112" ...
#>  .. $ kegg             : chr  NA NA NA NA ...
#>  .. $ group_hmdb       : chr  NA NA "HMDB123" "HMDB124" ...
#>  .. $ reason_excluded  : chr  NA NA NA NA ...
#>  .. $ excluded         : logi  FALSE FALSE FALSE FALSE FALSE FALSE ...
#>  @ exclusions     :List of 2
#>  .. $ samples :List of 5
#>  ..  ..$ user_excluded                    : chr(0) 
#>  ..  ..$ extreme_sample_missingness       : chr "ind13"
#>  ..  ..$ user_defined_sample_missingness  : chr(0) 
#>  ..  ..$ user_defined_sample_totalpeakarea: chr(0) 
#>  ..  ..$ user_defined_sample_pca_outlier  : chr(0) 
#>  .. $ features:List of 3
#>  ..  ..$ user_excluded                   : chr(0) 
#>  ..  ..$ extreme_feature_missingness     : chr(0) 
#>  ..  ..$ user_defined_feature_missingness: chr "179"
#>  @ feature_summary: num [1:20, 1:104, 1:2] 0.01 0 99 52876.67 25579.58 ...
#>  .. - attr(*, "dimnames")=List of 3
#>  ..  ..$ : chr [1:20] "missingness" "outlier_count" "n" "mean" ...
#>  ..  ..$ : chr [1:104] "123" "124" "125" "126" ...
#>  ..  ..$ : chr [1:2] "input" "qc"
#>  .. - attr(*, "qc_tree")=List of 7
#>  ..  ..$ merge      : int [1:102, 1:2] -35 -22 -70 -5 -23 -19 -91 -1 -10 -46 ...
#>  ..  ..$ height     : num [1:102] 0.632 0.646 0.659 0.664 0.671 ...
#>  ..  ..$ order      : int [1:103] 94 100 10 31 17 29 74 89 28 96 ...
#>  ..  ..$ labels     : chr [1:103] "123" "124" "125" "126" ...
#>  ..  ..$ method     : chr "complete"
#>  ..  ..$ call       : language stats::hclust(d = dist_matrix, method = "complete")
#>  ..  ..$ dist.method: NULL
#>  ..  ..- attr(*, "class")= chr "hclust"
#>  .. - attr(*, "qc_outlier_udist")= num 5
#>  .. - attr(*, "qc_tree_cut_height")= num 0.5
#>  @ sample_summary : num [1:100, 1:20, 1:2] 0.00962 0.00962 0.00962 0.00962 0.05769 ...
#>  .. - attr(*, "dimnames")=List of 3
#>  ..  ..$ : chr [1:100] "ind1" "ind2" "ind3" "ind4" ...
#>  ..  ..$ : chr [1:20] "missingness" "tpa_total" "tpa_complete_features" "outlier_count" ...
#>  ..  ..$ : chr [1:2] "input" "qc"
#>  .. - attr(*, "qc_varexp")= Named num [1:99] 0.0372 0.035 0.0334 0.0327 0.0316 ...
#>  ..  ..- attr(*, "names")= chr [1:99] "PC1" "PC2" "PC3" "PC4" ...
#>  .. - attr(*, "qc_num_pcs_scree")= num 2
#>  .. - attr(*, "qc_num_pcs_parallel")= int 16
#>  .. - attr(*, "qc_outlier_udist")= num 5