Add mean intensity for each feature to variable_info

Add median intensity for each feature to variable_info

Calculate RSD for features

Add NA number for each sample to sample_info.

Add NA frequency for each sample to sample_info

Add NA number for each sample to sample_info.

Add NA frequency for each sample to sample_info

Add NA number for each feature to variable_info

Add NA number for each feature to variable_info

Add NA number for each feature to variable_info

Add NA number for each feature to variable_info

mutate_mean_intensity(object, according_to_samples = "all", na.rm = TRUE)

mutate_median_intensity(object, according_to_samples = "all", na.rm = TRUE)

mutate_rsd(object, according_to_samples = "all")

mutate_sample_na_number(object, according_to_variables = "all")

mutate_sample_na_freq(object, according_to_variables = "all")

mutate_sample_zero_number(object, according_to_variables = "all")

mutate_sample_zero_freq(object, according_to_variables = "all")

mutate_variable_na_number(object, according_to_samples = "all")

mutate_variable_na_freq(object, according_to_samples = "all")

mutate_variable_zero_number(object, according_to_samples = "all")

mutate_variable_zero_freq(object, according_to_samples = "all")

Arguments

object

(required) mass_dataset class object.

according_to_samples

(required) What samples used to calculate NA number or percentage. Default is "all". If you want to use only several samples, provide their names as a vector.

na.rm

na.rm

according_to_variables

(required) What variables used to calculate NA number or percentage. Default is "all". If you want to use only several variables, provide their names as a vector.

Value

A mass_dataset class object.

A mass_dataset class object

A mass_data class object.

A mass_dataset class object

A mass_dataset class object

A mass_dataset class object

A mass_dataset class object

A mass_dataset class object

A mass_dataset class object

A mass_dataset class object

A mass_dataset class object

Author

Xiaotao Shen shenxt1990@outlook.com

Examples

data("expression_data")
data("sample_info")
data("variable_info")

object =
  create_mass_dataset(
    expression_data = expression_data,
    sample_info = sample_info,
    variable_info = variable_info,
  )

object
#> -------------------- 
#> massdataset version: 1.0.27 
#> -------------------- 
#> 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() 2023-10-01 14:00:40

##calculate mean intensity according to all the samples
object2 =
  mutate_mean_intensity(object = object, na.rm = TRUE)

object2
#> -------------------- 
#> massdataset version: 1.0.27 
#> -------------------- 
#> 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 4 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:[ 4 x 2 data.frame]
#> 6.ms2_data:[ 0 variables x 0 MS2 spectra]
#> -------------------- 
#> Processing information
#> 2 processings in total
#> create_mass_dataset ---------- 
#>       Package         Function.used                Time
#> 1 massdataset create_mass_dataset() 2023-10-01 14:00:40
#> mutate_mean_intensity ---------- 
#>       Package           Function.used                Time
#> 1 massdataset mutate_mean_intensity() 2023-10-01 14:00:40

head(extract_variable_info(object))
#>     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
head(extract_variable_info(object2))
#>                 variable_id        mz        rt mean_intensity
#> M136T55_2_POS M136T55_2_POS 136.06140  54.97902      1808605.7
#> M79T35_POS       M79T35_POS  79.05394  35.36550      2671173.4
#> M307T548_POS   M307T548_POS 307.14035 547.56641       276256.3
#> M183T224_POS   M183T224_POS 183.06209 224.32777      5103244.9
#> M349T47_POS     M349T47_POS 349.01584  47.00262      6789862.4
#> M182T828_POS   M182T828_POS 181.99775 828.35712      4326865.8

##calculate mean intensity according to only QC samples
object3 =
  mutate_mean_intensity(object = object2,
                according_to_samples =
              get_sample_id(object)[extract_sample_info(object)$class == "QC"])

object3
#> -------------------- 
#> massdataset version: 1.0.27 
#> -------------------- 
#> 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 5 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:[ 5 x 2 data.frame]
#> 6.ms2_data:[ 0 variables x 0 MS2 spectra]
#> -------------------- 
#> Processing information
#> 2 processings in total
#> create_mass_dataset ---------- 
#>       Package         Function.used                Time
#> 1 massdataset create_mass_dataset() 2023-10-01 14:00:40
#> mutate_mean_intensity ---------- 
#>       Package           Function.used                       Time
#> 1 massdataset mutate_mean_intensity() 2023-10-01 14:00:40.571995
#> 2 massdataset mutate_mean_intensity() 2023-10-01 14:00:40.598109

head(extract_variable_info(object3))
#>                 variable_id        mz        rt mean_intensity mean_intensity.1
#> M136T55_2_POS M136T55_2_POS 136.06140  54.97902      1808605.7        1447844.3
#> M79T35_POS       M79T35_POS  79.05394  35.36550      2671173.4        2063212.8
#> M307T548_POS   M307T548_POS 307.14035 547.56641       276256.3         342037.7
#> M183T224_POS   M183T224_POS 183.06209 224.32777      5103244.9              NaN
#> M349T47_POS     M349T47_POS 349.01584  47.00262      6789862.4        6417851.6
#> M182T828_POS   M182T828_POS 181.99775 828.35712      4326865.8        3662819.1
###remain variables with mean intensity (QC) /  mean intensity (Blank) > 3
qc_sample_name =
  get_sample_id(object)[extract_sample_info(object)$class == "QC"]
blank_sample_name =
  get_sample_id(object)[extract_sample_info(object)$class == "Blank"]

object4 =
object %>%
  mutate_mean_intensity(according_to_samples = qc_sample_name,
                        na.rm = TRUE) %>%
  mutate_mean_intensity(according_to_samples = blank_sample_name,
                        na.rm = TRUE) %>%
  activate_mass_dataset(what = "variable_info") %>%
  mutate(mean_intensity.1 = case_when(
    is.na(mean_intensity.1) ~ 0,
    TRUE ~ mean_intensity.1
  )) %>%
  mutate(mean_intensity = case_when(
    is.na(mean_intensity) ~ 0,
    TRUE ~ mean_intensity
  )) %>%
  mutate(qc_blank_ratio = mean_intensity.1 / mean_intensity) %>%
  mutate(qc_blank_ratio = case_when(
    is.na(qc_blank_ratio) ~ 0,
    TRUE ~ qc_blank_ratio
  )) %>%
  filter(qc_blank_ratio > 3)

