R/mutate_median_intensity.R
mutate_median_intensity.Rd
This function calculates the median intensity for each variable in the mass_dataset object based on the specified samples and adds it as a new column to the variable information.
mutate_median_intensity(object, according_to_samples = "all", na.rm = TRUE)
A modified mass_dataset object with added median intensity information.
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:53
##calculate median intensity according to all the samples
object2 =
mutate_median_intensity(object = object, na.rm = TRUE)
object2
#> --------------------
#> 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 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() 2024-09-06 08:49:53
#> mutate_median_intensity ----------
#> Package Function.used Time
#> 1 massdataset mutate_median_intensity() 2024-09-06 08:49:53
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.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:53
#> mutate_median_intensity ----------
#> Package Function.used Time
#> 1 massdataset mutate_median_intensity() 2024-09-06 08:49:53.576429
#> 2 massdataset mutate_median_intensity() 2024-09-06 08:49:53.589569
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