Calculate fold change.

mutate_fc(
  object,
  control_sample_id,
  case_sample_id,
  mean_median = c("mean", "median"),
  return_mass_dataset = TRUE
)

Arguments

object

tidymass-class object.

control_sample_id

A character vector.

case_sample_id

A character vector

mean_median

mean or median.

return_mass_dataset

logical default TRUE

Value

object with fold change (fc) in variable_info.

Author

Xiaotao Shen shenxt1990@outlook.com

Examples

library(massdataset)
library(magrittr)
library(dplyr)

data("liver_aging_pos")
liver_aging_pos
#> -------------------- 
#> massdataset version: 0.01 
#> -------------------- 
#> 1.expression_data:[ 21607 x 24 data.frame]
#> 2.sample_info:[ 24 x 4 data.frame]
#> 3.variable_info:[ 21607 x 3 data.frame]
#> 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 (extract_process_info())
#> 1 processings in total
#> Creation ---------- 
#>       Package         Function.used                Time
#> 1 massdataset create_mass_dataset() 2021-12-23 00:24:02

w_78 =
  liver_aging_pos %>%
  activate_mass_dataset(what = "sample_info") %>%
  dplyr::filter(group == "78W") %>%
  dplyr::pull(sample_id)

w_24 =
  liver_aging_pos %>%
  activate_mass_dataset(what = "sample_info") %>%
  dplyr::filter(group == "24W") %>%
  dplyr::pull(sample_id)


control_sample_id = w_24
case_sample_id = w_78

liver_aging_pos =
  mutate_fc(
    object = liver_aging_pos,
    control_sample_id = control_sample_id,
    case_sample_id = case_sample_id,
    mean_median = "mean"
  )
#> 10 control samples.
#> 10 case samples.

head(extract_variable_info(liver_aging_pos))
#>          variable_id       mz       rt        fc
#> M60T1209    M60T1209 60.04340 1209.340 1.1733118
#> M60T1182    M60T1182 60.04341 1181.850 1.2331847
#> M60T1163    M60T1163 60.04340 1163.205 0.6996320
#> M60T1310    M60T1310 60.04335 1310.170 0.8301097
#> M60T1240    M60T1240 60.04339 1239.900 0.9963933
#> M60T1254    M60T1254 60.04340 1254.240 1.1172962

liver_aging_pos =
  mutate_fc(
    object = liver_aging_pos,
    control_sample_id = control_sample_id,
    case_sample_id = case_sample_id,
    mean_median = "median"
  )
#> 10 control samples.
#> 10 case samples.

head(extract_variable_info(liver_aging_pos))
#>          variable_id       mz       rt        fc      fc.1
#> M60T1209    M60T1209 60.04340 1209.340 1.1733118 1.3044047
#> M60T1182    M60T1182 60.04341 1181.850 1.2331847 1.3044817
#> M60T1163    M60T1163 60.04340 1163.205 0.6996320 1.0927459
#> M60T1310    M60T1310 60.04335 1310.170 0.8301097 1.2033256
#> M60T1240    M60T1240 60.04339 1239.900 0.9963933 0.8143669
#> M60T1254    M60T1254 60.04340 1254.240 1.1172962 1.0093612

extract_variable_info(liver_aging_pos) %>%
  ggplot(aes(fc, fc.1)) +
  geom_point()