object4
#> -------------------- 
#> massdataset version: 1.0.27 
#> -------------------- 
#> 1.expression_data:[ 144 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:[ 144 x 6 data.frame]
#> 144 variables:M317T1035_POS M355T511_POS M270T586_POS ... M159T907_POS M172T916_POS
#> 4.sample_info_note:[ 4 x 2 data.frame]
#> 5.variable_info_note:[ 6 x 2 data.frame]
#> 6.ms2_data:[ 0 variables x 0 MS2 spectra]
#> -------------------- 
#> Processing information
#> 4 processings in total
#> create_mass_dataset ---------- 
#>       Package         Function.used                Time
#> 1 massdataset create_mass_dataset() 2023-10-01 14:00:40
#> mutate_mean_intensity ---------- 
#>       Package           Function.used                       Time
#> 1 massdataset mutate_mean_intensity() 2023-10-01 14:00:40.621658
#> 2 massdataset mutate_mean_intensity() 2023-10-01 14:00:40.636038
#> mutate ---------- 
#>       Package Function.used                       Time
#> 1 massdataset      mutate()  2023-10-01 14:00:40.65044
#> 2 massdataset      mutate() 2023-10-01 14:00:40.654718
#> 3 massdataset      mutate() 2023-10-01 14:00:40.659465
#> 4 massdataset      mutate() 2023-10-01 14:00:40.664817
#> filter ---------- 
#>       Package Function.used                Time
#> 1 massdataset      filter() 2023-10-01 14:00:40
object4 %>%
  extract_variable_info()
