add_new_column-mass_dataset: Add mean intensity for each feature to variable_info

mutate_mean_intensityR Documentation

Add mean intensity for each feature to variable_info

Description

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 feature to variable_info

Add NA number for each feature to variable_info

Usage

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_variable_na_number(object, according_to_samples = "all")

mutate_variable_na_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

Author(s)

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

##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()
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 median intensity according to all the samples
object2 =
  mutate_median_intensity(object = object, na.rm = TRUE)

object2

head(extract_variable_info(object))
head(extract_variable_info(object2))

##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

head(extract_variable_info(object3))
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 RSDs according to all the samples
object =
  mutate_rsd(object = object)

object

head(extract_variable_info(object))

##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

head(extract_variable_info(object))
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 NA number according to all the variables
object2 =
  mutate_sample_na_number(object = object)

colnames(extract_sample_info(object))
colnames(extract_sample_info(object2))
object2@sample_info_note

##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

head(extract_sample_info(object3))
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 NA frequency according to all the variables
object2 =
  mutate_sample_na_freq(object = object)

head(extract_sample_info(object))
head(extract_sample_info(object2))

##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

head(extract_sample_info(object3))
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 NA number according to all the samples
object2 =
  mutate_variable_na_number(object = object)

colnames(extract_variable_info(object))
colnames(extract_variable_info(object2))
object2@variable_info_note

##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

colnames(extract_variable_info(object3))
object3@variable_info_note
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 NA frequency according to all the samples
object2 =
  mutate_variable_na_freq(object = object)

head(extract_variable_info(object))
head(extract_variable_info(object2))

##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

head(extract_variable_info(object3))

tidymass/massdataset documentation built on Sept. 24, 2022, 8:32 p.m.