8  Extract data from mass_dataset

8.1 Use extract_xxx functions

We first created a mass_dataset class object.

library(massdataset)
library(tidyverse)

data("expression_data")
data("sample_info")
data("sample_info_note")
data("variable_info")
data("variable_info_note")

object =
  create_mass_dataset(
    expression_data = expression_data,
    sample_info = sample_info,
    variable_info = variable_info,
    sample_info_note = sample_info_note,
    variable_info_note = variable_info_note
  )
  
object
-------------------- 
massdataset version: 1.0.34 
-------------------- 
1.expression_data:[ 1000 x 8 data.frame]
2.sample_info:[ 8 x 4 data.frame]
8 samples:Blank_3 Blank_4 QC_1 ... PS4P3 PS4P4
3.variable_info:[ 1000 x 3 data.frame]
1000 variables:M136T55_2_POS M79T35_POS M307T548_POS ... M232T937_POS M301T277_POS
4.sample_info_note:[ 4 x 2 data.frame]
5.variable_info_note:[ 3 x 2 data.frame]
6.ms2_data:[ 0 variables x 0 MS2 spectra]
-------------------- 
Processing information
1 processings in total
create_mass_dataset ---------- 
      Package         Function.used                Time
1 massdataset create_mass_dataset() 2025-07-20 19:15:51

In massdataset package, there are a series of functions named as extract_xxx(), users can use them to extract data from mass_dataset calss object.

##sample_info
extract_sample_info(object)
  sample_id injection.order   class   group
1   Blank_3               1   Blank   Blank
2   Blank_4               2   Blank   Blank
3      QC_1               3      QC      QC
4      QC_2               4      QC      QC
5     PS4P1               5 Subject Subject
6     PS4P2               6 Subject Subject
7     PS4P3               7 Subject Subject
8     PS4P4               8 Subject Subject
##variable_info
extract_variable_info(object) %>% head()
    variable_id        mz        rt
1 M136T55_2_POS 136.06140  54.97902
2    M79T35_POS  79.05394  35.36550
3  M307T548_POS 307.14035 547.56641
4  M183T224_POS 183.06209 224.32777
5   M349T47_POS 349.01584  47.00262
6  M182T828_POS 181.99775 828.35712
##expression_data
extract_expression_data(object) %>% head()
              Blank_3 Blank_4      QC_1      QC_2     PS4P1     PS4P2   PS4P3
M136T55_2_POS      NA      NA 1857924.8 1037763.8 1494436.1 3496912.1 1959179
M79T35_POS         NA      NA 2821550.2 1304875.3 2471336.1 3333582.7 2734244
M307T548_POS       NA      NA  410387.6  273687.8  288590.2  137297.5      NA
M183T224_POS       NA      NA        NA        NA        NA 5059068.1 5147422
M349T47_POS        NA      NA 8730104.8 4105598.5 5141073.2 8424315.6 7896633
M182T828_POS  3761893 2572593        NA 3662819.1 5700534.8 4600172.4 5557015
                  PS4P4
M136T55_2_POS 1005418.8
M79T35_POS    3361452.3
M307T548_POS   271318.3
M183T224_POS         NA
M349T47_POS   6441449.0
M182T828_POS  4433034.2
##sample_info_note
extract_sample_info_note(object) 
             name         meaning
1       sample_id       sample_id
2 injection.order injection.order
3           class           class
4           group           group
##variable_info_note
extract_variable_info_note(object) 
         name     meaning
1 variable_id variable_id
2          mz          mz
3          rt          rt
##ms2_data
extract_ms2_data(object)
list()
##process_info
extract_annotation_table(object)
data frame with 0 columns and 0 rows
##process_info
extract_process_info(object)
$create_mass_dataset
-------------------- 
pacakge_name: massdataset 
function_name: create_mass_dataset() 
time: 2025-07-20 19:15:51.016795 
parameters:
no : no 

8.2 Use slot() function

slot(object = object, name = "sample_info")
  sample_id injection.order   class   group
1   Blank_3               1   Blank   Blank
2   Blank_4               2   Blank   Blank
3      QC_1               3      QC      QC
4      QC_2               4      QC      QC
5     PS4P1               5 Subject Subject
6     PS4P2               6 Subject Subject
7     PS4P3               7 Subject Subject
8     PS4P4               8 Subject Subject
slot(object = object, name = "variable_info") %>% head()
    variable_id        mz        rt