#>                     variable_id        mz         rt mean_intensity
#> M317T1035_POS     M317T1035_POS 316.98431 1034.84997           0.00
#> M355T511_POS       M355T511_POS 355.14057  510.77341           0.00
#> M270T586_POS       M270T586_POS 270.15293  585.84412           0.00
#> M297T826_POS       M297T826_POS 296.97977  826.48639           0.00
#> M102T310_POS       M102T310_POS 102.09111  309.99429           0.00
#> M288T32_POS         M288T32_POS 287.91101   32.38870           0.00
#> M343T415_POS       M343T415_POS 343.08142  415.20071           0.00
#> M340T611_POS       M340T611_POS 340.17983  610.92194           0.00
#> M224T34_POS         M224T34_POS 223.94330   33.89216           0.00
#> M325T33_POS         M325T33_POS 324.92931   32.65797           0.00
#> M293T559_POS       M293T559_POS 293.17128  559.48651           0.00
#> M169T33_POS         M169T33_POS 168.97938   33.26004           0.00
#> M233T34_1_POS     M233T34_1_POS 233.00991   34.19781           0.00
#> M104T1036_POS     M104T1036_POS 104.07047 1035.85997           0.00
#> M259T522_POS       M259T522_POS 259.16779  521.98340           0.00
#> M205T34_2_POS     M205T34_2_POS 204.99926   33.56249           0.00
#> M178T54_POS         M178T54_POS 178.00991   54.49800     8123950.28
#> M193T164_POS       M193T164_POS 192.97888  164.14429           0.00
#> M183T821_POS       M183T821_POS 182.98231  820.53082           0.00
#> M217T829_POS       M217T829_POS 217.19441  829.27887           0.00
#> M312T436_POS       M312T436_POS 312.24952  436.36490           0.00
#> M201T33_POS         M201T33_POS 200.99608   32.95857           0.00
#> M100T38_POS         M100T38_POS  99.97840   37.87358           0.00
#> M154T60_POS         M154T60_POS 153.97879   60.17500           0.00
#> M180T33_POS         M180T33_POS 179.97791   32.95857           0.00
#> M231T531_POS       M231T531_POS 231.17326  531.31525           0.00
#> M199T120_POS       M199T120_POS 199.00070  119.91092           0.00
#> M161T1024_1_POS M161T1024_1_POS 161.00031 1023.56997           0.00
#> M265T428_POS       M265T428_POS 265.18709  427.92566       97164.46
#> M248T34_POS         M248T34_POS 247.96430   33.89216           0.00
#> M292T34_POS         M292T34_POS 291.94954   34.16998           0.00
#> M261T829_1_POS   M261T829_1_POS 261.00909  829.46042      348637.28
#> M183T34_1_POS     M183T34_1_POS 182.99510   33.70049           0.00
#> M179T535_POS       M179T535_POS 179.07614  535.12622           0.00
#> M164T1036_POS     M164T1036_POS 163.98726 1036.18997           0.00
#> M351T467_POS       M351T467_POS 351.14741  467.13400           0.00
#> M102T112_POS       M102T112_POS 102.09119  111.92390           0.00
#> M178T968_2_POS   M178T968_2_POS 178.00998  967.70428           0.00
#> M241T822_POS       M241T822_POS 241.06738  822.17419           0.00
#> M192T122_POS       M192T122_POS 191.97117  122.43882           0.00
#> M195T155_POS       M195T155_POS 195.09274  155.12875           0.00
#> M136T909_POS       M136T909_POS 135.99948  909.14572           0.00
#> M249T33_POS         M249T33_POS 248.99771   32.95857           0.00
#> M305T225_POS       M305T225_POS 305.12567  225.32370           0.00
#> M167T402_POS       M167T402_POS 167.06997  401.73358      715970.92
#> M323T643_POS       M323T643_POS 323.12232  643.12091           0.00
#> M317T1008_POS     M317T1008_POS 316.98441 1007.75222      405656.23
#> M232T235_POS       M232T235_POS 232.05674  234.67485      311509.18
#> M133T103_POS       M133T103_POS 132.95810  103.12468           0.00
#> M74T146_POS         M74T146_POS  74.09637  145.82797           0.00
#> M106T33_POS         M106T33_POS 105.96361   32.95857           0.00
#> M313T481_POS       M313T481_POS 313.13986  480.83691           0.00
#> M95T1017_POS       M95T1017_POS  95.08536 1017.01251           0.00
#> M141T80_POS         M141T80_POS 141.07129   79.54538           0.00
#> M153T353_POS       M153T353_POS 153.00479  353.41220           0.00
#> M173T866_POS       M173T866_POS 172.97485  866.12396           0.00
#> M99T89_POS           M99T89_POS  99.08028   89.06227           0.00
#> M323T658_POS       M323T658_POS 323.15820  657.52545           0.00
#> M216T61_POS         M216T61_POS 215.99487   61.31047           0.00
#> M160T33_1_POS     M160T33_1_POS 159.96965   32.65797           0.00
#> M164T426_POS       M164T426_POS 164.03054  425.64816    34100870.56
#> M160T1010_POS     M160T1010_POS 159.99923 1010.42261           0.00
#> M237T464_POS       M237T464_POS 237.12704  463.65128           0.00
#> M314T471_POS       M314T471_POS 314.16304  470.54288           0.00
#> M359T481_POS       M359T481_POS 359.11526  480.64351           0.00
#> M117T1034_POS     M117T1034_POS 116.98565 1033.91997           0.00
#> M193T104_POS       M193T104_POS 192.97900  103.90944           0.00
#> M167T461_1_POS   M167T461_1_POS 167.06719  460.94473           0.00
#> M354T637_1_POS   M354T637_1_POS 354.23080  636.98621           0.00
#> M215T829_1_POS   M215T829_1_POS 214.97743  828.91132           0.00
#> M211T38_POS         M211T38_POS 210.96743   37.91269           0.00
#> M233T33_POS         M233T33_POS 232.99380   33.42523           0.00
#> M333T36_POS         M333T36_POS 332.96835   36.35993           0.00
#> M173T55_1_POS     M173T55_1_POS 172.99221   54.58524           0.00
#> M287T828_POS       M287T828_POS 287.01774  828.22208     4509238.10
#> M148T705_POS       M148T705_POS 148.05078  705.42828           0.00
#> M173T94_POS         M173T94_POS 173.01185   94.03935           0.00
#> M184T102_POS       M184T102_POS 184.04512  102.23300           0.00
#> M187T91_POS         M187T91_POS 187.00766   90.78848           0.00
#> M158T973_POS       M158T973_POS 157.97441  972.52249           0.00
#> M213T497_POS       M213T497_POS 213.00415  496.90598           0.00
#> M102T925_POS       M102T925_POS 102.09109  924.68045           0.00
#> M361T510_POS       M361T510_POS 361.15921  510.06927           0.00
#> M160T33_2_POS     M160T33_2_POS 159.98197   32.95857           0.00
#> M145T40_1_POS     M145T40_1_POS 144.99743   40.33353           0.00
#> M201T930_POS       M201T930_POS 201.02267  930.13623           0.00
#> M141T271_POS       M141T271_POS 141.07128  271.36676           0.00
#> M325T520_POS       M325T520_POS 325.13785  520.38269      825215.83
#> M246T221_POS       M246T221_POS 246.10861  221.40201           0.00
#> M187T154_POS       M187T154_POS 187.00765  153.82877           0.00
#> M156T165_POS       M156T165_POS 155.97397  165.08819           0.00
#> M183T49_POS         M183T49_POS 183.02410   48.93789           0.00
#> M271T448_POS       M271T448_POS 271.15266  447.93579           0.00
#> M250T481_POS       M250T481_POS 250.17661  481.03885    17019566.43
#> M261T522_POS       M261T522_POS 261.18150  521.75232           0.00
#> M360T547_POS       M360T547_POS 360.22115  546.53815           0.00
#> M192T150_POS       M192T150_POS 191.97627  150.17074           0.00
#> M282T481_POS       M282T481_POS 282.20261  480.71379    11364551.57
#> M172T33_POS         M172T33_POS 171.98932   32.95857           0.00
#> M359T33_POS         M359T33_POS 358.84215   32.52293           0.00
#> M200T37_POS         M200T37_POS 200.02223   37.19968           0.00
#> M252T192_POS       M252T192_POS 252.04628  192.37624           0.00
#> M341T605_2_POS   M341T605_2_POS 341.39605  604.66263           0.00
#> M195T75_1_POS     M195T75_1_POS 194.97944   74.73264           0.00
#> M151T546_POS       M151T546_POS 151.00498  546.37540     3348781.68
#> M162T33_POS         M162T33_POS 161.96736   32.65797           0.00
#> M200T488_POS       M200T488_POS 200.17202  488.12100           0.00
#> M166T737_POS       M166T737_POS 166.09402  736.74915           0.00
#> M185T1004_POS     M185T1004_POS 185.01938 1004.23590           0.00
#> M153T33_1_POS     M153T33_1_POS 152.96912   33.09496           0.00
#> M175T104_POS       M175T104_POS 174.97963  103.73222           0.00
#> M220T963_POS       M220T963_POS 220.02006  963.31354           0.00
#> M226T536_POS       M226T536_POS 226.09662  535.79327           0.00
#> M273T829_2_POS   M273T829_2_POS 273.25638  829.27887           0.00
#> M126T826_POS       M126T826_POS 126.12746  826.33936           0.00
#> M305T34_1_POS     M305T34_1_POS 304.94916   33.71391      118631.41
#> M197T933_POS       M197T933_POS 196.99989  932.58405     5881674.72
#> M95T918_POS         M95T918_POS  95.08532  918.17102           0.00
#> M149T694_POS       M149T694_POS 149.02295  694.02527           0.00
#> M196T179_POS       M196T179_POS 196.00222  178.80635           0.00
#> M301T544_POS       M301T544_POS 301.17615  544.49435           0.00
#> M167T270_POS       M167T270_POS 167.06854  269.85345           0.00
#> M185T961_POS       M185T961_POS 185.01579  961.07852           0.00
#> M229T33_2_POS     M229T33_2_POS 229.01499   33.42523           0.00
#> M103T534_POS       M103T534_POS 103.00632  534.36121    13445378.54
#> M72T34_POS           M72T34_POS  71.92866   33.50882           0.00
#> M210T203_POS       M210T203_POS 210.01770  202.93176           0.00
#> M333T526_POS       M333T526_POS 333.16565  526.45145           0.00
#> M176T32_POS         M176T32_POS 175.98469   32.40417     4443308.21
#> M235T92_POS         M235T92_POS 234.98957   92.36749           0.00
#> M181T204_POS       M181T204_POS 181.03052  204.29840      800621.26
#> M195T1035_POS     M195T1035_POS 194.97909 1035.16997           0.00
#> M362T827_POS       M362T827_POS 361.93258  827.00286      114210.45
#> M333T563_POS       M333T563_POS 333.17906  563.24689           0.00
#> M293T530_POS       M293T530_POS 293.17292  530.19983           0.00
#> M164T210_POS       M164T210_POS 164.03058  210.35624    12150849.08
#> M359T539_POS       M359T539_POS 359.36947  538.65298           0.00
#> M161T1012_POS     M161T1012_POS 161.00040 1011.90338           0.00
#> M326T519_POS       M326T519_POS 326.37694  519.15479           0.00
#> M251T509_POS       M251T509_POS 251.19720  509.40466           0.00
#> M301T34_1_POS     M301T34_1_POS 300.90872   33.61617           0.00
#> M253T830_2_POS   M253T830_2_POS 253.02032  829.69879     1922198.26
#> M159T907_POS       M159T907_POS 159.00689  907.19733           0.00
#> M172T916_POS       M172T916_POS 171.96517  916.47171           0.00
#>                 mean_intensity.1 qc_blank_ratio
#> M317T1035_POS         1589593.87            Inf
#> M355T511_POS           125532.88            Inf
#> M270T586_POS           175169.64            Inf
#> M297T826_POS           421410.38            Inf
#> M102T310_POS          3706367.91            Inf
#> M288T32_POS           7041231.86            Inf
#> M343T415_POS           104459.94            Inf
#> M340T611_POS           692102.74            Inf
#> M224T34_POS           1249987.39            Inf
#> M325T33_POS           8245924.53            Inf
#> M293T559_POS          1931033.26            Inf
#> M169T33_POS          13239755.94            Inf
#> M233T34_1_POS         2202366.37            Inf
#> M104T1036_POS          682326.04            Inf
#> M259T522_POS          1778856.90            Inf
#> M205T34_2_POS        28369003.40            Inf
#> M178T54_POS          48761266.62       6.002162
#> M193T164_POS         12657903.77            Inf
#> M183T821_POS           258769.55            Inf
#> M217T829_POS           483984.23            Inf
#> M312T436_POS           252062.89            Inf
#> M201T33_POS          14437236.68            Inf
#> M100T38_POS           7100827.97            Inf
#> M154T60_POS          12637719.38            Inf
#> M180T33_POS          15610247.24            Inf
#> M231T531_POS           689831.72            Inf
#> M199T120_POS          4562978.53            Inf
#> M161T1024_1_POS       1715204.92            Inf
#> M265T428_POS          1614838.48      16.619642
#> M248T34_POS            979718.49            Inf
#> M292T34_POS            909575.35            Inf
#> M261T829_1_POS        2055234.90       5.895052
#> M183T34_1_POS         1847383.90            Inf
#> M179T535_POS         13635502.84            Inf
#> M164T1036_POS          424728.36            Inf
#> M351T467_POS            81056.64            Inf
#> M102T112_POS         22054068.30            Inf
#> M178T968_2_POS       21389765.66            Inf
#> M241T822_POS          1724941.73            Inf
#> M192T122_POS        495938567.21            Inf
#> M195T155_POS          4683161.49            Inf
#> M136T909_POS         13447802.47            Inf
#> M249T33_POS           3305877.21            Inf
#> M305T225_POS            60378.24            Inf
#> M167T402_POS          3253105.52       4.543628
#> M323T643_POS           311837.38            Inf
#> M317T1008_POS         3059302.39       7.541613
#> M232T235_POS          3898892.53      12.516140
#> M133T103_POS         62498508.02            Inf
#> M74T146_POS           7315628.52            Inf
#> M106T33_POS           5152620.80            Inf
#> M313T481_POS          1730513.49            Inf
#> M95T1017_POS          2100708.97            Inf
#> M141T80_POS           2227386.88            Inf
#> M153T353_POS         13233809.33            Inf
#> M173T866_POS          7286010.44            Inf
#> M99T89_POS            1981797.35            Inf
#> M323T658_POS          2281229.49            Inf
#> M216T61_POS          29824980.50            Inf
#> M160T33_1_POS        82861899.00            Inf
#> M164T426_POS        118641296.15       3.479128
#> M160T1010_POS         9290642.32            Inf
#> M237T464_POS            92886.66            Inf
#> M314T471_POS           309761.57            Inf
#> M359T481_POS            84515.31            Inf
#> M117T1034_POS       397365097.11            Inf
#> M193T104_POS        125445310.20            Inf
#> M167T461_1_POS        1367153.98            Inf
#> M354T637_1_POS         326502.92            Inf
#> M215T829_1_POS        2204549.53            Inf
#> M211T38_POS           2266744.70            Inf
#> M233T33_POS           8647145.41            Inf
#> M333T36_POS           1216438.57            Inf
#> M173T55_1_POS        17846337.80            Inf
#> M287T828_POS         14286940.76       3.168371
#> M148T705_POS          5255395.10            Inf
#> M173T94_POS           1100997.79            Inf
#> M184T102_POS          1684119.12            Inf
#> M187T91_POS          14633154.61            Inf
#> M158T973_POS         17187569.47            Inf
#> M213T497_POS         24266118.74            Inf
#> M102T925_POS         12252054.39            Inf
#> M361T510_POS           210483.79            Inf
#> M160T33_2_POS         4041697.03            Inf
#> M145T40_1_POS         4448727.42            Inf
#> M201T930_POS          9330131.57            Inf
#> M141T271_POS          3268042.17            Inf
#> M325T520_POS          2754628.69       3.338071
#> M246T221_POS           127934.38            Inf
#> M187T154_POS          9912862.44            Inf
#> M156T165_POS         24097429.22            Inf
#> M183T49_POS          17916278.77            Inf
#> M271T448_POS          1629170.56            Inf
#> M250T481_POS         58187874.06       3.418881
#> M261T522_POS           988088.70            Inf
#> M360T547_POS           440523.13            Inf
#> M192T150_POS         57361084.45            Inf
#> M282T481_POS         39022312.14       3.433687
#> M172T33_POS          75527416.31            Inf
#> M359T33_POS           8317512.63            Inf
#> M200T37_POS           3104648.18            Inf
#> M252T192_POS          1760546.26            Inf
#> M341T605_2_POS        1376759.16            Inf
#> M195T75_1_POS         8664373.57            Inf
#> M151T546_POS         16226658.36       4.845541
#> M162T33_POS          10428428.93            Inf
#> M200T488_POS           273025.26            Inf
#> M166T737_POS          3890542.47            Inf
#> M185T1004_POS         3630130.16            Inf
#> M153T33_1_POS        35097582.78            Inf
#> M175T104_POS          9755350.21            Inf
#> M220T963_POS          7401092.99            Inf
#> M226T536_POS           372160.83            Inf
#> M273T829_2_POS         404811.79            Inf
#> M126T826_POS           164848.88            Inf
#> M305T34_1_POS         1600901.28      13.494751
#> M197T933_POS         22114522.68       3.759902
#> M95T918_POS           1585287.50            Inf
#> M149T694_POS          5423565.01            Inf
#> M196T179_POS          6956064.34            Inf
#> M301T544_POS         26094367.81            Inf
#> M167T270_POS          2056951.33            Inf
#> M185T961_POS          2101928.86            Inf
#> M229T33_2_POS         2677465.77            Inf
#> M103T534_POS         43250685.25       3.216770
#> M72T34_POS             468329.27            Inf
#> M210T203_POS         29742563.05            Inf
#> M333T526_POS          2922955.53            Inf
#> M176T32_POS         321650414.47      72.389850
#> M235T92_POS          11471894.29            Inf
#> M181T204_POS         58478294.50      73.041146
#> M195T1035_POS         2482562.36            Inf
#> M362T827_POS           448563.95       3.927521
#> M333T563_POS            37968.16            Inf
#> M293T530_POS          2111122.64            Inf
#> M164T210_POS         48792496.72       4.015563
#> M359T539_POS           253846.58            Inf
#> M161T1012_POS          776518.02            Inf
#> M326T519_POS           490420.09            Inf
#> M251T509_POS          1408886.26            Inf
#> M301T34_1_POS          603205.06            Inf
#> M253T830_2_POS        8362385.71       4.350428
#> M159T907_POS          8756452.51            Inf
#> M172T916_POS          2360169.30            Inf
data("expression_data")
data("sample_info")
data("variable_info")

