This function adds a new column to the variable_info slot of a mass_dataset object, which contains the number of zeros for each variable according to the samples specified.

mutate_variable_zero_number(object, according_to_samples = "all")

Arguments

object

A mass_dataset object.

according_to_samples

A character vector specifying the sample IDs to consider when counting zeros. Default is "all", which considers all samples.

Value

A modified mass_dataset object with an updated variable_info slot.

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.33 
#> -------------------- 
#> 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() 2024-09-06 08:49:55

##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.33 
#> -------------------- 
#> 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() 2024-09-06 08:49:55
#> mutate_variable_zero_number ---------- 
#>       Package                 Function.used                       Time
#> 1 massdataset mutate_variable_zero_number() 2024-09-06 08:49:55.061393
#> 2 massdataset mutate_variable_zero_number()   2024-09-06 08:49:55.0641

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