R/mutate_sample_zero.R
mutate_sample_zero_number.Rd
This function adds a new column to the sample_info
slot of a mass_dataset object,
which contains the number of zero values for each sample according to the variables specified.
mutate_sample_zero_number(object, according_to_variables = "all")
A modified mass_dataset object with an updated sample_info
slot.
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:54
##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.33
#> --------------------
#> 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() 2024-09-06 08:49:54
#> mutate_sample_zero_number ----------
#> Package Function.used Time
#> 1 massdataset mutate_sample_zero_number() 2024-09-06 08:49:54.478908
#> 2 massdataset mutate_sample_zero_number() 2024-09-06 08:49:54.481902
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