object =
  create_mass_dataset(
    expression_data = expression_data,
    sample_info = sample_info,
    variable_info = variable_info,
  )

object
#> -------------------- 
#> massdataset version: 1.0.27 
#> -------------------- 
#> 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() 2023-10-01 14:00:40

##calculate median intensity according to all the samples
object2 =
  mutate_median_intensity(object = object, na.rm = TRUE)

object2
#> -------------------- 
#> massdataset version: 1.0.27 
#> -------------------- 
#> 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 4 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:[ 4 x 2 data.frame]
#> 6.ms2_data:[ 0 variables x 0 MS2 spectra]
#> -------------------- 
#> Processing information
#> 2 processings in total
#> create_mass_dataset ---------- 
#>       Package         Function.used                Time
#> 1 massdataset create_mass_dataset() 2023-10-01 14:00:40
#> mutate_median_intensity ---------- 
#>       Package             Function.used                Time
#> 1 massdataset mutate_median_intensity() 2023-10-01 14:00:40

head(extract_variable_info(object))
#>     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
head(extract_variable_info(object2))
#>                 variable_id        mz        rt median_intensity
#> M136T55_2_POS M136T55_2_POS 136.06140  54.97902        1676180.4
#> M79T35_POS       M79T35_POS  79.05394  35.36550        2777897.0
#> M307T548_POS   M307T548_POS 307.14035 547.56641         273687.8
#> M183T224_POS   M183T224_POS 183.06209 224.32777        5103244.9
#> M349T47_POS     M349T47_POS 349.01584  47.00262        7169041.1
#> M182T828_POS   M182T828_POS 181.99775 828.35712        4433034.2