1 M136T55_2_POS 136.06140  54.97902
2    M79T35_POS  79.05394  35.36550
3  M307T548_POS 307.14035 547.56641
4  M183T224_POS 183.06209 224.32777
5   M349T47_POS 349.01584  47.00262
6  M182T828_POS 181.99775 828.35712
slot(object = object, name = "expression_data") %>% head()
              Blank_3 Blank_4      QC_1      QC_2     PS4P1     PS4P2   PS4P3
M136T55_2_POS      NA      NA 1857924.8 1037763.8 1494436.1 3496912.1 1959179
M79T35_POS         NA      NA 2821550.2 1304875.3 2471336.1 3333582.7 2734244
M307T548_POS       NA      NA  410387.6  273687.8  288590.2  137297.5      NA
M183T224_POS       NA      NA        NA        NA        NA 5059068.1 5147422
M349T47_POS        NA      NA 8730104.8 4105598.5 5141073.2 8424315.6 7896633
M182T828_POS  3761893 2572593        NA 3662819.1 5700534.8 4600172.4 5557015
                  PS4P4
M136T55_2_POS 1005418.8
M79T35_POS    3361452.3
M307T548_POS   271318.3
M183T224_POS         NA
M349T47_POS   6441449.0
M182T828_POS  4433034.2
slot(object = object, name = "sample_info_note") 
             name         meaning
1       sample_id       sample_id
2 injection.order injection.order
3           class           class
4           group           group
slot(object = object, name = "variable_info_note") 
         name     meaning
1 variable_id variable_id
2          mz          mz
3          rt          rt
slot(object = object, name = "ms2_data") 
list()
slot(object = object, name = "process_info") 
$create_mass_dataset
-------------------- 
pacakge_name: massdataset 
function_name: create_mass_dataset() 
time: 2025-07-20 19:15:51.016795 
parameters:
no : no 
slot(object = object, name = "annotation_table") 
data frame with 0 columns and 0 rows

8.3 Use @

mass_data class is a S4 object. So we can also use @.

object@expression_data %>% head()
              Blank_3 Blank_4      QC_1      QC_2     PS4P1     PS4P2   PS4P3
M136T55_2_POS      NA      NA 1857924.8 1037763.8 1494436.1 3496912.1 1959179
M79T35_POS         NA      NA 2821550.2 1304875.3 2471336.1 3333582.7 2734244
M307T548_POS       NA      NA  410387.6  273687.8  288590.2  137297.5      NA
M183T224_POS       NA      NA        NA        NA        NA 5059068.1 5147422
M349T47_POS        NA      NA 8730104.8 4105598.5 5141073.2 8424315.6 7896633
M182T828_POS  3761893 2572593        NA 3662819.1 5700534.8 4600172.4 5557015
                  PS4P4
M136T55_2_POS 1005418.8
M79T35_POS    3361452.3
M307T548_POS   271318.3
M183T224_POS         NA
M349T47_POS   6441449.0
M182T828_POS  4433034.2
object@sample_info
  sample_id injection.order   class   group
1   Blank_3               1   Blank   Blank
2   Blank_4               2   Blank   Blank
3      QC_1               3      QC      QC
4      QC_2               4      QC      QC
5     PS4P1               5 Subject Subject
6     PS4P2               6 Subject Subject
7     PS4P3               7 Subject Subject
8     PS4P4               8 Subject Subject
object@variable_info %>% head()
    variable_id        mz        rt
1 M136T55_2_POS 136.06140  54.97902
2    M79T35_POS  79.05394  35.36550
3  M307T548_POS 307.14035 547.56641
4  M183T224_POS 183.06209 224.32777
5   M349T47_POS 349.01584  47.00262
6  M182T828_POS 181.99775 828.35712
object@sample_info_note
             name         meaning
1       sample_id       sample_id
2 injection.order injection.order
3           class           class
4           group           group
object@variable_info_note
         name     meaning
1 variable_id variable_id
2          mz          mz
3          rt          rt
object@process_info
$create_mass_dataset
-------------------- 
pacakge_name: massdataset 
function_name: create_mass_dataset() 
time: 2025-07-20 19:15:51.016795 
parameters:
no : no 
object@ms2_data
list()
object@annotation_table
data frame with 0 columns and 0 rows

