Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR contains work towards a new filter panel API as outlined in #187. **TESTING class methods**: 1. preparations ``` # get FilteredData object on demand utils::data(miniACC, package = "MultiAssayExperiment") get_fd <- function() { init_filtered_data( x = list( iris = list(dataset = iris), mtcars = list(dataset = mtcars), mae = list(dataset = miniACC) ) ) } # specify filter states (old way) fss <- list( iris = list( "Species" = list(selected = "setosa"), "Sepal.Length" = list(selected = c(5, 6)) ), mtcars = list( "disp" = list(selected = c(0, 280)), "cyl" = list(selected = 6) ), mae = list( subjects = list( years_to_birth = list(selected = c(30, 50), keep_na = TRUE, keep_inf = FALSE), vital_status = list(selected = "1", keep_na = FALSE), gender = list(selected = "female", keep_na = TRUE) ), RPPAArray = list( subset = list( ARRAY_TYPE = list(selected = "", keep_na = TRUE) ) ) ) ) # specify filter states (new way) tss <- filter_settings( filter_var("iris", "Species", selected = "setosa"), filter_var("iris", "Sepal.Length", selected = c(5, 6)), filter_var("mtcars", "disp", selected = c(0, 280)), filter_var("mtcars", "cyl", selected = 6), filter_var("mae", "years_to_birth", selected = c(30, 50), keep_na = TRUE, keep_inf = FALSE, datalabel = "subjects", target = "y"), filter_var("mae", "vital_status", selected = "1", keep_na = FALSE, datalabel = "subjects", target = "y"), filter_var("mae", "gender", selected = "female", keep_na = TRUE, datalabel = "subjects", target = "y"), filter_var("mae", "ARRAY_TYPE", selected = "", keep_na = TRUE, datalabel = "RPPAArray", target = "subset") ) ``` 2. convert old states specification to new one ``` fss_new <- as.teal_slices(fss) identical(fss, tss) identical(fss_new, tss) ``` :point_up: this happens in `FilteredData$set_filter_state` with a warning Note `as.teal_slices` does not perform any validation, so a list-like filter state that specifies filters on columns of `MAE@colData` that is not wrapped as `list(MAE = list(...))` but is only `list(var = list(...))` will be interpreted as a `data.frame` filter. 3. set states as list ``` # create FilteredData fd <- get_fd() # apply filter states fd$set_filter_state(fss) # see calls fd$get_call("iris") %>% isolate fd$get_call("mtcars") %>% isolate fd$get_call("mae") %>% isolate #recover filter states fd$get_filter_state() %>% isolate ``` 4. set states as `teal_slices` ``` # create FilteredData fd <- get_fd() # apply filter states fd$set_filter_state(tss) # see calls fd$get_call("iris") %>% isolate fd$get_call("mtcars") %>% isolate fd$get_call("mae") %>% isolate #recover filter states fd$get_filter_state() %>% isolate ``` Note that calls are not generated. This is these filters are instantiated and constructors don't know how to handle choices yet, so by default they are created with everything selected, hence no calls. 5. modify states as `teal_slices` ``` fd$set_filter_state(tss) # see calls fd$get_call("iris") %>% isolate fd$get_call("mtcars") %>% isolate fd$get_call("mae") %>% isolate #recover filter states fd$get_filter_state() %>% isolate ``` **TESTING wrapper functions**: ``` datasets <- init_filtered_data( x = list( iris = list(dataset = iris), mae = list(dataset = miniACC) ) ) fs <- filter_settings( filter_var("iris", "Species", selected = c("setosa", "versicolor")), filter_var("iris", "Sepal.Length", selected = c(5.1, 6.4)), filter_var("mae", "years_to_birth", selected = c(30, 50), keep_na = TRUE, keep_inf = FALSE, datalabel = "subjects", target = "y"), filter_var("mae", "vital_status", selected = "1", keep_na = FALSE, datalabel = "subjects", target = "y"), filter_var("mae", "gender", selected = "female", keep_na = TRUE, datalabel = "subjects", target = "y"), filter_var("mae", "ARRAY_TYPE", selected = "", keep_na = TRUE, datalabel = "RPPAArray", target = "subset") ) # set initial filter state set_filter_state(datasets, filter = fs) fd$.__enclos_env__$private$get_filter_count() %>% isolate # get filter state get_filter_state(datasets) fd$.__enclos_env__$private$get_filter_count() %>% isolate # modify filter state set_filter_state( datasets, filter_settings( filter_var("iris", "Species", selected = "setosa", keep_na = TRUE) ) ) fd$.__enclos_env__$private$get_filter_count() %>% isolate # remove specific filters remove_filter_state( datasets, filter_settings( filter_var("iris", "Species"), filter_var("mae", "years_to_birth"), filter_var("mae", "vital_status") ) ) fd$.__enclos_env__$private$get_filter_count() %>% isolate # remove all states clear_filter_states(datasets) fd$.__enclos_env__$private$get_filter_count() %>% isolate ``` --------- Signed-off-by: Marek Blazewicz <110387997+BLAZEWIM@users.noreply.github.com> Co-authored-by: Marek Blazewicz <110387997+BLAZEWIM@users.noreply.github.com> Co-authored-by: Blazewicz <blazewim@emea.roche.com> Co-authored-by: Dawid Kałędkowski <6959016+gogonzo@users.noreply.github.com>
- Loading branch information