##calculate median intensity according to only QC samples
object3 =
  mutate_median_intensity(object = object2,
                according_to_samples =
              get_sample_id(object)[extract_sample_info(object)$class == "QC"])

object3
#> -------------------- 
#> massdataset version: 1.0.27 
#> -------------------- 
#> 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 5 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:[ 5 x 2 data.frame]
#> 6.ms2_data:[ 0 variables x 0 MS2 spectra]
#> -------------------- 
#> Processing information
#> 2 processings in total
#> create_mass_dataset ---------- 
#>       Package         Function.used                Time
#> 1 massdataset create_mass_dataset() 2023-10-01 14:00:40
#> mutate_median_intensity ---------- 
#>       Package             Function.used                       Time
#> 1 massdataset mutate_median_intensity() 2023-10-01 14:00:40.764494
#> 2 massdataset mutate_median_intensity()  2023-10-01 14:00:40.80526

head(extract_variable_info(object3))
#>                 variable_id        mz        rt median_intensity
#> M136T55_2_POS M136T55_2_POS 136.06140  54.97902        1676180.4
#> M79T35_POS       M79T35_POS  79.05394  35.36550        2777897.0
#> M307T548_POS   M307T548_POS 307.14035 547.56641         273687.8
#> M183T224_POS   M183T224_POS 183.06209 224.32777        5103244.9
#> M349T47_POS     M349T47_POS 349.01584  47.00262        7169041.1
#> M182T828_POS   M182T828_POS 181.99775 828.35712        4433034.2
#>               median_intensity.1
#> M136T55_2_POS          1447844.3
#> M79T35_POS             2063212.8
#> M307T548_POS            342037.7
#> M183T224_POS                  NA
#> M349T47_POS            6417851.6
#> M182T828_POS           3662819.1
data("expression_data")
data("sample_info")
data("variable_info")

object =
  create_mass_dataset(
    expression_data = expression_data,
    sample_info = sample_info,
    variable_info = variable_info,
  )

object
#> -------------------- 
#> massdataset version: 1.0.27 
#> -------------------- 
#> 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() 2023-10-01 14:00:40

##calculate RSDs according to all the samples
object =
  mutate_rsd(object = object)

object
#> -------------------- 
#> massdataset version: 1.0.27 
#> -------------------- 
#> 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 4 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:[ 4 x 2 data.frame]
#> 6.ms2_data:[ 0 variables x 0 MS2 spectra]
#> -------------------- 
#> Processing information
#> 2 processings in total
#> create_mass_dataset ---------- 
#>       Package         Function.used                Time
#> 1 massdataset create_mass_dataset() 2023-10-01 14:00:40
#> mutate_rsd ---------- 
#>       Package Function.used                Time
#> 1 massdataset  mutate_rsd() 2023-10-01 14:00:40

head(extract_variable_info(object))
#>                 variable_id        mz        rt       rsd
#> M136T55_2_POS M136T55_2_POS 136.06140  54.97902 50.756560
#> M79T35_POS       M79T35_POS  79.05394  35.36550 28.257007
#> M307T548_POS   M307T548_POS 307.14035 547.56641 35.041286
#> M183T224_POS   M183T224_POS 183.06209 224.32777  1.224228
#> M349T47_POS     M349T47_POS 349.01584  47.00262 27.715030
#> M182T828_POS   M182T828_POS 181.99775 828.35712 25.534063

##calculate RSDs according to only QC samples
object =
  mutate_rsd(object = object,
                according_to_samples =
              get_sample_id(object)[extract_sample_info(object)$class == "QC"])

object
#> -------------------- 
#> massdataset version: 1.0.27 
#> -------------------- 
#> 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 5 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:[ 5 x 2 data.frame]
#> 6.ms2_data:[ 0 variables x 0 MS2 spectra]
#> -------------------- 
#> Processing information
#> 2 processings in total
#> create_mass_dataset ---------- 
#>       Package         Function.used                Time
#> 1 massdataset create_mass_dataset() 2023-10-01 14:00:40
#> mutate_rsd ---------- 
#>       Package Function.used                       Time
#> 1 massdataset  mutate_rsd() 2023-10-01 14:00:40.846596
#> 2 massdataset  mutate_rsd() 2023-10-01 14:00:40.872842

