This function splits a mass_dataset object into multiple subsets based on a specified column in either sample_info or variable_info. It also updates the process_info slot with the splitting parameters.

split_mass_dataset(object, by, fun)

Arguments

object

A mass_dataset object to be split.

by

The column name in sample_info or variable_info used for splitting.

fun

A function to apply when by is numeric. This function should return a logical vector.

Value

A list of subsetted mass_dataset objects.

Author

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 <-
activate_mass_dataset(object, what = "sample_info")

new_object <-
  split_mass_dataset(object = object, by = "group")

new_object %>% lapply(dim)
#> $Blank
#> variables   samples 
#>      1000         2 
#> 
#> $QC
#> variables   samples 
#>      1000         2 
#> 
#> $Subject
#> variables   samples 
#>      1000         4 
#> 
new_object %>% lapply(colnames)
#> $Blank
#> [1] "Blank_3" "Blank_4"
#> 
#> $QC
#> [1] "QC_1" "QC_2"
#> 
#> $Subject
#> [1] "PS4P1" "PS4P2" "PS4P3" "PS4P4"
#> 

object <-
  activate_mass_dataset(object, what = "variable_info")

new_object <-
  split_mass_dataset(object = object, by = "rt", fun = function(rt) rt > 600)

new_object %>% lapply(dim)
#> [[1]]
#> variables   samples 
#>       245         8 
#> 
#> [[2]]
#> variables   samples 
#>       755         8 
#> 
plot(extract_variable_info(new_object[[1]])$rt)

plot(extract_variable_info(new_object[[2]])$rt)