View source: R/mutate_mean_intensity.R
mutate_mean_intensity | R Documentation |
This function calculates the mean 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_mean_intensity(object, according_to_samples = "all", na.rm = TRUE)
object |
A mass_dataset object. |
according_to_samples |
A character vector specifying the samples to consider for the mean calculation. Default is "all". |
na.rm |
Logical, whether to remove NA values before calculating the mean Default is TRUE. |
A modified mass_dataset object with added mean intensity information.
Xiaotao Shen shenxt1990@outlook.com
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
##calculate mean intensity according to all the samples
object2 =
mutate_mean_intensity(object = object, na.rm = TRUE)
object2
head(extract_variable_info(object))
head(extract_variable_info(object2))
##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
head(extract_variable_info(object3))
###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
object4 %>%
extract_variable_info()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.