head(extract_variable_info(object))
#>                 variable_id        mz        rt       rsd    rsd.1
#> M136T55_2_POS M136T55_2_POS 136.06140  54.97902 50.756560 40.05551
#> M79T35_POS       M79T35_POS  79.05394  35.36550 28.257007 51.97966
#> M307T548_POS   M307T548_POS 307.14035 547.56641 35.041286 28.26044
#> M183T224_POS   M183T224_POS 183.06209 224.32777  1.224228       NA
#> M349T47_POS     M349T47_POS 349.01584  47.00262 27.715030 50.95194
#> M182T828_POS   M182T828_POS 181.99775 828.35712 25.534063       NA
data("expression_data")
data("sample_info")
data("variable_info")

object =
  create_mass_dataset(
    expression_data = expression_data,
    sample_info = sample_info,
    variable_info = variable_info
  )

object
#> -------------------- 
#> massdataset version: 1.0.27 
#> -------------------- 
#> 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() 2023-10-01 14:00:40

##calculate NA number according to all the variables
object2 =
  mutate_sample_na_number(object = object)

colnames(extract_sample_info(object))
#> [1] "sample_id"       "injection.order" "class"           "group"          
colnames(extract_sample_info(object2))
#> [1] "sample_id"       "injection.order" "class"           "group"          
#> [5] "na_number"      
object2@sample_info_note
#>              name         meaning
#> 1       sample_id       sample_id
#> 2 injection.order injection.order
#> 3           class           class
#> 4           group           group
#> 5       na_number       na_number

##calculate NA number according to only variables with mz > 100
variable_id =
object2 %>%
  activate_mass_dataset(what = "variable_info") %>%
  filter(mz > 100) %>%
  pull(variable_id)

object3 =
  mutate_sample_na_number(object = object2,
                according_to_variables = variable_id)

object3
#> -------------------- 
#> massdataset version: 1.0.27 
#> -------------------- 
#> 1.expression_data:[ 1000 x 8 data.frame]
#> 2.sample_info:[ 8 x 6 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:[ 6 x 2 data.frame]
#> 5.variable_info_note:[ 3 x 2 data.frame]
#> 6.ms2_data:[ 0 variables x 0 MS2 spectra]
#> -------------------- 
#> Processing information
#> 2 processings in total
#> create_mass_dataset ---------- 
#>       Package         Function.used                Time
#> 1 massdataset create_mass_dataset() 2023-10-01 14:00:40
#> mutate_sample_na_number ---------- 
#>       Package             Function.used                       Time
#> 1 massdataset mutate_sample_na_number() 2023-10-01 14:00:40.901413
#> 2 massdataset mutate_sample_na_number() 2023-10-01 14:00:40.914953

head(extract_sample_info(object3))
#>   sample_id injection.order   class   group na_number na_number.1
#> 1   Blank_3               1   Blank   Blank       682         667
#> 2   Blank_4               2   Blank   Blank       702         687
#> 3      QC_1               3      QC      QC       397         385
#> 4      QC_2               4      QC      QC       381         372
#> 5     PS4P1               5 Subject Subject       424         411
#> 6     PS4P2               6 Subject Subject       427         414
data("expression_data")
data("sample_info")
data("variable_info")

object =
  create_mass_dataset(
    expression_data = expression_data,
    sample_info = sample_info,
    variable_info = variable_info
  )

object
#> -------------------- 
#> massdataset version: 1.0.27 
#> -------------------- 
#> 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() 2023-10-01 14:00:40

##calculate NA frequency according to all the variables
object2 =
  mutate_sample_na_freq(object = object)