8.4 Session information

sessionInfo()
R version 4.4.1 (2024-06-14)
Platform: aarch64-apple-darwin20
Running under: macOS 15.5

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRblas.0.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: Asia/Singapore
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] lubridate_1.9.3    forcats_1.0.0      stringr_1.5.1      purrr_1.0.2       
 [5] readr_2.1.5        tidyr_1.3.1        tibble_3.2.1       tidyverse_2.0.0   
 [9] ggplot2_3.5.1      dplyr_1.1.4        magrittr_2.0.3     masstools_1.0.15  
[13] massdataset_1.0.34

loaded via a namespace (and not attached):
  [1] pbapply_1.7-2               remotes_2.5.0              
  [3] rlang_1.1.4                 clue_0.3-65                
  [5] GetoptLong_1.0.5            matrixStats_1.4.1          
  [7] compiler_4.4.1              png_0.1-8                  
  [9] vctrs_0.6.5                 reshape2_1.4.4             
 [11] rvest_1.0.4                 ProtGenerics_1.36.0        
 [13] pkgconfig_2.0.3             shape_1.4.6.1              
 [15] crayon_1.5.3                fastmap_1.2.0              
 [17] XVector_0.44.0              rmarkdown_2.29             
 [19] tzdb_0.4.0                  UCSC.utils_1.0.0           
 [21] preprocessCore_1.66.0       xfun_0.52                  
 [23] MultiAssayExperiment_1.30.3 zlibbioc_1.50.0            
 [25] GenomeInfoDb_1.40.1         jsonlite_1.8.9             
 [27] DelayedArray_0.30.1         BiocParallel_1.38.0        
 [29] parallel_4.4.1              cluster_2.1.6              
 [31] R6_2.5.1                    stringi_1.8.4              
 [33] RColorBrewer_1.1-3          limma_3.60.6               
 [35] GenomicRanges_1.56.2        Rcpp_1.0.13-1              
 [37] SummarizedExperiment_1.34.0 iterators_1.0.14           
 [39] knitr_1.49                  IRanges_2.38.1             
 [41] timechange_0.3.0            Matrix_1.7-1               
 [43] igraph_2.1.1                tidyselect_1.2.1           
 [45] rstudioapi_0.17.1           abind_1.4-8                
 [47] doParallel_1.0.17           codetools_0.2-20           
 [49] affy_1.82.0                 lattice_0.22-6             
 [51] plyr_1.8.9                  withr_3.0.2                
 [53] Biobase_2.64.0              evaluate_1.0.1             
 [55] zip_2.3.1                   xml2_1.3.6                 
 [57] circlize_0.4.16             pillar_1.11.0              
 [59] affyio_1.74.0               BiocManager_1.30.25        
 [61] MatrixGenerics_1.16.0       foreach_1.5.2              
 [63] stats4_4.4.1                MSnbase_2.30.1             
 [65] MALDIquant_1.22.3           ncdf4_1.23                 
 [67] generics_0.1.3              hms_1.1.3                  
 [69] S4Vectors_0.42.1            munsell_0.5.1              
 [71] scales_1.3.0                glue_1.8.0                 
 [73] lazyeval_0.2.2              tools_4.4.1                
 [75] mzID_1.42.0                 QFeatures_1.14.2           
 [77] vsn_3.72.0                  mzR_2.38.0                 
 [79] openxlsx_4.2.7.1            XML_3.99-0.17              
 [81] grid_4.4.1                  impute_1.78.0              
 [83] MsCoreUtils_1.16.1          colorspace_2.1-1           
 [85] GenomeInfoDbData_1.2.12     PSMatch_1.8.0              
 [87] cli_3.6.3                   S4Arrays_1.4.1             
 [89] ComplexHeatmap_2.20.0       AnnotationFilter_1.28.0    
 [91] pcaMethods_1.96.0           gtable_0.3.6               
 [93] digest_0.6.37               BiocGenerics_0.50.0        
 [95] SparseArray_1.4.8           rjson_0.2.23               
 [97] htmlwidgets_1.6.4           htmltools_0.5.8.1          
 [99] lifecycle_1.0.4             httr_1.4.7                 
[101] GlobalOptions_0.1.2         statmod_1.5.0              
[103] MASS_7.3-61