View source: R/method_create_ti_method_r.R
create_ti_method_r | R Documentation |
Create a TI method from an R function wrapper
create_ti_method_r(
definition,
run_fun,
package_required = character(),
package_loaded = character(),
remotes_package = character(),
return_function = TRUE
)
definition |
A definition, see |
run_fun |
A function to infer a trajectory, with parameters counts/expression, parameters, priors, verbose and seed |
package_required |
The packages that need to be installed before executing the method. |
package_loaded |
The packages that need to be loaded before executing the method. |
remotes_package |
Package from which the remote locations of dependencies have to be extracted, eg. |
return_function |
Whether to return a function that allows you to override the default parameters, or just return the method meta data as is. |
A method definition
# define the parameters and other metadata
definition <- definition(
method = def_method(
id = "comp1"
),
parameters = def_parameters(
dynparam::integer_parameter(
id = "component",
default = 1,
distribution = dynparam::uniform_distribution(1, 10),
description = "The nth component to use"
)
),
wrapper = def_wrapper(
input_required = "expression",
input_optional = "start_id"
)
)
# define a wrapper function
run_fun <- function(expression, priors, parameters, seed, verbose) {
pca <- prcomp(expression)
pseudotime <- pca$x[, parameters$component]
# flip pseudotimes using start_id
if (!is.null(priors$start_id)) {
if(mean(pseudotime[start_id]) > 0.5) {
pseudotime <- 1-pseudotime
}
}
wrap_data(cell_ids = rownames(expression)) %>%
add_linear_trajectory(pseudotime = pseudotime)
}
method <- create_ti_method_r(definition, run_fun, package_loaded = "dplyr")
trajectory <- infer_trajectory(example_dataset, method())
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.