head(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
head(extract_sample_info(object2))
#>   sample_id injection.order   class   group na_freq
#> 1   Blank_3               1   Blank   Blank   0.682
#> 2   Blank_4               2   Blank   Blank   0.702
#> 3      QC_1               3      QC      QC   0.397
#> 4      QC_2               4      QC      QC   0.381
#> 5     PS4P1               5 Subject Subject   0.424
#> 6     PS4P2               6 Subject Subject   0.427

##calculate NA frequency according to only variables with mz > 100
variable_id =
object2 %>%
  activate_mass_dataset(what = "variable_info") %>%
  filter(mz > 100) %>%
  pull(variable_id)

object3 =
  mutate_sample_na_freq(object = object2,
                according_to_variables = variable_id)

object3
#> -------------------- 
#> massdataset version: 1.0.27 
#> -------------------- 
#> 1.expression_data:[ 1000 x 8 data.frame]
#> 2.sample_info:[ 8 x 6 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:[ 6 x 2 data.frame]
#> 5.variable_info_note:[ 3 x 2 data.frame]
#> 6.ms2_data:[ 0 variables x 0 MS2 spectra]
#> -------------------- 
#> Processing information
#> 2 processings in total
#> create_mass_dataset ---------- 
#>       Package         Function.used                Time
#> 1 massdataset create_mass_dataset() 2023-10-01 14:00:40
#> mutate_sample_na_freq ---------- 
#>       Package           Function.used                       Time
#> 1 massdataset mutate_sample_na_freq() 2023-10-01 14:00:40.942775
#> 2 massdataset mutate_sample_na_freq() 2023-10-01 14:00:40.954041

head(extract_sample_info(object3))
#>   sample_id injection.order   class   group na_freq na_freq.1
#> 1   Blank_3               1   Blank   Blank   0.682 0.6834016
#> 2   Blank_4               2   Blank   Blank   0.702 0.7038934
#> 3      QC_1               3      QC      QC   0.397 0.3944672
#> 4      QC_2               4      QC      QC   0.381 0.3811475
#> 5     PS4P1               5 Subject Subject   0.424 0.4211066
#> 6     PS4P2               6 Subject Subject   0.427 0.4241803
data("expression_data")
data("sample_info")
data("variable_info")

object =
  create_mass_dataset(
    expression_data = expression_data,
    sample_info = sample_info,
    variable_info = variable_info
  )

object
#> -------------------- 
#> massdataset version: 1.0.27 
#> -------------------- 
#> 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() 2023-10-01 14:00:40

##calculate NA number according to all the variables
object2 =
  mutate_sample_zero_number(object = object)

colnames(extract_sample_info(object))
#> [1] "sample_id"       "injection.order" "class"           "group"          
colnames(extract_sample_info(object2))
#> [1] "sample_id"       "injection.order" "class"           "group"          
#> [5] "zero_number"    
object2@sample_info_note
#>              name         meaning
#> 1       sample_id       sample_id
#> 2 injection.order injection.order
#> 3           class           class
#> 4           group           group
#> 5     zero_number     zero_number

##calculate NA number according to only variables with mz > 100
variable_id =
object2 %>%
  activate_mass_dataset(what = "variable_info") %>%
  filter(mz > 100) %>%
  pull(variable_id)

object3 =
  mutate_sample_zero_number(object = object2,
                according_to_variables = variable_id)

object3
#> -------------------- 
#> massdataset version: 1.0.27 
#> -------------------- 
#> 1.expression_data:[ 1000 x 8 data.frame]
#> 2.sample_info:[ 8 x 6 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:[ 6 x 2 data.frame]
#> 5.variable_info_note:[ 3 x 2 data.frame]
#> 6.ms2_data:[ 0 variables x 0 MS2 spectra]
#> -------------------- 
#> Processing information
#> 2 processings in total
#> create_mass_dataset ---------- 
#>       Package         Function.used                Time
#> 1 massdataset create_mass_dataset() 2023-10-01 14:00:40
#> mutate_sample_zero_number ---------- 
#>       Package               Function.used                       Time
#> 1 massdataset mutate_sample_zero_number() 2023-10-01 14:00:40.983062
#> 2 massdataset mutate_sample_zero_number() 2023-10-01 14:00:40.994261

head(extract_sample_info(object3))
#>   sample_id injection.order   class   group zero_number zero_number.1
#> 1   Blank_3               1   Blank   Blank          NA            NA
#> 2   Blank_4               2   Blank   Blank          NA            NA
#> 3      QC_1               3      QC      QC          NA            NA
#> 4      QC_2               4      QC      QC          NA            NA
#> 5     PS4P1               5 Subject Subject          NA            NA
#> 6     PS4P2               6 Subject Subject          NA            NA
data("expression_data")
data("sample_info")
data("variable_info")

object =
  create_mass_dataset(
    expression_data = expression_data,
    sample_info = sample_info,
    variable_info = variable_info
  )

object
#> -------------------- 
#> massdataset version: 1.0.27 
#> -------------------- 
#> 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() 2023-10-01 14:00:41

##calculate NA frequency according to all the variables
object2 =
  mutate_sample_zero_freq(object = object)

head(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
head(extract_sample_info(object2))
#>   sample_id injection.order   class   group zero_freq
#> 1   Blank_3               1   Blank   Blank        NA
#> 2   Blank_4               2   Blank   Blank        NA
#> 3      QC_1               3      QC      QC        NA
#> 4      QC_2               4      QC      QC        NA
#> 5     PS4P1               5 Subject Subject        NA
#> 6     PS4P2               6 Subject Subject        NA

##calculate NA frequency according to only variables with mz > 100
variable_id =
object2 %>%
  activate_mass_dataset(what = "variable_info") %>%
  filter(mz > 100) %>%
  pull(variable_id)

object3 =
  mutate_sample_zero_freq(object = object2,
                according_to_variables = variable_id)

object3
#> -------------------- 
#> massdataset version: 1.0.27 
#> -------------------- 
#> 1.expression_data:[ 1000 x 8 data.frame]
#> 2.sample_info:[ 8 x 6 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:[ 6 x 2 data.frame]
#> 5.variable_info_note:[ 3 x 2 data.frame]
#> 6.ms2_data:[ 0 variables x 0 MS2 spectra]
#> -------------------- 
#> Processing information
#> 2 processings in total
#> create_mass_dataset ---------- 
#>       Package         Function.used                Time
#> 1 massdataset create_mass_dataset() 2023-10-01 14:00:41
#> mutate_sample_zero_freq ---------- 
#>       Package             Function.used                       Time
#> 1 massdataset mutate_sample_zero_freq() 2023-10-01 14:00:41.021459
#> 2 massdataset mutate_sample_zero_freq() 2023-10-01 14:00:41.031262

head(extract_sample_info(object3))
#>   sample_id injection.order   class   group zero_freq zero_freq.1
#> 1   Blank_3               1   Blank   Blank        NA          NA
#> 2   Blank_4               2   Blank   Blank        NA          NA
#> 3      QC_1               3      QC      QC        NA          NA
#> 4      QC_2               4      QC      QC        NA          NA
#> 5     PS4P1               5 Subject Subject        NA          NA
#> 6     PS4P2               6 Subject Subject        NA          NA
data("expression_data")
data("sample_info")
data("variable_info")

object =
  create_mass_dataset(
    expression_data = expression_data,
    sample_info = sample_info,
    variable_info = variable_info,
  )

object
#> -------------------- 
#> massdataset version: 1.0.27 
#> -------------------- 
#> 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() 2023-10-01 14:00:41

##calculate NA number according to all the samples
object2 =
  mutate_variable_na_number(object = object)

colnames(extract_variable_info(object))
#> [1] "variable_id" "mz"          "rt"         
colnames(extract_variable_info(object2))
#> [1] "variable_id" "mz"          "rt"          "na_number"  
object2@variable_info_note
#>          name     meaning
#> 1 variable_id variable_id
#> 2          mz          mz
#> 3          rt          rt
#> 4   na_number   na_number

##calculate NA number according to only QC samples
object3 <-
  mutate_variable_na_number(object = object2,
                according_to_samples =
              get_sample_id(object)[extract_sample_info(object)$class == "QC"])

object3
#> -------------------- 
#> massdataset version: 1.0.27 
#> -------------------- 
#> 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 5 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:[ 5 x 2 data.frame]
#> 6.ms2_data:[ 0 variables x 0 MS2 spectra]
#> -------------------- 
#> Processing information
#> 2 processings in total
#> create_mass_dataset ---------- 
#>       Package         Function.used                Time
#> 1 massdataset create_mass_dataset() 2023-10-01 14:00:41
#> mutate_variable_na_number ---------- 
#>       Package               Function.used                       Time
#> 1 massdataset mutate_variable_na_number() 2023-10-01 14:00:41.056656
#> 2 massdataset mutate_variable_na_number() 2023-10-01 14:00:41.064771

colnames(extract_variable_info(object3))
#> [1] "variable_id" "mz"          "rt"          "na_number"   "na_number.1"
object3@variable_info_note
#>          name     meaning
#> 1 variable_id variable_id
#> 2          mz          mz
#> 3          rt          rt
#> 4   na_number   na_number
#> 5 na_number.1 na_number.1
data("expression_data")
data("sample_info")
data("variable_info")

object =
  create_mass_dataset(
    expression_data = expression_data,
    sample_info = sample_info,
    variable_info = variable_info,
  )

object
#> -------------------- 
#> massdataset version: 1.0.27 
#> -------------------- 
#> 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() 2023-10-01 14:00:41

##calculate NA frequency according to all the samples
object2 =
  mutate_variable_na_freq(object = object)

head(extract_variable_info(object))
#>     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
head(extract_variable_info(object2))
#>     variable_id        mz        rt na_freq
#> 1 M136T55_2_POS 136.06140  54.97902   0.250
#> 2    M79T35_POS  79.05394  35.36550   0.250
#> 3  M307T548_POS 307.14035 547.56641   0.375
#> 4  M183T224_POS 183.06209 224.32777   0.750
#> 5   M349T47_POS 349.01584  47.00262   0.250
#> 6  M182T828_POS 181.99775 828.35712   0.125

##calculate NA number according to only QC samples
object3 =
  mutate_variable_na_freq(object = object2,
                according_to_samples =
              get_sample_id(object)[extract_sample_info(object)$class == "QC"])

object3
#> -------------------- 
#> massdataset version: 1.0.27 
#> -------------------- 
#> 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 5 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:[ 5 x 2 data.frame]
#> 6.ms2_data:[ 0 variables x 0 MS2 spectra]
#> -------------------- 
#> Processing information
#> 2 processings in total
#> create_mass_dataset ---------- 
#>       Package         Function.used                Time
#> 1 massdataset create_mass_dataset() 2023-10-01 14:00:41
#> mutate_variable_na_freq ---------- 
#>       Package             Function.used                       Time
#> 1 massdataset mutate_variable_na_freq() 2023-10-01 14:00:41.090454
#> 2 massdataset mutate_variable_na_freq() 2023-10-01 14:00:41.098247

head(extract_variable_info(object3))
#>     variable_id        mz        rt na_freq na_freq.1
#> 1 M136T55_2_POS 136.06140  54.97902   0.250       0.0
#> 2    M79T35_POS  79.05394  35.36550   0.250       0.0
#> 3  M307T548_POS 307.14035 547.56641   0.375       0.0
#> 4  M183T224_POS 183.06209 224.32777   0.750       1.0
#> 5   M349T47_POS 349.01584  47.00262   0.250       0.0
#> 6  M182T828_POS 181.99775 828.35712   0.125       0.5
data("expression_data")
data("sample_info")
data("variable_info")

object =
  create_mass_dataset(
    expression_data = expression_data,
    sample_info = sample_info,
    variable_info = variable_info,
  )

object
#> -------------------- 
#> massdataset version: 1.0.27 
#> -------------------- 
#> 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() 2023-10-01 14:00:41

##calculate NA number according to all the samples
object2 =
  mutate_variable_zero_number(object = object)

colnames(extract_variable_info(object))
#> [1] "variable_id" "mz"          "rt"         
colnames(extract_variable_info(object2))
#> [1] "variable_id" "mz"          "rt"          "zero_number"
object2@variable_info_note
#>          name     meaning
#> 1 variable_id variable_id
#> 2          mz          mz
#> 3          rt          rt
#> 4 zero_number zero_number

##calculate NA number according to only QC samples
object3 <-
  mutate_variable_zero_number(object = object2,
                according_to_samples =
              get_sample_id(object)[extract_sample_info(object)$class == "QC"])

object3
#> -------------------- 
#> massdataset version: 1.0.27 
#> -------------------- 
#> 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 5 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:[ 5 x 2 data.frame]
#> 6.ms2_data:[ 0 variables x 0 MS2 spectra]
#> -------------------- 
#> Processing information
#> 2 processings in total
#> create_mass_dataset ---------- 
#>       Package         Function.used                Time
#> 1 massdataset create_mass_dataset() 2023-10-01 14:00:41
#> mutate_variable_zero_number ---------- 
#>       Package                 Function.used                       Time
#> 1 massdataset mutate_variable_zero_number() 2023-10-01 14:00:41.123918
#> 2 massdataset mutate_variable_zero_number() 2023-10-01 14:00:41.133321

colnames(extract_variable_info(object3))
#> [1] "variable_id"   "mz"            "rt"            "zero_number"  
#> [5] "zero_number.1"
object3@variable_info_note
#>            name       meaning
#> 1   variable_id   variable_id
#> 2            mz            mz
#> 3            rt            rt
#> 4   zero_number   zero_number
#> 5 zero_number.1 zero_number.1
data("expression_data")
data("sample_info")
data("variable_info")

object =
  create_mass_dataset(
    expression_data = expression_data,
    sample_info = sample_info,
    variable_info = variable_info,
  )

object
#> -------------------- 
#> massdataset version: 1.0.27 
#> -------------------- 
#> 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() 2023-10-01 14:00:41

##calculate NA frequency according to all the samples
object2 =
  mutate_variable_zero_freq(object = object)

head(extract_variable_info(object))
#>     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
head(extract_variable_info(object2))
#>     variable_id        mz        rt zero_freq
#> 1 M136T55_2_POS 136.06140  54.97902        NA
#> 2    M79T35_POS  79.05394  35.36550        NA
#> 3  M307T548_POS 307.14035 547.56641        NA
#> 4  M183T224_POS 183.06209 224.32777        NA
#> 5   M349T47_POS 349.01584  47.00262        NA
#> 6  M182T828_POS 181.99775 828.35712        NA

##calculate NA number according to only QC samples
object3 =
  mutate_variable_zero_freq(object = object2,
                according_to_samples =
              get_sample_id(object)[extract_sample_info(object)$class == "QC"])

object3
#> -------------------- 
#> massdataset version: 1.0.27 
#> -------------------- 
#> 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 5 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:[ 5 x 2 data.frame]
#> 6.ms2_data:[ 0 variables x 0 MS2 spectra]
#> -------------------- 
#> Processing information
#> 2 processings in total
#> create_mass_dataset ---------- 
#>       Package         Function.used                Time
#> 1 massdataset create_mass_dataset() 2023-10-01 14:00:41
#> mutate_variable_zero_freq ---------- 
#>       Package               Function.used                       Time
#> 1 massdataset mutate_variable_zero_freq() 2023-10-01 14:00:41.169417
#> 2 massdataset mutate_variable_zero_freq() 2023-10-01 14:00:41.180255

head(extract_variable_info(object3))
#>     variable_id        mz        rt zero_freq zero_freq.1
#> 1 M136T55_2_POS 136.06140  54.97902        NA           0
#> 2    M79T35_POS  79.05394  35.36550        NA           0
#> 3  M307T548_POS 307.14035 547.56641        NA           0
#> 4  M183T224_POS 183.06209 224.32777        NA          NA
#> 5   M349T47_POS 349.01584  47.00262        NA           0
#> 6  M182T828_POS 181.99775 828.35712        NA          NA